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,4 +1,3 @@
import { OntimeEvent } from 'ontime-types';
import { failEmptyObjects } from '../utils/routerUtils.js';
import {
addEvent,
@@ -7,19 +6,21 @@ import {
deleteEvent,
editEvent,
reorderEvent,
swapEvents,
} from '../services/rundown-service/RundownService.js';
import { getDelayedRundown } from '../services/rundown-service/delayedRundown.utils.js';
import { RequestHandler } from 'express';
// Create controller for GET request to '/events'
// Returns -
export const rundownGetAll = async (req, res) => {
export const rundownGetAll: RequestHandler = async (_req, res) => {
const delayedRundown = getDelayedRundown();
res.json(delayedRundown);
};
// Create controller for POST request to '/events/'
// Returns -
export const rundownPost = async (req, res) => {
export const rundownPost: RequestHandler = async (req, res) => {
if (failEmptyObjects(req.body, res)) {
return;
}
@@ -34,7 +35,7 @@ export const rundownPost = async (req, res) => {
// Create controller for PUT request to '/events/'
// Returns -
export const rundownPut = async (req, res) => {
export const rundownPut: RequestHandler = async (req, res) => {
if (failEmptyObjects(req.body, res)) {
return;
}
@@ -47,7 +48,7 @@ export const rundownPut = async (req, res) => {
}
};
export const rundownReorder = async (req, res) => {
export const rundownReorder: RequestHandler = async (req, res) => {
if (failEmptyObjects(req.body, res)) {
return;
}
@@ -61,9 +62,23 @@ export const rundownReorder = async (req, res) => {
}
};
export const rundownSwap: RequestHandler = async (req, res) => {
if (failEmptyObjects(req.body, res)) {
return;
}
try {
const { from, to } = req.body;
await swapEvents(from, to);
res.sendStatus(200);
} catch (error) {
res.status(400).send(error);
}
};
// Create controller for PATCH request to '/events/applydelay/:eventId'
// Returns -
export const rundownApplyDelay = async (req, res) => {
export const rundownApplyDelay: RequestHandler = async (req, res) => {
try {
await applyDelay(req.params.eventId);
res.sendStatus(200);
@@ -74,7 +89,7 @@ export const rundownApplyDelay = async (req, res) => {
// Create controller for DELETE request to '/events/:eventId'
// Returns -
export const deleteEventById = async (req, res) => {
export const deleteEventById: RequestHandler = async (req, res) => {
try {
await deleteEvent(req.params.eventId);
res.sendStatus(204);
@@ -85,7 +100,7 @@ export const deleteEventById = async (req, res) => {
// Create controller for DELETE request to '/events/'
// Returns -
export const rundownDelete = async (req, res) => {
export const rundownDelete: RequestHandler = async (req, res) => {
try {
await deleteAllEvents();
res.sendStatus(204);