mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 21:03:29 +00:00
fix: delete nested events
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { CustomFields, OntimeEvent, SupportedEntry, TimeStrategy } from 'ontime-types';
|
import { CustomFields, OntimeBlock, OntimeEvent, SupportedEntry, TimeStrategy } from 'ontime-types';
|
||||||
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, dayInMs } from 'ontime-utils';
|
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, dayInMs } from 'ontime-utils';
|
||||||
|
|
||||||
import { demoDb } from '../../../models/demoProject.js';
|
import { demoDb } from '../../../models/demoProject.js';
|
||||||
@@ -663,6 +663,28 @@ describe('remove() mutation', () => {
|
|||||||
expect(newRundown.order.length).toBe(3);
|
expect(newRundown.order.length).toBe(3);
|
||||||
expect(newRundown.entries[newRundown.order[0]].id).toBe('4');
|
expect(newRundown.entries[newRundown.order[0]].id).toBe('4');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('deletes a nested event', () => {
|
||||||
|
const rundown = makeRundown({
|
||||||
|
order: ['1'],
|
||||||
|
flatOrder: ['1', '11', '12', '13'],
|
||||||
|
entries: {
|
||||||
|
'1': makeOntimeBlock({ id: '1', events: ['11', '12', '13'] }),
|
||||||
|
'11': makeOntimeEvent({ id: '11', parent: '1' }),
|
||||||
|
'12': makeOntimeDelay({ id: '12', parent: '1' }),
|
||||||
|
'13': makeOntimeEvent({ id: '13', parent: '1' }),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { newRundown } = remove({ eventIds: ['12'], rundown });
|
||||||
|
expect(newRundown.order).toStrictEqual(['1']);
|
||||||
|
expect(newRundown.entries).toMatchObject({
|
||||||
|
'1': { id: '1' },
|
||||||
|
'11': { id: '11' },
|
||||||
|
'13': { id: '13' },
|
||||||
|
});
|
||||||
|
expect((newRundown.entries['1'] as OntimeBlock).events).toStrictEqual(['11', '13']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('edit() mutation', () => {
|
describe('edit() mutation', () => {
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ export function generate(
|
|||||||
let blockStartTime = null;
|
let blockStartTime = null;
|
||||||
let blockEndTime = null;
|
let blockEndTime = null;
|
||||||
let isFirstLinked = false;
|
let isFirstLinked = false;
|
||||||
|
const blockEvents: EntryId[] = [];
|
||||||
|
|
||||||
// check if the block contains events
|
// check if the block contains events
|
||||||
for (let i = 0; i < processedEntry.events.length; i++) {
|
for (let i = 0; i < processedEntry.events.length; i++) {
|
||||||
@@ -123,6 +124,8 @@ export function generate(
|
|||||||
if (!nestedEntry) {
|
if (!nestedEntry) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockEvents.push(nestedEntry.id);
|
||||||
const { processedData: processedNestedData, processedEntry: processedNestedEntry } = process(
|
const { processedData: processedNestedData, processedEntry: processedNestedEntry } = process(
|
||||||
nestedEntry,
|
nestedEntry,
|
||||||
processedEntry.id,
|
processedEntry.id,
|
||||||
@@ -150,7 +153,8 @@ export function generate(
|
|||||||
processedEntry.startTime = blockStartTime;
|
processedEntry.startTime = blockStartTime;
|
||||||
processedEntry.endTime = blockEndTime;
|
processedEntry.endTime = blockEndTime;
|
||||||
processedEntry.isFirstLinked = isFirstLinked;
|
processedEntry.isFirstLinked = isFirstLinked;
|
||||||
processedEntry.numEvents = processedEntry.events.length;
|
processedEntry.events = blockEvents;
|
||||||
|
processedEntry.numEvents = blockEvents.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,27 +347,36 @@ export function add({ rundown, atIndex, parent, entry }: AddArgs): Required<Muta
|
|||||||
type RemoveArgs = MutationParams<{ eventIds: EntryId[] }>;
|
type RemoveArgs = MutationParams<{ eventIds: EntryId[] }>;
|
||||||
/**
|
/**
|
||||||
* Remove entries in a rundown
|
* Remove entries in a rundown
|
||||||
|
* It needs to ensure that the parent block is updated
|
||||||
*/
|
*/
|
||||||
export function remove({ rundown, eventIds }: RemoveArgs): MutatingReturn {
|
export function remove({ rundown, eventIds }: RemoveArgs): MutatingReturn {
|
||||||
let didMutate = false;
|
let didMutate = false;
|
||||||
|
|
||||||
for (let i = 0; i < eventIds.length; i++) {
|
for (let i = 0; i < eventIds.length; i++) {
|
||||||
const entry = rundown.entries[eventIds[i]];
|
const entry = rundown.entries[eventIds[i]];
|
||||||
if (isOntimeEvent(entry) && entry.parent) {
|
if (isOntimeBlock(entry) || !entry.parent) {
|
||||||
|
// top level events can simply be removed from the order
|
||||||
|
// the deletion process and the flatOrder are handled globally
|
||||||
|
rundown.order = rundown.order.filter((id) => id !== eventIds[i]);
|
||||||
|
} else {
|
||||||
const parentBlock = rundown.entries[entry.parent] as OntimeBlock;
|
const parentBlock = rundown.entries[entry.parent] as OntimeBlock;
|
||||||
|
const parentEvents = parentBlock.events.filter((id) => id !== eventIds[i]);
|
||||||
|
|
||||||
|
// we call a mutation to the parent event to
|
||||||
|
// - remove this entry from the events
|
||||||
|
// - reduce the children count
|
||||||
edit({
|
edit({
|
||||||
rundown,
|
rundown,
|
||||||
eventId: entry.parent,
|
eventId: entry.parent,
|
||||||
patch: {
|
patch: {
|
||||||
events: parentBlock.events.filter((id) => id !== eventIds[i]),
|
events: parentEvents,
|
||||||
numEvents: parentBlock.events.length - 1,
|
numEvents: parentEvents.length,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
parentBlock.events = parentBlock.events.filter((id) => id !== entry.id);
|
|
||||||
} else {
|
|
||||||
rundown.order = rundown.order.filter((id) => id !== eventIds[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
didMutate = true;
|
didMutate = true;
|
||||||
|
rundown.flatOrder = rundown.flatOrder.filter((id) => id !== eventIds[i]);
|
||||||
delete rundown.entries[eventIds[i]];
|
delete rundown.entries[eventIds[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user