From 700948bfbb0dd4df99f117f6b69ee51e72428737 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Sun, 5 Oct 2025 07:19:30 +0200 Subject: [PATCH] fix: use correct order when creating groups --- .../rundown/__tests__/rundown.dao.test.ts | 42 ++++++++++++++++++- .../src/api-data/rundown/rundown.dao.ts | 2 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/apps/server/src/api-data/rundown/__tests__/rundown.dao.test.ts b/apps/server/src/api-data/rundown/__tests__/rundown.dao.test.ts index ed6b5c618..da7663172 100644 --- a/apps/server/src/api-data/rundown/__tests__/rundown.dao.test.ts +++ b/apps/server/src/api-data/rundown/__tests__/rundown.dao.test.ts @@ -1,4 +1,12 @@ -import { CustomFields, OntimeGroup, OntimeDelay, OntimeEvent, SupportedEntry, TimeStrategy, OntimeMilestone } from 'ontime-types'; +import { + CustomFields, + OntimeGroup, + OntimeDelay, + OntimeEvent, + SupportedEntry, + TimeStrategy, + OntimeMilestone, +} from 'ontime-types'; import { dayInMs, MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from 'ontime-utils'; import { @@ -1641,6 +1649,38 @@ describe('rundownMutation.group()', () => { '3': { id: '3', type: SupportedEntry.Event, parent: null }, }); }); + + it('BUG: creates a group in between groups', () => { + const rundown = makeRundown({ + order: ['group-1', '1', '2', '3', '4', 'group-2'], + entries: { + 'group-1': makeOntimeGroup({ id: 'group-1', entries: ['1a', '1b'] }), + 'group-2': makeOntimeGroup({ id: 'group-2', entries: ['2a', '2b'] }), + '1': makeOntimeEvent({ id: '1', parent: null }), + '2': makeOntimeEvent({ id: '2', parent: null }), + '3': makeOntimeEvent({ id: '3', parent: null }), + '4': makeOntimeEvent({ id: '4', parent: null }), + '1a': makeOntimeEvent({ id: '1a', parent: 'group-1' }), + '1b': makeOntimeEvent({ id: '1b', parent: 'group-1' }), + '2a': makeOntimeEvent({ id: '2a', parent: 'group-2' }), + '2b': makeOntimeEvent({ id: '2b', parent: 'group-2' }), + }, + }); + + rundownMutation.group(rundown, ['2', '3']); + + const groupId = rundown.order[2]; + expect(groupId).toStrictEqual(expect.any(String)); + expect(rundown.order).toStrictEqual(['group-1', '1', expect.any(String), '4', 'group-2']); + expect(rundown.entries).toMatchObject({ + [groupId]: { + type: SupportedEntry.Group, + entries: ['2', '3'], + }, + '2': { id: '2', type: SupportedEntry.Event, parent: groupId }, + '3': { id: '3', type: SupportedEntry.Event, parent: groupId }, + }); + }); }); describe('rundownMutation.ungroup()', () => { diff --git a/apps/server/src/api-data/rundown/rundown.dao.ts b/apps/server/src/api-data/rundown/rundown.dao.ts index 085d38b15..7594d4752 100644 --- a/apps/server/src/api-data/rundown/rundown.dao.ts +++ b/apps/server/src/api-data/rundown/rundown.dao.ts @@ -498,7 +498,7 @@ function group(rundown: Rundown, entryIds: EntryId[]): OntimeGroup { // the group will be created at the first selected event position // note that this is not the lowest index if (firstIndex === -1) { - firstIndex = rundown.flatOrder.indexOf(entryId); + firstIndex = rundown.order.indexOf(entryId); } nestedEvents.push(entryId);