Fix: sheet export (#1606)

* add util to get keys from labels

* look for existing keys first then create new

* save ontime key to rundown metadata

* update test
This commit is contained in:
Alex Christoffer Rasmussen
2025-05-12 13:56:25 +02:00
committed by GitHub
parent 1f0cde6d0d
commit 1e1aa4bca5
4 changed files with 31 additions and 11 deletions
+7 -5
View File
@@ -1,5 +1,6 @@
import {
customFieldLabelToKey,
customKeyFromLabel,
defaultImportMap,
generateId,
type ImportMap,
@@ -60,7 +61,7 @@ export function getCustomFieldData(
const customFields = {};
const customFieldImportKeys = {};
for (const ontimeLabel in importMap.custom) {
const ontimeKey = customFieldLabelToKey(ontimeLabel);
const ontimeKey = customKeyFromLabel(ontimeLabel, existingCustomFields) ?? customFieldLabelToKey(ontimeLabel);
const importLabel = importMap.custom[ontimeLabel].toLowerCase();
const colour = ontimeKey in existingCustomFields ? existingCustomFields[ontimeKey].colour : '';
customFields[ontimeKey] = {
@@ -198,9 +199,9 @@ export const parseExcel = (
entryIdIndex = col;
rundownMetadata['id'] = { row, col };
},
custom: (row: number, col: number, columnText: string) => {
custom: (row: number, col: number, columnText: string, ontimeKey: string) => {
customFieldIndexes[col] = columnText;
rundownMetadata[`custom:${columnText}`] = { row, col };
rundownMetadata[`custom:${ontimeKey}`] = { row, col };
},
} as const;
@@ -266,12 +267,13 @@ export const parseExcel = (
// check if it is an ontime column
if (handlers[columnText]) {
handlers[columnText](rowIndex, j, undefined);
handlers[columnText](rowIndex, j, undefined, undefined);
}
// check if it is a custom field
if (columnText in customFieldImportKeys) {
handlers.custom(rowIndex, j, columnText);
const ontimeKey = customFieldImportKeys[columnText];
handlers.custom(rowIndex, j, columnText, ontimeKey);
}
// else. we don't know how to handle this column