mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 10:23:54 +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) {
|
||||
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 });
|
||||
|
||||
Reference in New Issue
Block a user