From 8c6ef9bfc30021f48abd35785dc53ccac366beba Mon Sep 17 00:00:00 2001 From: cv <34649812+cpvalente@users.noreply.github.com> Date: Sat, 2 Sep 2023 14:52:44 +0200 Subject: [PATCH] refactor!: rename eventData > project --- apps/client/src/common/api/apiConstants.ts | 4 +-- apps/client/src/common/api/eventDataApi.ts | 21 ------------ apps/client/src/common/api/ontimeApi.ts | 4 +-- apps/client/src/common/api/projectDataApi.ts | 21 ++++++++++++ .../{useEventData.ts => useProjectData.ts} | 14 ++++---- .../models/{EventData.ts => ProjectData.ts} | 4 +-- .../src/features/cuesheet/CuesheetWrapper.tsx | 4 +-- .../CuesheetTableHeader.tsx | 14 ++++---- .../src/features/cuesheet/cuesheetUtils.ts | 7 ++-- .../features/info/info-header/InfoHeader.tsx | 4 +-- .../modals/quick-start/QuickStart.tsx | 30 ++++++++-------- ...{EventDataForm.tsx => ProjectDataForm.tsx} | 30 ++++++++-------- .../modals/settings-modal/SettingsModal.tsx | 6 ++-- .../src/features/viewers/ViewWrapper.tsx | 6 ++-- .../features/viewers/backstage/Backstage.scss | 2 +- .../features/viewers/backstage/Backstage.tsx | 6 ++-- .../viewers/minimal-timer/MinimalTimer.tsx | 3 +- .../src/features/viewers/public/Public.scss | 2 +- .../src/features/viewers/public/Public.tsx | 6 ++-- .../src/features/viewers/timer/Timer.tsx | 3 +- apps/server/src/app.ts | 4 +-- .../src/classes/data-provider/DataProvider.ts | 14 ++++---- .../data-provider/DataProvider.utils.ts | 4 +-- .../__test__/DataProvider.test.ts | 8 ++--- .../src/controllers/ontimeController.ts | 8 ++--- ...DataController.ts => projectController.ts} | 16 ++++----- ...idate.ts => projectController.validate.ts} | 2 +- apps/server/src/models/dataModel.ts | 2 +- apps/server/src/routes/eventDataRouter.ts | 11 ------ apps/server/src/routes/ontimeRouter.ts | 4 +-- apps/server/src/routes/projectRouter.ts | 11 ++++++ .../server/src/utils/__tests__/parser.test.ts | 18 +++++----- apps/server/src/utils/parser.ts | 31 ++++++++++------- apps/server/src/utils/parserFunctions.ts | 34 +++++++++---------- apps/server/test-db/db.json | 2 +- apps/test-db/db.json | 2 +- demo-db/db.json | 2 +- e2e/tests/fixtures/test-db.json | 2 +- .../types/src/definitions/DataModel.type.ts | 4 +-- ...{EventData.type.ts => ProjectData.type.ts} | 2 +- packages/types/src/index.ts | 4 +-- 41 files changed, 191 insertions(+), 185 deletions(-) delete mode 100644 apps/client/src/common/api/eventDataApi.ts create mode 100644 apps/client/src/common/api/projectDataApi.ts rename apps/client/src/common/hooks-query/{useEventData.ts => useProjectData.ts} (54%) rename apps/client/src/common/models/{EventData.ts => ProjectData.ts} (53%) rename apps/client/src/features/modals/settings-modal/{EventDataForm.tsx => ProjectDataForm.tsx} (80%) rename apps/server/src/controllers/{eventDataController.ts => projectController.ts} (60%) rename apps/server/src/controllers/{eventDataController.validate.ts => projectController.validate.ts} (94%) delete mode 100644 apps/server/src/routes/eventDataRouter.ts create mode 100644 apps/server/src/routes/projectRouter.ts rename packages/types/src/definitions/core/{EventData.type.ts => ProjectData.type.ts} (82%) diff --git a/apps/client/src/common/api/apiConstants.ts b/apps/client/src/common/api/apiConstants.ts index d94553ac6..f3a19e46f 100644 --- a/apps/client/src/common/api/apiConstants.ts +++ b/apps/client/src/common/api/apiConstants.ts @@ -1,5 +1,5 @@ // REST stuff -export const EVENT_DATA = ['eventdata']; +export const PROJECT_DATA = ['project']; export const ALIASES = ['aliases']; export const USERFIELDS = ['userFields']; export const RUNDOWN_TABLE_KEY = 'rundown'; @@ -19,7 +19,7 @@ export const serverPort = isProduction ? location.port : STATIC_PORT; export const serverURL = `${location.protocol}//${location.hostname}:${serverPort}`; export const websocketUrl = `${socketProtocol}://${location.hostname}:${serverPort}/ws`; -export const eventURL = `${serverURL}/eventdata`; +export const projectDataURL = `${serverURL}/project`; export const rundownURL = `${serverURL}/events`; export const ontimeURL = `${serverURL}/ontime`; diff --git a/apps/client/src/common/api/eventDataApi.ts b/apps/client/src/common/api/eventDataApi.ts deleted file mode 100644 index 9e29750ea..000000000 --- a/apps/client/src/common/api/eventDataApi.ts +++ /dev/null @@ -1,21 +0,0 @@ -import axios from 'axios'; -import { EventData } from 'ontime-types'; - -import { eventURL } from './apiConstants'; - -/** - * @description HTTP request to fetch event data - * @return {Promise} - */ -export async function fetchEventData(): Promise { - const res = await axios.get(eventURL); - return res.data; -} - -/** - * @description HTTP request to mutate event data - * @return {Promise} - */ -export async function postEventData(data: EventData) { - return axios.post(eventURL, data); -} diff --git a/apps/client/src/common/api/ontimeApi.ts b/apps/client/src/common/api/ontimeApi.ts index 6fc503259..6e9d6b4c6 100644 --- a/apps/client/src/common/api/ontimeApi.ts +++ b/apps/client/src/common/api/ontimeApi.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Alias, EventData, OSCSettings, OscSubscription, Settings, UserFields, ViewSettings } from 'ontime-types'; +import { Alias, OSCSettings, OscSubscription, ProjectData, Settings, UserFields, ViewSettings } from 'ontime-types'; import { apiRepoLatest } from '../../externals'; import { InfoType } from '../models/Info'; @@ -178,6 +178,6 @@ export async function getLatestVersion(): Promise { }; } -export async function postNew(initialData: Partial) { +export async function postNew(initialData: Partial) { return axios.post(`${ontimeURL}/new`, initialData); } diff --git a/apps/client/src/common/api/projectDataApi.ts b/apps/client/src/common/api/projectDataApi.ts new file mode 100644 index 000000000..b89bebffb --- /dev/null +++ b/apps/client/src/common/api/projectDataApi.ts @@ -0,0 +1,21 @@ +import axios from 'axios'; +import { ProjectData } from 'ontime-types'; + +import { projectDataURL } from './apiConstants'; + +/** + * @description HTTP request to fetch project data + * @return {Promise} + */ +export async function getProjectData(): Promise { + const res = await axios.get(projectDataURL); + return res.data; +} + +/** + * @description HTTP request to mutate project data + * @return {Promise} + */ +export async function postProjectData(data: ProjectData) { + return axios.post(projectDataURL, data); +} diff --git a/apps/client/src/common/hooks-query/useEventData.ts b/apps/client/src/common/hooks-query/useProjectData.ts similarity index 54% rename from apps/client/src/common/hooks-query/useEventData.ts rename to apps/client/src/common/hooks-query/useProjectData.ts index 215605e31..707a24018 100644 --- a/apps/client/src/common/hooks-query/useEventData.ts +++ b/apps/client/src/common/hooks-query/useProjectData.ts @@ -1,15 +1,15 @@ import { useQuery } from '@tanstack/react-query'; import { queryRefetchIntervalSlow } from '../../ontimeConfig'; -import { EVENT_DATA } from '../api/apiConstants'; -import { fetchEventData } from '../api/eventDataApi'; -import { eventDataPlaceholder } from '../models/EventData'; +import { PROJECT_DATA } from '../api/apiConstants'; +import { getProjectData } from '../api/projectDataApi'; +import { projectDataPlaceholder } from '../models/ProjectData'; -export default function useEventData() { +export default function useProjectData() { const { data, status, isFetching, isError, refetch } = useQuery({ - queryKey: EVENT_DATA, - queryFn: fetchEventData, - placeholderData: eventDataPlaceholder, + queryKey: PROJECT_DATA, + queryFn: getProjectData, + placeholderData: projectDataPlaceholder, retry: 5, retryDelay: (attempt) => attempt * 2500, refetchInterval: queryRefetchIntervalSlow, diff --git a/apps/client/src/common/models/EventData.ts b/apps/client/src/common/models/ProjectData.ts similarity index 53% rename from apps/client/src/common/models/EventData.ts rename to apps/client/src/common/models/ProjectData.ts index 9add8fee4..142748e82 100644 --- a/apps/client/src/common/models/EventData.ts +++ b/apps/client/src/common/models/ProjectData.ts @@ -1,6 +1,6 @@ -import { EventData } from 'ontime-types'; +import { ProjectData } from 'ontime-types'; -export const eventDataPlaceholder: EventData = { +export const projectDataPlaceholder: ProjectData = { title: '', description: '', publicUrl: '', diff --git a/apps/client/src/features/cuesheet/CuesheetWrapper.tsx b/apps/client/src/features/cuesheet/CuesheetWrapper.tsx index c2f92e0ec..e6e8e432f 100644 --- a/apps/client/src/features/cuesheet/CuesheetWrapper.tsx +++ b/apps/client/src/features/cuesheet/CuesheetWrapper.tsx @@ -1,5 +1,5 @@ import { useCallback, useEffect, useMemo } from 'react'; -import { EventData, OntimeRundownEntry } from 'ontime-types'; +import { OntimeRundownEntry, ProjectData } from 'ontime-types'; import Empty from '../../common/components/state/Empty'; import { useEventAction } from '../../common/hooks/useEventAction'; @@ -69,7 +69,7 @@ export default function CuesheetWrapper() { ); const exportHandler = useCallback( - (headerData: EventData) => { + (headerData: ProjectData) => { if (!headerData || !rundown || !userFields) { return; } diff --git a/apps/client/src/features/cuesheet/cuesheet-table-header/CuesheetTableHeader.tsx b/apps/client/src/features/cuesheet/cuesheet-table-header/CuesheetTableHeader.tsx index 52e3cda2b..c52586882 100644 --- a/apps/client/src/features/cuesheet/cuesheet-table-header/CuesheetTableHeader.tsx +++ b/apps/client/src/features/cuesheet/cuesheet-table-header/CuesheetTableHeader.tsx @@ -3,12 +3,12 @@ import { IoContract } from '@react-icons/all-files/io5/IoContract'; import { IoExpand } from '@react-icons/all-files/io5/IoExpand'; import { IoLocate } from '@react-icons/all-files/io5/IoLocate'; import { IoSettingsOutline } from '@react-icons/all-files/io5/IoSettingsOutline'; -import { EventData, Playback } from 'ontime-types'; +import { Playback, ProjectData } from 'ontime-types'; import { formatDisplay } from 'ontime-utils'; import useFullscreen from '../../../common/hooks/useFullscreen'; import { useTimer } from '../../../common/hooks/useSocket'; -import useEventData from '../../../common/hooks-query/useEventData'; +import useProjectData from '../../../common/hooks-query/useProjectData'; import { formatTime } from '../../../common/utils/time'; import { tooltipDelayFast } from '../../../ontimeConfig'; import { useCuesheetSettings } from '../store/CuesheetSettings'; @@ -17,7 +17,7 @@ import PlaybackIcon from '../tableElements/PlaybackIcon'; import style from './CuesheetTableHeader.module.scss'; interface CuesheetTableHeaderProps { - handleCSVExport: (headerData: EventData) => void; + handleCSVExport: (headerData: ProjectData) => void; featureData: { playback: Playback; selectedEventIndex: number | null; @@ -33,11 +33,11 @@ export default function CuesheetTableHeader({ handleCSVExport, featureData }: Cu const toggleFollow = useCuesheetSettings((state) => state.toggleFollow); const timer = useTimer(); const { isFullScreen, toggleFullScreen } = useFullscreen(); - const { data: event } = useEventData(); + const { data: project } = useProjectData(); const exportCsv = () => { - if (event) { - handleCSVExport(event); + if (project) { + handleCSVExport(project); } }; @@ -58,7 +58,7 @@ export default function CuesheetTableHeader({ handleCSVExport, featureData }: Cu return (
-
{event?.title || '-'}
+
{project?.title || '-'}
{featureData?.titleNow || '-'}
diff --git a/apps/client/src/features/cuesheet/cuesheetUtils.ts b/apps/client/src/features/cuesheet/cuesheetUtils.ts index 8a1f93ca9..a85f707fc 100644 --- a/apps/client/src/features/cuesheet/cuesheetUtils.ts +++ b/apps/client/src/features/cuesheet/cuesheetUtils.ts @@ -1,5 +1,5 @@ import { stringify } from 'csv-stringify/browser/esm/sync'; -import { EventData, OntimeEntryCommonKeys, OntimeRundown, UserFields } from 'ontime-types'; +import { OntimeEntryCommonKeys, OntimeRundown, ProjectData, UserFields } from 'ontime-types'; import { millisToString } from 'ontime-utils'; /** @@ -38,10 +38,11 @@ export const parseField = (field: keyof OntimeRundown, data: unknown): string => * @param {object} userFields * @return {(string[])[]} */ -export const makeTable = (headerData: EventData, rundown: OntimeRundown, userFields: UserFields): string[][] => { +export const makeTable = (headerData: ProjectData, rundown: OntimeRundown, userFields: UserFields): string[][] => { const data = [ ['Ontime ยท Schedule Template'], - ['Event Name', headerData?.title || ''], + ['Project Title', headerData?.title || ''], + ['Project Description', headerData?.description || ''], ['Public URL', headerData?.publicUrl || ''], ['Backstage URL', headerData?.backstageUrl || ''], [], diff --git a/apps/client/src/features/info/info-header/InfoHeader.tsx b/apps/client/src/features/info/info-header/InfoHeader.tsx index 577d53932..5877e1c5a 100644 --- a/apps/client/src/features/info/info-header/InfoHeader.tsx +++ b/apps/client/src/features/info/info-header/InfoHeader.tsx @@ -1,9 +1,9 @@ -import useEventData from '../../../common/hooks-query/useEventData'; +import useProjectData from '../../../common/hooks-query/useProjectData'; import style from '../Info.module.scss'; export default function InfoHeader({ selected }: { selected: string }) { - const { data } = useEventData(); + const { data } = useProjectData(); return ( <> diff --git a/apps/client/src/features/modals/quick-start/QuickStart.tsx b/apps/client/src/features/modals/quick-start/QuickStart.tsx index c3eae49cf..5fbc675c6 100644 --- a/apps/client/src/features/modals/quick-start/QuickStart.tsx +++ b/apps/client/src/features/modals/quick-start/QuickStart.tsx @@ -16,12 +16,12 @@ import { ModalOverlay, Textarea, } from '@chakra-ui/react'; -import type { EventData } from 'ontime-types'; +import type { ProjectData } from 'ontime-types'; -import { EVENT_DATA, RUNDOWN_TABLE } from '../../../common/api/apiConstants'; +import { PROJECT_DATA, RUNDOWN_TABLE } from '../../../common/api/apiConstants'; import { postNew } from '../../../common/api/ontimeApi'; -import useEventData from '../../../common/hooks-query/useEventData'; -import { eventDataPlaceholder } from '../../../common/models/EventData'; +import useProjectData from '../../../common/hooks-query/useProjectData'; +import { projectDataPlaceholder } from '../../../common/models/ProjectData'; import { ontimeQueryClient } from '../../../common/queryClient'; import styles from '../Modal.module.scss'; @@ -32,7 +32,7 @@ interface QuickStartProps { } export default function QuickStart({ onClose, isOpen }: QuickStartProps) { - const { data, status } = useEventData(); + const { data, status } = useProjectData(); const { handleSubmit, register, @@ -49,10 +49,10 @@ export default function QuickStart({ onClose, isOpen }: QuickStartProps) { if (data) reset(data); }, [data, reset]); - const onSubmit = async (data: Partial) => { + const onSubmit = async (data: Partial) => { try { await postNew(data); - await ontimeQueryClient.invalidateQueries(EVENT_DATA); + await ontimeQueryClient.invalidateQueries(PROJECT_DATA); await ontimeQueryClient.invalidateQueries(RUNDOWN_TABLE); onClose(); @@ -61,7 +61,7 @@ export default function QuickStart({ onClose, isOpen }: QuickStartProps) { } }; - const onReset = () => reset(eventDataPlaceholder); + const onReset = () => reset(projectDataPlaceholder); const disableButtons = status !== 'success' || isSubmitting; return ( @@ -86,13 +86,13 @@ export default function QuickStart({ onClose, isOpen }: QuickStartProps) {
Note - On submit, application options will be kept but rundown and event data will be reset + On submit, application options will be kept but rundown and project data will be reset