fix: ensure IDs on import from excel

This commit is contained in:
Carlos Valente
2025-11-02 12:10:20 +01:00
committed by Carlos Valente
parent b65b3fa6d2
commit 3918664945
2 changed files with 15 additions and 3 deletions
@@ -13,21 +13,27 @@ describe('parseExcel()', () => {
expect(result.rundown.flatOrder.length).toBe(14); expect(result.rundown.flatOrder.length).toBe(14);
expect(result.rundown.order.length).toBe(4); expect(result.rundown.order.length).toBe(4);
const firstEvent = result.rundown.entries[result.rundown.flatOrder[2]]; const firstEventId = result.rundown.flatOrder[2];
const firstEvent = result.rundown.entries[firstEventId];
expect(firstEvent).toMatchObject({ expect(firstEvent).toMatchObject({
id: firstEventId,
type: SupportedEntry.Event, type: SupportedEntry.Event,
title: 'Pre-show Countdown', title: 'Pre-show Countdown',
}); });
expect(millisToString((firstEvent as OntimeEvent).timeStart)).toBe('10:00:00'); expect(millisToString((firstEvent as OntimeEvent).timeStart)).toBe('10:00:00');
const lastEvent = result.rundown.entries[result.rundown.flatOrder[12]]; const lastEventId = result.rundown.flatOrder[12];
const lastEvent = result.rundown.entries[lastEventId];
expect(lastEvent).toMatchObject({ expect(lastEvent).toMatchObject({
id: lastEventId,
type: SupportedEntry.Event, type: SupportedEntry.Event,
title: 'Wrap up', title: 'Wrap up',
}); });
// the excel step does not relate elements yet // the excel step does not relate elements yet
expect(millisToString((lastEvent as OntimeEvent).timeEnd)).toBe('00:00:00'); expect(millisToString((lastEvent as OntimeEvent).timeEnd)).toBe('00:00:00');
}); });
it('parses an import map with only custom fields', () => { it('parses an import map with only custom fields', () => {
// partial import map with only custom fields // partial import map with only custom fields
const importMap = { const importMap = {
@@ -184,6 +184,7 @@ export const parseExcel = (
// from excel, we can only get groups, milestones and events // from excel, we can only get groups, milestones and events
if (isOntimeGroup(entry as OntimeEntry)) { if (isOntimeGroup(entry as OntimeEntry)) {
const group = { const group = {
id, // will be replaced by a potentially user given ID
...entry, ...entry,
targetDuration: entry.duration ? entry.duration : null, targetDuration: entry.duration ? entry.duration : null,
custom: { ...entryCustomFields }, custom: { ...entryCustomFields },
@@ -200,7 +201,11 @@ export const parseExcel = (
} }
if (isOntimeMilestone(entry as OntimeEntry)) { if (isOntimeMilestone(entry as OntimeEntry)) {
const milestone = { ...entry, custom: { ...entryCustomFields } } as OntimeMilestone; const milestone = {
id, // will be replaced by a potentially user given ID
...entry,
custom: { ...entryCustomFields },
} as OntimeMilestone;
if (currentGroupId) { if (currentGroupId) {
groupEntries.push(id); groupEntries.push(id);
milestone.parent = currentGroupId; milestone.parent = currentGroupId;
@@ -214,6 +219,7 @@ export const parseExcel = (
// after group and milestones we only have events remaining // after group and milestones we only have events remaining
const event = { const event = {
id, // will be replaced by a potentially user given ID
...entry, ...entry,
custom: { ...entryCustomFields }, custom: { ...entryCustomFields },
type: SupportedEntry.Event, type: SupportedEntry.Event,