From d0b4c6a279ed043cc7a1f944e42dc413a464de88 Mon Sep 17 00:00:00 2001 From: Alex Christoffer Rasmussen Date: Wed, 26 Feb 2025 21:12:36 +0100 Subject: [PATCH] import id's from sheet (#1516) * import id's from sheet * fix test * fix test in utils * remove comment * ensure uri safe ids --- .../import-map/importMapUtils.ts | 2 ++ .../sources-panel/preview/PreviewRundown.tsx | 4 +++ .../server/src/utils/__tests__/parser.test.ts | 2 ++ apps/server/src/utils/parser.ts | 13 +++++-- .../__tests__/spreadsheetImport.test.ts | 34 ++++++++++++++++--- .../spreadsheet-import/spreadsheetImport.ts | 1 + 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/apps/client/src/features/app-settings/panel/sources-panel/import-map/importMapUtils.ts b/apps/client/src/features/app-settings/panel/sources-panel/import-map/importMapUtils.ts index 9492ae8ce..0f786355f 100644 --- a/apps/client/src/features/app-settings/panel/sources-panel/import-map/importMapUtils.ts +++ b/apps/client/src/features/app-settings/panel/sources-panel/import-map/importMapUtils.ts @@ -20,6 +20,7 @@ export const namedImportMap = { 'Timer type': 'timer type', 'Time warning': 'warning time', 'Time danger': 'danger time', + ID: 'id', custom: [] as ImportCustom[], }; @@ -58,6 +59,7 @@ export function convertToImportMap(namedImportMap: NamedImportMap): ImportMap { timeWarning: namedImportMap['Time warning'], timeDanger: namedImportMap['Time danger'], custom, + entryId: namedImportMap.ID, }; } diff --git a/apps/client/src/features/app-settings/panel/sources-panel/preview/PreviewRundown.tsx b/apps/client/src/features/app-settings/panel/sources-panel/preview/PreviewRundown.tsx index dc54b90a0..98cdb34dc 100644 --- a/apps/client/src/features/app-settings/panel/sources-panel/preview/PreviewRundown.tsx +++ b/apps/client/src/features/app-settings/panel/sources-panel/preview/PreviewRundown.tsx @@ -49,6 +49,7 @@ export default function PreviewRundown(props: PreviewRundownProps) { {fieldLabels.map((label) => ( {label} ))} + ID @@ -113,6 +114,9 @@ export default function PreviewRundown(props: PreviewRundownProps) { } return {value}; })} + + {event.id} + {event.note && ( diff --git a/apps/server/src/utils/__tests__/parser.test.ts b/apps/server/src/utils/__tests__/parser.test.ts index 939486c20..6a4c4e724 100644 --- a/apps/server/src/utils/__tests__/parser.test.ts +++ b/apps/server/src/utils/__tests__/parser.test.ts @@ -787,6 +787,7 @@ describe('getCustomFieldData()', () => { sound: 'sound', video: 'av', }, + entryId: 'id', } as ImportMap; const result = getCustomFieldData(importMap, {}); @@ -838,6 +839,7 @@ describe('getCustomFieldData()', () => { sound: 'sound', video: 'av', }, + entryId: 'id', } as ImportMap; const customFields: CustomFields = { diff --git a/apps/server/src/utils/parser.ts b/apps/server/src/utils/parser.ts index 0096ebe8c..11680f5f6 100644 --- a/apps/server/src/utils/parser.ts +++ b/apps/server/src/utils/parser.ts @@ -120,6 +120,9 @@ export const parseExcel = ( let endActionIndex: number | null = null; let timerTypeIndex: number | null = null; + //ID + let entryIdIndex: number | null = null; + // record of column index and the name of the field const customFieldIndexes: Record = {}; @@ -185,11 +188,15 @@ export const parseExcel = ( }, [importMap.timeWarning]: (row: number, col: number) => { timeWarningIndex = col; - rundownMetadata['timeWarningIndex'] = { row, col }; + rundownMetadata['timeWarning'] = { row, col }; }, [importMap.timeDanger]: (row: number, col: number) => { timeDangerIndex = col; - rundownMetadata['timeDangerIndex'] = { row, col }; + rundownMetadata['timeDanger'] = { row, col }; + }, + [importMap.entryId]: (row: number, col: number) => { + entryIdIndex = col; + rundownMetadata['id'] = { row, col }; }, custom: (row: number, col: number, columnText: string) => { customFieldIndexes[col] = columnText; @@ -242,6 +249,8 @@ export const parseExcel = ( event.timeDanger = parseExcelDate(column); } else if (j === colourIndex) { event.colour = makeString(column, ''); + } else if (j === entryIdIndex) { + event.id = encodeURIComponent(makeString(column, undefined)); } else if (j in customFieldIndexes) { const importKey = customFieldIndexes[j]; const ontimeKey = customFieldImportKeys[importKey]; diff --git a/packages/utils/src/feature/spreadsheet-import/__tests__/spreadsheetImport.test.ts b/packages/utils/src/feature/spreadsheet-import/__tests__/spreadsheetImport.test.ts index 8dbe13e0d..97732accd 100644 --- a/packages/utils/src/feature/spreadsheet-import/__tests__/spreadsheetImport.test.ts +++ b/packages/utils/src/feature/spreadsheet-import/__tests__/spreadsheetImport.test.ts @@ -3,7 +3,7 @@ import { isImportMap } from '../spreadsheetImport'; describe('isImportMap()', () => { it('validates a v3 default import map', () => { - const v3ImportMap = { + const v3ImportMap: ImportMap = { worksheet: 'event schedule', timeStart: 'time start', linkStart: 'link start', @@ -21,13 +21,38 @@ describe('isImportMap()', () => { timeWarning: 'warning time', timeDanger: 'danger time', custom: {}, - } as ImportMap; + entryId: 'id', + }; expect(isImportMap(v3ImportMap)).toBe(true); }); + it('rejects map missing keys', () => { + const importMap = { + worksheet: 'event schedule', + timeStart: 'time start', + linkStart: 'link start', + timeEnd: 'time end', + duration: 'duration', + cue: 'cue', + title: 'title', + countToEnd: 'count to end', + isPublic: 'public', + skip: 'skip', + note: 'notes', + colour: 'colour', + endAction: 'end action', + timerType: 'timer type', + timeWarning: 'warning time', + timeDanger: 'danger time', + custom: {}, + }; + + expect(isImportMap(importMap)).toBe(false); + }); + it('handles custom properties', () => { - const v3ImportMap = { + const v3ImportMap: ImportMap = { worksheet: 'event schedule', timeStart: 'time start', linkStart: 'link start', @@ -48,7 +73,8 @@ describe('isImportMap()', () => { userDefined: 'userDefined', anotherOne: 'anotherOne', }, - } as ImportMap; + entryId: 'id', + }; expect(isImportMap(v3ImportMap)).toBe(true); }); diff --git a/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts b/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts index 3ac82f10a..7f5c5f8db 100644 --- a/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts +++ b/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts @@ -21,6 +21,7 @@ export const defaultImportMap = { timeWarning: 'warning time', timeDanger: 'danger time', custom: {}, + entryId: 'id', }; /**