fix: parse nested events in rundown

This commit is contained in:
Carlos Valente
2025-07-14 09:08:29 +02:00
parent 6f9e13948d
commit 1e5081f4a2
3 changed files with 35 additions and 13 deletions
@@ -1,4 +1,12 @@
import { SupportedEntry, OntimeEvent, OntimeDelay, OntimeBlock, Rundown, CustomField } from 'ontime-types'; import {
SupportedEntry,
OntimeEvent,
OntimeDelay,
OntimeBlock,
Rundown,
CustomField,
OntimeMilestone,
} from 'ontime-types';
import { defaultRundown } from '../../../models/dataModel.js'; import { defaultRundown } from '../../../models/dataModel.js';
@@ -13,6 +21,12 @@ const baseBlock = {
entries: [], entries: [],
}; };
const baseMilestone = {
type: SupportedEntry.Milestone,
cue: '',
title: '',
};
/** /**
* Utility to create a Ontime event * Utility to create a Ontime event
*/ */
@@ -37,6 +51,13 @@ export function makeOntimeBlock(patch: Partial<OntimeBlock>): OntimeBlock {
return { id: 'block', ...baseBlock, ...patch } as OntimeBlock; return { id: 'block', ...baseBlock, ...patch } as OntimeBlock;
} }
/**
* Utility to create a block event
*/
export function makeOntimeMilestone(patch: Partial<OntimeMilestone>): OntimeMilestone {
return { id: 'milestone', ...baseMilestone, ...patch } as OntimeMilestone;
}
/** /**
* Utility to create a rundown object * Utility to create a rundown object
*/ */
@@ -1,7 +1,7 @@
import { SupportedEntry, OntimeEvent, OntimeBlock, Rundown, CustomFields } from 'ontime-types'; import { SupportedEntry, OntimeEvent, OntimeBlock, Rundown, CustomFields } from 'ontime-types';
import { defaultRundown } from '../../../models/dataModel.js'; import { defaultRundown } from '../../../models/dataModel.js';
import { makeOntimeBlock, makeOntimeEvent } from '../__mocks__/rundown.mocks.js'; import { makeOntimeBlock, makeOntimeEvent, makeOntimeMilestone } from '../__mocks__/rundown.mocks.js';
import { parseRundowns, parseRundown, handleCustomField, addToCustomAssignment } from '../rundown.parser.js'; import { parseRundowns, parseRundown, handleCustomField, addToCustomAssignment } from '../rundown.parser.js';
@@ -241,7 +241,7 @@ describe('parseRundown()', () => {
expect((parsedRundown.entries['21'] as OntimeEvent).custom).not.toHaveProperty('lighting'); expect((parsedRundown.entries['21'] as OntimeEvent).custom).not.toHaveProperty('lighting');
}); });
it('parses data in blocks', () => { it('parses data in groups', () => {
const rundown = { const rundown = {
id: 'test', id: 'test',
title: '', title: '',
@@ -254,20 +254,21 @@ describe('parseRundown()', () => {
title: 'block-title', title: 'block-title',
note: 'block-note', note: 'block-note',
colour: 'red', colour: 'red',
entries: ['1', '2'], entries: ['1', '2', '3'],
}), }),
'1': makeOntimeEvent({ id: '1' }), '1': makeOntimeEvent({ id: '1', parent: 'block' }),
'2': makeOntimeMilestone({ id: '2', parent: 'block' }),
}, },
revision: 1, revision: 1,
} as Rundown; } as Rundown;
const parsedRundown = parseRundown(rundown, {}); const parsedRundown = parseRundown(rundown, {});
expect(parsedRundown.order.length).toEqual(1); expect(parsedRundown.order).toStrictEqual(['block']);
expect(parsedRundown.entries.block).toMatchObject({ expect(parsedRundown.flatOrder).toStrictEqual(['block', '1', '2']);
title: 'block-title', expect(parsedRundown.entries).toMatchObject({
note: 'block-note', block: { id: 'block', type: SupportedEntry.Block, entries: ['1', '2'] },
colour: 'red', '1': { id: '1', type: SupportedEntry.Event },
entries: ['1'], '2': { id: '2', type: SupportedEntry.Milestone },
}); });
}); });
@@ -127,9 +127,9 @@ export function parseRundown(
cleanupCustomFields(newNestedEvent.custom, parsedCustomFields); cleanupCustomFields(newNestedEvent.custom, parsedCustomFields);
eventIndex += 1; eventIndex += 1;
} else if (isOntimeDelay(nestedEvent)) { } else if (isOntimeDelay(nestedEvent)) {
newNestedEvent = { ...delayDef, duration: nestedEvent.duration, id }; newNestedEvent = { ...delayDef, duration: nestedEvent.duration, id: nestedEventId };
} else if (isOntimeMilestone(nestedEvent)) { } else if (isOntimeMilestone(nestedEvent)) {
newNestedEvent = createMilestone({ ...nestedEvent, id }); newNestedEvent = createMilestone({ ...nestedEvent, id: nestedEventId });
cleanupCustomFields(newNestedEvent.custom, parsedCustomFields); cleanupCustomFields(newNestedEvent.custom, parsedCustomFields);
} }