mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
refactor: type cleanup and test improvements
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { OntimeBlock, OntimeEvent, RundownEntries, SupportedEntry } from 'ontime-types';
|
import { OntimeBlock, OntimeDelay, OntimeEvent, RundownEntries, SupportedEntry } from 'ontime-types';
|
||||||
|
|
||||||
import { makeRundownMetadata, makeSortableList } from '../rundown.utils';
|
import { makeRundownMetadata, makeSortableList } from '../rundown.utils';
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ describe('makeRundownMetadata()', () => {
|
|||||||
block: {
|
block: {
|
||||||
id: 'block',
|
id: 'block',
|
||||||
type: SupportedEntry.Block,
|
type: SupportedEntry.Block,
|
||||||
events: ['11', '12', '13'],
|
events: ['11', 'delay', '12', '13'],
|
||||||
colour: 'red',
|
colour: 'red',
|
||||||
} as OntimeBlock,
|
} as OntimeBlock,
|
||||||
'11': {
|
'11': {
|
||||||
@@ -36,6 +36,12 @@ describe('makeRundownMetadata()', () => {
|
|||||||
skip: false,
|
skip: false,
|
||||||
linkStart: false,
|
linkStart: false,
|
||||||
} as OntimeEvent,
|
} as OntimeEvent,
|
||||||
|
delay: {
|
||||||
|
id: 'delay',
|
||||||
|
type: SupportedEntry.Delay,
|
||||||
|
parent: 'block',
|
||||||
|
duration: 0,
|
||||||
|
} as OntimeDelay,
|
||||||
'12': {
|
'12': {
|
||||||
id: '12',
|
id: '12',
|
||||||
type: SupportedEntry.Event,
|
type: SupportedEntry.Event,
|
||||||
@@ -136,10 +142,25 @@ describe('makeRundownMetadata()', () => {
|
|||||||
groupColour: 'red',
|
groupColour: 'red',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(process(demoEvents['delay'])).toMatchObject({
|
||||||
|
previousEvent: demoEvents['11'],
|
||||||
|
latestEvent: demoEvents['11'],
|
||||||
|
previousEntryId: demoEvents['11'].id,
|
||||||
|
thisId: demoEvents['delay'].id,
|
||||||
|
eventIndex: 2,
|
||||||
|
isPast: true,
|
||||||
|
isNextDay: false,
|
||||||
|
totalGap: 10,
|
||||||
|
isLinkedToLoaded: false,
|
||||||
|
isLoaded: false,
|
||||||
|
groupId: 'block',
|
||||||
|
groupColour: 'red',
|
||||||
|
});
|
||||||
|
|
||||||
expect(process(demoEvents['12'])).toMatchObject({
|
expect(process(demoEvents['12'])).toMatchObject({
|
||||||
previousEvent: demoEvents['11'],
|
previousEvent: demoEvents['11'],
|
||||||
latestEvent: demoEvents['12'],
|
latestEvent: demoEvents['12'],
|
||||||
previousEntryId: demoEvents['11'].id,
|
previousEntryId: demoEvents['delay'].id,
|
||||||
thisId: demoEvents['12'].id,
|
thisId: demoEvents['12'].id,
|
||||||
eventIndex: 3,
|
eventIndex: 3,
|
||||||
isPast: false,
|
isPast: false,
|
||||||
|
|||||||
@@ -203,6 +203,11 @@ export async function reorderEntry(eventId: EntryId, from: number, to: number):
|
|||||||
return newRundown;
|
return newRundown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies a delay into the rundown effectively changing the schedule
|
||||||
|
* The applied delay is deleted
|
||||||
|
* @param delayId
|
||||||
|
*/
|
||||||
export async function applyDelay(delayId: EntryId) {
|
export async function applyDelay(delayId: EntryId) {
|
||||||
const scopedMutation = cache.mutateCache(cache.applyDelay);
|
const scopedMutation = cache.mutateCache(cache.applyDelay);
|
||||||
await scopedMutation({ delayId });
|
await scopedMutation({ delayId });
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ function processEntry<T extends OntimeEntry>(
|
|||||||
} else if (isOntimeDelay(currentEntry)) {
|
} else if (isOntimeDelay(currentEntry)) {
|
||||||
// !!! this must happen after handling the links
|
// !!! this must happen after handling the links
|
||||||
processedData.totalDelay += currentEntry.duration;
|
processedData.totalDelay += currentEntry.duration;
|
||||||
|
currentEntry.parent = childOfBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!childOfBlock) {
|
if (!childOfBlock) {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ export type RundownEntries = Record<EntryId, OntimeEntry>;
|
|||||||
// we need to create a manual union type since keys cannot be used in type unions
|
// we need to create a manual union type since keys cannot be used in type unions
|
||||||
export type OntimeEntryCommonKeys = keyof OntimeEvent | keyof OntimeDelay | keyof OntimeBlock;
|
export type OntimeEntryCommonKeys = keyof OntimeEvent | keyof OntimeDelay | keyof OntimeBlock;
|
||||||
|
|
||||||
export type ProjectRundowns = Record<string, Rundown>;
|
type RundownId = string;
|
||||||
|
export type ProjectRundowns = Record<RundownId, Rundown>;
|
||||||
|
|
||||||
export type Rundown = {
|
export type Rundown = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user