fix: guard corrupted parent on delete

This commit is contained in:
Carlos Valente
2025-07-14 06:03:19 +02:00
parent dd47d2b7e7
commit 55e34b5f9a
2 changed files with 17 additions and 4 deletions
@@ -808,8 +808,12 @@ function optimisticDeleteEntries(entryIds: EntryId[], rundown: Rundown) {
if (isOntimeBlock(entry) || !entry.parent) {
order = order.filter((id) => id !== entry.id);
} else {
const parent = entries[entry.parent] as OntimeBlock;
parent.entries = parent.entries.filter((parentEntry) => parentEntry !== entry.id);
const parent = entries[entry.parent];
if ('parent' in entries) {
(parent as OntimeBlock).entries = (parent as OntimeBlock).entries.filter(
(parentEntry) => parentEntry !== entry.id,
);
}
}
delete entries[entry.id];
@@ -40,6 +40,7 @@ import {
getUniqueId,
} from './rundown.utils.js';
import { makeRundownMetadata, ProcessedRundownMetadata } from './rundown.parser.js';
import { consoleError } from '../../utils/console.js';
/**
* The currently loaded rundown in cache
@@ -243,8 +244,16 @@ function remove(rundown: Rundown, entry: OntimeEntry) {
}
} else if (entry.parent) {
// 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;
if (parentBlock) {
const parentBlock = rundown.entries[entry.parent];
// 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
const filteredEvents = deleteById(parentBlock.entries, entry.id);
edit(rundown, { id: parentBlock.id, entries: filteredEvents });