mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-05 22:39:11 +00:00
fix: guard corrupted parent on delete
This commit is contained in:
@@ -808,8 +808,12 @@ function optimisticDeleteEntries(entryIds: EntryId[], rundown: Rundown) {
|
|||||||
if (isOntimeBlock(entry) || !entry.parent) {
|
if (isOntimeBlock(entry) || !entry.parent) {
|
||||||
order = order.filter((id) => id !== entry.id);
|
order = order.filter((id) => id !== entry.id);
|
||||||
} else {
|
} else {
|
||||||
const parent = entries[entry.parent] as OntimeBlock;
|
const parent = entries[entry.parent];
|
||||||
parent.entries = parent.entries.filter((parentEntry) => parentEntry !== entry.id);
|
if ('parent' in entries) {
|
||||||
|
(parent as OntimeBlock).entries = (parent as OntimeBlock).entries.filter(
|
||||||
|
(parentEntry) => parentEntry !== entry.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete entries[entry.id];
|
delete entries[entry.id];
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import {
|
|||||||
getUniqueId,
|
getUniqueId,
|
||||||
} from './rundown.utils.js';
|
} from './rundown.utils.js';
|
||||||
import { makeRundownMetadata, ProcessedRundownMetadata } from './rundown.parser.js';
|
import { makeRundownMetadata, ProcessedRundownMetadata } from './rundown.parser.js';
|
||||||
|
import { consoleError } from '../../utils/console.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The currently loaded rundown in cache
|
* The currently loaded rundown in cache
|
||||||
@@ -243,8 +244,16 @@ function remove(rundown: Rundown, entry: OntimeEntry) {
|
|||||||
}
|
}
|
||||||
} else if (entry.parent) {
|
} else if (entry.parent) {
|
||||||
// at this point, we are handling entries inside a block, so we need to remove the reference
|
// at this point, we are handling entries inside a block, so we need to remove the reference
|
||||||
const parentBlock = rundown.entries[entry.parent] as OntimeBlock;
|
const parentBlock = rundown.entries[entry.parent];
|
||||||
if (parentBlock) {
|
|
||||||
|
// eslint-disable-next-line no-unused-labels -- dev code path
|
||||||
|
DEV: {
|
||||||
|
if (parentBlock && !isOntimeBlock(parentBlock)) {
|
||||||
|
consoleError(`Parent block with ID ${entry.parent} is not a valid OntimeBlock`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentBlock && isOntimeBlock(parentBlock)) {
|
||||||
// we call a mutation to the parent event to remove the entry from the events
|
// we call a mutation to the parent event to remove the entry from the events
|
||||||
const filteredEvents = deleteById(parentBlock.entries, entry.id);
|
const filteredEvents = deleteById(parentBlock.entries, entry.id);
|
||||||
edit(rundown, { id: parentBlock.id, entries: filteredEvents });
|
edit(rundown, { id: parentBlock.id, entries: filteredEvents });
|
||||||
|
|||||||
Reference in New Issue
Block a user