Swap Event Data (#446)

* use zustand store in `ContextMenuContext`

* add `withDivider` prop to context menu `Option`

* add `isDisabled` prop to `Option`

* create `eventIdSwapping` store

* create swapping context menu options

* fix `key` in ContextMenu

* address `tanstack-eslint` errors

* create initial `requestEventSwap` event

* create initial `swapEvents` action

* use `swapEvents` in `EventBlock`

* move from `emitError` to `logAxiosError`

* remove extra curly brace from Copy ID

* add `clearEventId` func

* finalize context menu swapping logic

* write optimistic swapping logic

* remove unused import and type out handler in `rundownController`

* create `rundownSwapValidator`

* move index increase to `EventBlock`

* move swapping logic from `id` to `index`

* create `swapEvents` endpoint

* move `useEventIdSwapping` hook into its own file

* revert to using event `id`

* logic now uses indexes to swap events

* add `todo` to `swapEvents`

* revert index increment

* create `swapOntimeEvents` and export in `index.ts`

* use `swapOntimeEvents` in frontend & server

* update import path

* remove extra `setCached`
This commit is contained in:
asharonbaltazar
2023-08-15 16:04:53 -04:00
committed by GitHub
parent a46a0e1631
commit 51c31adaf1
17 changed files with 363 additions and 123 deletions
@@ -1,3 +1,5 @@
import { OntimeEvent, OntimeRundown } from 'ontime-types';
import { dayInMs } from '../timeConstants.js';
/**
@@ -13,3 +15,43 @@ export const calculateDuration = (timeStart: number, timeEnd: number): number =>
}
return timeEnd - timeStart;
};
/**
* @description swaps two OntimeEvents in the rundown
* @param {OntimeRundown} rundown
* @param {number} fromEventIndex
* @param {number} toEventIndex
* @returns {OntimeRundown}
*/
export const swapOntimeEvents = (
rundown: OntimeRundown,
fromEventIndex: number,
toEventIndex: number,
): OntimeRundown => {
const updatedRundown = [...rundown];
if (fromEventIndex < 0 || toEventIndex < 0) {
throw new Error('ID not found at index');
}
const fromEvent = updatedRundown.at(fromEventIndex) as OntimeEvent;
const toEvent = updatedRundown.at(toEventIndex) as OntimeEvent;
updatedRundown[fromEventIndex] = {
...toEvent,
timeStart: fromEvent.timeStart,
timeEnd: fromEvent.timeEnd,
duration: fromEvent.duration,
delay: fromEvent.delay,
};
updatedRundown[toEventIndex] = {
...fromEvent,
timeStart: toEvent.timeStart,
timeEnd: toEvent.timeEnd,
duration: toEvent.duration,
delay: toEvent.delay,
};
return updatedRundown;
};