From 9813643c96cff7dfe27f2669cf84cbbdfdebb773 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Mon, 16 Dec 2024 10:38:52 +0100 Subject: [PATCH] feat: parse timeToEnd from excel --- .../import-map/importMapUtils.ts | 2 ++ .../sources-panel/preview/PreviewRundown.tsx | 3 +++ .../server/src/utils/__tests__/parser.test.ts | 24 ++++++++++++++----- apps/server/src/utils/parser.ts | 8 ++++++- .../__tests__/spreadsheetImport.test.ts | 2 ++ .../spreadsheet-import/spreadsheetImport.ts | 1 + 6 files changed, 33 insertions(+), 7 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 a3fb757151..506d6c41c6 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 @@ -11,6 +11,7 @@ export const namedImportMap = { Duration: 'duration', Cue: 'cue', Title: 'title', + 'Time to end': 'time to end', 'Is Public': 'public', Skip: 'skip', Note: 'notes', @@ -47,6 +48,7 @@ export function convertToImportMap(namedImportMap: NamedImportMap): ImportMap { duration: namedImportMap.Duration, cue: namedImportMap.Cue, title: namedImportMap.Title, + isTimeToEnd: namedImportMap['Time to end'], isPublic: namedImportMap['Is Public'], skip: namedImportMap.Skip, note: namedImportMap.Note, 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 1ede1ef042..f47a4fa297 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 @@ -40,6 +40,7 @@ export default function PreviewRundown(props: PreviewRundownProps) { Duration Warning Time Danger Time + Is Time to End Is Public Skip Colour @@ -71,6 +72,7 @@ export default function PreviewRundown(props: PreviewRundownProps) { } eventIndex += 1; const colour = event.colour ? getAccessibleColour(event.colour) : {}; + const isTimeToEnd = booleanToText(event.isTimeToEnd); const isPublic = booleanToText(event.isPublic); const skip = booleanToText(event.skip); @@ -93,6 +95,7 @@ export default function PreviewRundown(props: PreviewRundownProps) { {millisToString(event.duration)} {millisToString(event.timeWarning)} {millisToString(event.timeDanger)} + {isTimeToEnd && {isTimeToEnd}} {isPublic && {isPublic}} {skip && {skip}} {event.colour} diff --git a/apps/server/src/utils/__tests__/parser.test.ts b/apps/server/src/utils/__tests__/parser.test.ts index f8b32b1f3f..955f482233 100644 --- a/apps/server/src/utils/__tests__/parser.test.ts +++ b/apps/server/src/utils/__tests__/parser.test.ts @@ -775,6 +775,7 @@ describe('getCustomFieldData()', () => { duration: 'duration', cue: 'cue', title: 'title', + isTimeToEnd: 'time to end', isPublic: 'public', skip: 'skip', note: 'notes', @@ -825,6 +826,7 @@ describe('getCustomFieldData()', () => { duration: 'duration', cue: 'cue', title: 'title', + isTimeToEnd: 'time to end', isPublic: 'public', skip: 'skip', note: 'notes', @@ -884,6 +886,7 @@ describe('parseExcel()', () => { 'Title', 'End Action', 'Timer type', + 'Time to end', 'Public', 'Skip', 'Notes', @@ -906,7 +909,8 @@ describe('parseExcel()', () => { 'Guest Welcome', '', '', - 'x', + 'x', // <-- time to end + 'x', // <-- public '', 'Ballyhoo', 'a0', @@ -928,7 +932,8 @@ describe('parseExcel()', () => { 'A song from the hearth', 'load-next', 'clock', - '', + 'x', // <-- time to end + '', // <-- public 'x', 'Rainbow chase', 'b0', @@ -972,6 +977,7 @@ describe('parseExcel()', () => { timerType: 'count-down', endAction: 'none', isPublic: true, + isTimeToEnd: true, skip: false, note: 'Ballyhoo', custom: { @@ -995,6 +1001,7 @@ describe('parseExcel()', () => { timeEnd: 30600000, title: 'A song from the hearth', timerType: 'clock', + isTimeToEnd: true, endAction: 'load-next', isPublic: false, skip: true, @@ -1455,12 +1462,17 @@ describe('parseExcel()', () => { timeDanger: 'danger time', custom: {}, }; + const result = parseExcel(testdata, {}, importMap); expect(result.rundown.length).toBe(2); - expect((result.rundown.at(0) as OntimeEvent).type).toBe(SupportedEvent.Event); - expect((result.rundown.at(0) as OntimeEvent).timerType).toBe(TimerType.CountDown); - expect((result.rundown.at(1) as OntimeEvent).type).toBe(SupportedEvent.Event); - expect((result.rundown.at(1) as OntimeEvent).timerType).toBe(TimerType.CountDown); + expect(result.rundown[0]).toMatchObject({ + type: SupportedEvent.Event, + timerType: TimerType.CountDown, + }); + expect(result.rundown[1]).toMatchObject({ + type: SupportedEvent.Event, + timerType: TimerType.CountDown, + }); }); it('imports as events if timer type is empty or has whitespace', () => { diff --git a/apps/server/src/utils/parser.ts b/apps/server/src/utils/parser.ts index e9822f9840..f8b7ae2785 100644 --- a/apps/server/src/utils/parser.ts +++ b/apps/server/src/utils/parser.ts @@ -110,6 +110,7 @@ export const parseExcel = ( // options: booleans let isPublicIndex: number | null = null; let skipIndex: number | null = null; + let isTimeToEndIndex: number | null = null; let linkStartIndex: number | null = null; @@ -159,6 +160,10 @@ export const parseExcel = ( titleIndex = col; rundownMetadata['title'] = { row, col }; }, + [importMap.isTimeToEnd]: (row: number, col: number) => { + isTimeToEndIndex = col; + rundownMetadata['isTimeToEnd'] = { row, col }; + }, [importMap.isPublic]: (row: number, col: number) => { isPublicIndex = col; rundownMetadata['isPublic'] = { row, col }; @@ -226,6 +231,8 @@ export const parseExcel = ( event.duration = parseExcelDate(column); } else if (j === cueIndex) { event.cue = makeString(column, ''); + } else if (j === isTimeToEndIndex) { + event.isTimeToEnd = parseBooleanString(column); } else if (j === isPublicIndex) { event.isPublic = parseBooleanString(column); } else if (j === skipIndex) { @@ -271,7 +278,6 @@ export const parseExcel = ( // if any data was found in row, push to array const keysFound = Object.keys(event).length + Object.keys(eventCustomFields).length; - console.log('keys found ---->', event) if (keysFound > 0) { // if it is a Block type drop all other filed if (isOntimeBlock(event)) { 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 2ef3c5005f..bad03307cd 100644 --- a/packages/utils/src/feature/spreadsheet-import/__tests__/spreadsheetImport.test.ts +++ b/packages/utils/src/feature/spreadsheet-import/__tests__/spreadsheetImport.test.ts @@ -11,6 +11,7 @@ describe('isImportMap()', () => { duration: 'duration', cue: 'cue', title: 'title', + isTimeToEnd: 'time to end', isPublic: 'public', skip: 'skip', note: 'notes', @@ -34,6 +35,7 @@ describe('isImportMap()', () => { duration: 'duration', cue: 'cue', title: 'title', + isTimeToEnd: 'time to end', isPublic: 'public', skip: 'skip', note: 'notes', diff --git a/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts b/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts index c8ec35a344..830b805e53 100644 --- a/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts +++ b/packages/utils/src/feature/spreadsheet-import/spreadsheetImport.ts @@ -11,6 +11,7 @@ export const defaultImportMap = { duration: 'duration', cue: 'cue', title: 'title', + isTimeToEnd: 'time to end', isPublic: 'public', skip: 'skip', note: 'notes',