From bdeb087e2849bdda0420996db464cf8cc542619b Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Fri, 10 Oct 2025 06:42:42 +0200 Subject: [PATCH] fix: op gets params from preset context --- apps/client/src/AppRouter.tsx | 2 + .../features/operator/operator.options.tsx | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/apps/client/src/AppRouter.tsx b/apps/client/src/AppRouter.tsx index 711b5e13c..c68bc6d0e 100644 --- a/apps/client/src/AppRouter.tsx +++ b/apps/client/src/AppRouter.tsx @@ -207,6 +207,8 @@ function PresetView() { /** * Locked presets do not allow configuration changes * Whether the user can navigate is determined by the locked param + * + * We inject the preset to the context value for the view to consume */ const Component = PresetViewMap[preset.target as OntimeViewPresettable]; return ( diff --git a/apps/client/src/features/operator/operator.options.tsx b/apps/client/src/features/operator/operator.options.tsx index 3c18e1705..0561c90f0 100644 --- a/apps/client/src/features/operator/operator.options.tsx +++ b/apps/client/src/features/operator/operator.options.tsx @@ -1,6 +1,6 @@ -import { useMemo } from 'react'; +import { use, useMemo } from 'react'; import { useSearchParams } from 'react-router'; -import { CustomFields, OntimeEvent } from 'ontime-types'; +import { CustomFields, EntryId, OntimeEvent } from 'ontime-types'; import { getTimeOption } from '../../common/components/view-params-editor/common.options'; import { OptionTitle } from '../../common/components/view-params-editor/constants'; @@ -9,6 +9,7 @@ import { makeCustomFieldSelectOptions, makeOptionsFromCustomFields, } from '../../common/components/view-params-editor/viewParams.utils'; +import { PresetContext } from '../../common/context/PresetContext'; import { isStringBoolean } from '../viewers/common/viewUtils'; export const getOperatorOptions = (customFields: CustomFields, timeFormat: string): ViewOption[] => { @@ -93,15 +94,26 @@ type OperatorOptions = { * Utility extract the view options from URL Params * the names and fallback are manually matched with timerOptions */ -function getOptionsFromParams(searchParams: URLSearchParams): OperatorOptions { +function getOptionsFromParams(searchParams: URLSearchParams, defaultValues?: URLSearchParams): OperatorOptions { + // Helper to get value from either source, prioritizing defaultValues + const getValue = (key: string) => defaultValues?.get(key) ?? searchParams.get(key); + + // Helper to get array values from either source + const getArrayValues = (key: string): EntryId[] => { + if (defaultValues?.has(key)) { + return defaultValues.getAll(key) as EntryId[]; + } + return searchParams.getAll(key) as EntryId[]; + }; + // we manually make an object that matches the key above return { - mainSource: searchParams.get('main') as keyof OntimeEvent | null, - secondarySource: searchParams.get('secondary-src') as keyof OntimeEvent | null, - subscribe: searchParams.getAll('subscribe'), - shouldEdit: isStringBoolean(searchParams.get('shouldEdit')), - hidePast: isStringBoolean(searchParams.get('hidePast')), - showStart: isStringBoolean(searchParams.get('showStart')), + mainSource: getValue('main') as keyof OntimeEvent | null, + secondarySource: getValue('secondary-src') as keyof OntimeEvent | null, + subscribe: getArrayValues('subscribe'), + shouldEdit: isStringBoolean(getValue('shouldEdit')), + hidePast: isStringBoolean(getValue('hidePast')), + showStart: isStringBoolean(getValue('showStart')), }; } @@ -110,6 +122,12 @@ function getOptionsFromParams(searchParams: URLSearchParams): OperatorOptions { */ export function useOperatorOptions(): OperatorOptions { const [searchParams] = useSearchParams(); - const options = useMemo(() => getOptionsFromParams(searchParams), [searchParams]); + const maybePreset = use(PresetContext); + + const options = useMemo(() => { + const defaultValues = maybePreset ? new URLSearchParams(maybePreset.search) : undefined; + return getOptionsFromParams(searchParams, defaultValues); + }, [maybePreset, searchParams]); + return options; }