refactor: swap maintains schedule

This commit is contained in:
Carlos Valente
2025-03-28 21:35:23 +01:00
committed by arc-alex
parent ef73c87e2f
commit 84fac739f0
3 changed files with 14 additions and 2 deletions
@@ -525,6 +525,8 @@ export function swap({ rundown, fromId, toId }: SwapArgs): MutatingReturn {
rundown.entries[fromId] = newFrom;
rundown.entries[toId] = newTo;
newFrom.revision++;
newTo.revision++;
setIsStale();
return { newRundown: rundown, didMutate: true };
@@ -203,6 +203,7 @@ describe('swapEventData', () => {
duration: 1,
delay: 1,
revision: 3,
currentBlock: null,
} as OntimeEvent;
const eventB = {
id: '2',
@@ -212,6 +213,7 @@ describe('swapEventData', () => {
duration: 2,
delay: 2,
revision: 7,
currentBlock: 'testing',
} as OntimeEvent;
const [newA, newB] = swapEventData(eventA, eventB);
@@ -223,7 +225,8 @@ describe('swapEventData', () => {
timeEnd: 1,
duration: 1,
delay: 1,
revision: 4,
revision: 3,
currentBlock: null,
});
expect(newB).toMatchObject({
id: '2',
@@ -232,7 +235,8 @@ describe('swapEventData', () => {
timeEnd: 2,
duration: 2,
delay: 2,
revision: 8,
revision: 7,
currentBlock: 'testing',
});
});
});
@@ -278,10 +278,13 @@ export const swapEventData = (eventA: OntimeEvent, eventB: OntimeEvent): [newA:
timeEnd: eventA.timeEnd,
duration: eventA.duration,
linkStart: eventA.linkStart,
currentBlock: eventA.currentBlock,
// keep schedule metadata
delay: eventA.delay,
gap: eventA.gap,
dayOffset: eventA.dayOffset,
// keep revision number
revision: eventA.revision,
};
const newB = {
@@ -293,10 +296,13 @@ export const swapEventData = (eventA: OntimeEvent, eventB: OntimeEvent): [newA:
timeEnd: eventB.timeEnd,
duration: eventB.duration,
linkStart: eventB.linkStart,
currentBlock: eventB.currentBlock,
// keep schedule metadata
delay: eventB.delay,
gap: eventB.gap,
dayOffset: eventB.dayOffset,
// keep revision number
revision: eventB.revision,
};
return [newA, newB];