feat: multiple selection (#703)

feat: multiple event selection

---------

Co-authored-by: asharonbaltazar <asharonbaltazar@outlook.com>
Co-authored-by: Alex <ac@omnivox.dk>
This commit is contained in:
Carlos Valente
2024-01-12 13:07:56 +01:00
committed by GitHub
parent f965db148c
commit 7f63cde7a5
20 changed files with 460 additions and 171 deletions
@@ -21,6 +21,7 @@ import {
cachedClear,
cachedDelete,
cachedEdit,
cachedBatchEdit,
cachedReorder,
cachedSwap,
delayedRundownCacheKey,
@@ -212,6 +213,16 @@ export async function editEvent(eventData: Partial<OntimeEvent> | Partial<Ontime
return newEvent;
}
export async function batchEditEvents(ids: string[], data: Partial<OntimeEvent>) {
await cachedBatchEdit(ids, data);
// notify timer service of changed events
updateTimer(ids);
// advice socket subscribers of change
sendRefetch();
}
/**
* deletes event by its ID
* @param eventId
@@ -115,7 +115,17 @@ export async function cachedEdit(
}
const updatedRundown = DataProvider.getRundown();
const newEvent = { ...updatedRundown[indexInMemory], ...patchObject } as OntimeRundownEntry;
const eventFromRundown = updatedRundown[indexInMemory];
const isPatchObjectDifferentFromRundownEvent = Object.entries(patchObject).some(
([key, value]) => eventFromRundown[key] !== value,
);
if (!isPatchObjectDifferentFromRundownEvent) {
return eventFromRundown;
}
const newEvent = { ...eventFromRundown, ...patchObject } as OntimeRundownEntry;
if (isOntimeEvent(newEvent)) {
newEvent.revision++;
}
@@ -144,6 +154,12 @@ export async function cachedEdit(
return newEvent;
}
export async function cachedBatchEdit(ids: string[], patchObject: Partial<OntimeEvent>) {
const cachedEdits = ids.map((id) => cachedEdit(id, patchObject));
await Promise.allSettled(cachedEdits);
}
/**
* Deletes an event with given id from rundown, ensuring replication to delayed rundown cache
* @param eventId