refactor: apply param structure

This commit is contained in:
Carlos Valente
2025-01-24 22:03:52 +01:00
committed by Carlos Valente
parent 4503d1e411
commit bb1e9072fd
14 changed files with 629 additions and 499 deletions
@@ -38,3 +38,14 @@ export const showLeadingZeros: ParamField = {
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}; };
export enum OptionTitle {
ClockOptions = 'Clock Options',
TimerOptions = 'Timer Options',
DataSources = 'Data sources',
ElementVisibility = 'Element visibility',
BehaviourOptions = 'View behaviour',
StyleOverride = 'View style override',
Animation = 'View animation',
Schedule = 'Schedule options',
}
@@ -1,3 +1,5 @@
import { OptionTitle } from './constants';
type BaseField = { type BaseField = {
id: string; id: string;
title: string; title: string;
@@ -26,7 +28,7 @@ export type ParamField = BaseField &
(OptionsField | MultiOptionsField | StringField | NumberField | BooleanField | ColourField | PersistedField); (OptionsField | MultiOptionsField | StringField | NumberField | BooleanField | ColourField | PersistedField);
export type ViewOption = { export type ViewOption = {
title: string; title: OptionTitle;
options: ParamField[]; options: ParamField[];
collapsible?: boolean; collapsible?: boolean;
}; };
@@ -1,6 +1,10 @@
import { CustomFields } from 'ontime-types'; import { CustomFields } from 'ontime-types';
import { getTimeOption, makeOptionsFromCustomFields } from '../../common/components/view-params-editor/constants'; import {
getTimeOption,
makeOptionsFromCustomFields,
OptionTitle,
} from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/types'; import { ViewOption } from '../../common/components/view-params-editor/types';
export const getOperatorOptions = (customFields: CustomFields, timeFormat: string): ViewOption[] => { export const getOperatorOptions = (customFields: CustomFields, timeFormat: string): ViewOption[] => {
@@ -14,10 +18,11 @@ export const getOperatorOptions = (customFields: CustomFields, timeFormat: strin
}, {}); }, {});
return [ return [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), {
{ section: 'Data sources' }, title: OptionTitle.DataSources,
collapsible: true,
options: [
{ {
id: 'main', id: 'main',
title: 'Main data field', title: 'Main data field',
@@ -41,7 +46,12 @@ export const getOperatorOptions = (customFields: CustomFields, timeFormat: strin
type: 'multi-option', type: 'multi-option',
values: customFieldSelect, values: customFieldSelect,
}, },
{ section: 'Element visibility' }, ],
},
{
title: OptionTitle.ElementVisibility,
collapsible: true,
options: [
{ {
id: 'hidepast', id: 'hidepast',
title: 'Hide Past Events', title: 'Hide Past Events',
@@ -56,5 +66,7 @@ export const getOperatorOptions = (customFields: CustomFields, timeFormat: strin
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
}; };
@@ -1,15 +1,21 @@
import { CustomFields } from 'ontime-types'; import { CustomFields } from 'ontime-types';
import { getTimeOption, makeOptionsFromCustomFields } from '../../../common/components/view-params-editor/constants'; import {
getTimeOption,
makeOptionsFromCustomFields,
OptionTitle,
} from '../../../common/components/view-params-editor/constants';
import { ViewOption } from '../../../common/components/view-params-editor/types'; import { ViewOption } from '../../../common/components/view-params-editor/types';
export const getBackstageOptions = (timeFormat: string, customFields: CustomFields): ViewOption[] => { export const getBackstageOptions = (timeFormat: string, customFields: CustomFields): ViewOption[] => {
const secondaryOptions = makeOptionsFromCustomFields(customFields, { note: 'Note' }); const secondaryOptions = makeOptionsFromCustomFields(customFields, { note: 'Note' });
return [ return [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), {
{ section: 'Data sources' }, title: OptionTitle.DataSources,
collapsible: true,
options: [
{ {
id: 'secondary-src', id: 'secondary-src',
title: 'Event secondary text', title: 'Event secondary text',
@@ -18,7 +24,13 @@ export const getBackstageOptions = (timeFormat: string, customFields: CustomFiel
values: secondaryOptions, values: secondaryOptions,
defaultValue: '', defaultValue: '',
}, },
{ section: 'Schedule options' }, ],
},
{
title: OptionTitle.Schedule,
collapsible: true,
options: [
{ {
id: 'eventsPerPage', id: 'eventsPerPage',
title: 'Events per page', title: 'Events per page',
@@ -40,5 +52,7 @@ export const getBackstageOptions = (timeFormat: string, customFields: CustomFiel
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
}; };
@@ -1,10 +1,12 @@
import { getTimeOption } from '../../../common/components/view-params-editor/constants'; import { getTimeOption, OptionTitle } from '../../../common/components/view-params-editor/constants';
import { ViewOption } from '../../../common/components/view-params-editor/types'; import { ViewOption } from '../../../common/components/view-params-editor/types';
export const getClockOptions = (timeFormat: string): ViewOption[] => [ export const getClockOptions = (timeFormat: string): ViewOption[] => [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), {
{ section: 'View style override' }, title: OptionTitle.ClockOptions,
collapsible: true,
options: [
{ {
id: 'key', id: 'key',
title: 'Key Colour', title: 'Key Colour',
@@ -70,4 +72,6 @@ export const getClockOptions = (timeFormat: string): ViewOption[] => [
type: 'number', type: 'number',
placeholder: '0 (default)', placeholder: '0 (default)',
}, },
],
},
]; ];
@@ -1,7 +1,7 @@
import { getTimeOption, hideTimerSeconds } from '../../../common/components/view-params-editor/constants'; import { getTimeOption, hideTimerSeconds, OptionTitle } from '../../../common/components/view-params-editor/constants';
import { ViewOption } from '../../../common/components/view-params-editor/types'; import { ParamField, ViewOption } from '../../../common/components/view-params-editor/types';
const makePersistedField = (id: string, value: string): ViewOption => { const makePersistedField = (id: string, value: string): ParamField => {
return { return {
id, id,
title: 'Used to keep the selection on submit', title: 'Used to keep the selection on submit',
@@ -13,11 +13,12 @@ const makePersistedField = (id: string, value: string): ViewOption => {
type Persisted = { id: string; value: string }; type Persisted = { id: string; value: string };
export const getCountdownOptions = (timeFormat: string, persisted?: Persisted): ViewOption[] => [ export const getCountdownOptions = (timeFormat: string, persisted?: Persisted): ViewOption[] => [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), { title: OptionTitle.TimerOptions, collapsible: true, options: [hideTimerSeconds] },
{ section: 'Timer Options' }, {
hideTimerSeconds, title: OptionTitle.BehaviourOptions,
{ section: 'View behaviour' }, collapsible: true,
options: [
{ {
id: 'showProjected', id: 'showProjected',
title: 'Show projected time', title: 'Show projected time',
@@ -26,4 +27,6 @@ export const getCountdownOptions = (timeFormat: string, persisted?: Persisted):
defaultValue: false, defaultValue: false,
}, },
...(persisted ? [makePersistedField(persisted.id, persisted.value)] : []), ...(persisted ? [makePersistedField(persisted.id, persisted.value)] : []),
],
},
]; ];
@@ -1,6 +1,6 @@
import { CustomFields } from 'ontime-types'; import { CustomFields } from 'ontime-types';
import { makeOptionsFromCustomFields } from '../../../common/components/view-params-editor/constants'; import { makeOptionsFromCustomFields, OptionTitle } from '../../../common/components/view-params-editor/constants';
import { ViewOption } from '../../../common/components/view-params-editor/types'; import { ViewOption } from '../../../common/components/view-params-editor/types';
export const getLowerThirdOptions = (customFields: CustomFields): ViewOption[] => { export const getLowerThirdOptions = (customFields: CustomFields): ViewOption[] => {
@@ -16,7 +16,10 @@ export const getLowerThirdOptions = (customFields: CustomFields): ViewOption[] =
}); });
return [ return [
{ section: 'Data sources' }, {
title: OptionTitle.DataSources,
collapsible: true,
options: [
{ {
id: 'top-src', id: 'top-src',
title: 'Top Text', title: 'Top Text',
@@ -33,7 +36,13 @@ export const getLowerThirdOptions = (customFields: CustomFields): ViewOption[] =
values: bottomSourceOptions, values: bottomSourceOptions,
defaultValue: 'none', defaultValue: 'none',
}, },
{ section: 'View animation' }, ],
},
{
title: OptionTitle.Animation,
collapsible: true,
options: [
{ {
id: 'transition', id: 'transition',
title: 'Transition', title: 'Transition',
@@ -48,7 +57,13 @@ export const getLowerThirdOptions = (customFields: CustomFields): ViewOption[] =
type: 'number', type: 'number',
placeholder: '3 (default)', placeholder: '3 (default)',
}, },
{ section: 'View style override' }, ],
},
{
title: OptionTitle.StyleOverride,
collapsible: true,
options: [
{ {
id: 'top-size', id: 'top-size',
title: 'Top Text Size', title: 'Top Text Size',
@@ -113,5 +128,7 @@ export const getLowerThirdOptions = (customFields: CustomFields): ViewOption[] =
type: 'colour', type: 'colour',
defaultValue: 'FF0000', defaultValue: 'FF0000',
}, },
],
},
]; ];
}; };
@@ -1,11 +1,16 @@
import { hideTimerSeconds, showLeadingZeros } from '../../../common/components/view-params-editor/constants'; import {
hideTimerSeconds,
OptionTitle,
showLeadingZeros,
} from '../../../common/components/view-params-editor/constants';
import { ViewOption } from '../../../common/components/view-params-editor/types'; import { ViewOption } from '../../../common/components/view-params-editor/types';
export const MINIMAL_TIMER_OPTIONS: ViewOption[] = [ export const MINIMAL_TIMER_OPTIONS: ViewOption[] = [
{ section: 'Timer Options' }, { title: OptionTitle.TimerOptions, collapsible: true, options: [hideTimerSeconds, showLeadingZeros] },
hideTimerSeconds, {
showLeadingZeros, title: OptionTitle.ElementVisibility,
{ section: 'Element visibility' }, collapsible: true,
options: [
{ {
id: 'hideovertime', id: 'hideovertime',
title: 'Hide Overtime', title: 'Hide Overtime',
@@ -20,7 +25,12 @@ export const MINIMAL_TIMER_OPTIONS: ViewOption[] = [
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
{ section: 'View style override' }, ],
},
{
title: OptionTitle.StyleOverride,
collapsible: true,
options: [
{ {
id: 'key', id: 'key',
title: 'Key Colour', title: 'Key Colour',
@@ -86,4 +96,6 @@ export const MINIMAL_TIMER_OPTIONS: ViewOption[] = [
type: 'number', type: 'number',
placeholder: '0 (default)', placeholder: '0 (default)',
}, },
],
},
]; ];
@@ -1,15 +1,21 @@
import { CustomFields } from 'ontime-types'; import { CustomFields } from 'ontime-types';
import { getTimeOption, makeOptionsFromCustomFields } from '../../../common/components/view-params-editor/constants'; import {
getTimeOption,
makeOptionsFromCustomFields,
OptionTitle,
} from '../../../common/components/view-params-editor/constants';
import { ViewOption } from '../../../common/components/view-params-editor/types'; import { ViewOption } from '../../../common/components/view-params-editor/types';
export const getPublicOptions = (timeFormat: string, customFields: CustomFields): ViewOption[] => { export const getPublicOptions = (timeFormat: string, customFields: CustomFields): ViewOption[] => {
const secondaryOptions = makeOptionsFromCustomFields(customFields, { note: 'Note' }); const secondaryOptions = makeOptionsFromCustomFields(customFields, { note: 'Note' });
return [ return [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), {
{ section: 'Data sources' }, title: OptionTitle.DataSources,
collapsible: true,
options: [
{ {
id: 'secondary-src', id: 'secondary-src',
title: 'Event secondary text', title: 'Event secondary text',
@@ -18,7 +24,12 @@ export const getPublicOptions = (timeFormat: string, customFields: CustomFields)
values: secondaryOptions, values: secondaryOptions,
defaultValue: '', defaultValue: '',
}, },
{ section: 'Schedule options' }, ],
},
{
title: OptionTitle.Schedule,
collapsible: true,
options: [
{ {
id: 'eventsPerPage', id: 'eventsPerPage',
title: 'Events per page', title: 'Events per page',
@@ -40,5 +51,7 @@ export const getPublicOptions = (timeFormat: string, customFields: CustomFields)
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
}; };
@@ -1,12 +1,13 @@
import { getTimeOption, hideTimerSeconds } from '../../../common/components/view-params-editor/constants'; import { getTimeOption, hideTimerSeconds, OptionTitle } from '../../../common/components/view-params-editor/constants';
import type { ViewOption } from '../../../common/components/view-params-editor/types'; import type { ViewOption } from '../../../common/components/view-params-editor/types';
export const getStudioClockOptions = (timeFormat: string): ViewOption[] => [ export const getStudioClockOptions = (timeFormat: string): ViewOption[] => [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), { title: OptionTitle.TimerOptions, collapsible: true, options: [hideTimerSeconds] },
{ section: 'Timer Options' }, {
hideTimerSeconds, title: OptionTitle.ElementVisibility,
{ section: 'Element visibility' }, collapsible: true,
options: [
{ {
id: 'hideRight', id: 'hideRight',
title: 'Hide right section', title: 'Hide right section',
@@ -14,4 +15,6 @@ export const getStudioClockOptions = (timeFormat: string): ViewOption[] => [
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
@@ -1,6 +1,7 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useSearchParams } from 'react-router-dom'; import { useSearchParams } from 'react-router-dom';
import { OptionTitle } from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/types'; import { ViewOption } from '../../common/components/view-params-editor/types';
import { isStringBoolean } from '../../features/viewers/common/viewUtils'; import { isStringBoolean } from '../../features/viewers/common/viewUtils';
@@ -9,7 +10,10 @@ import { isStringBoolean } from '../../features/viewers/common/viewUtils';
* we save the user preferences in the local storage * we save the user preferences in the local storage
*/ */
export const cuesheetOptions: ViewOption[] = [ export const cuesheetOptions: ViewOption[] = [
{ section: 'Table options' }, {
title: OptionTitle.ElementVisibility,
collapsible: true,
options: [
{ {
id: 'showActionMenu', id: 'showActionMenu',
title: 'Show action menu', title: 'Show action menu',
@@ -45,7 +49,12 @@ export const cuesheetOptions: ViewOption[] = [
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
{ section: 'Delay flow' }, ],
},
{
title: OptionTitle.BehaviourOptions,
collapsible: true,
options: [
{ {
id: 'showDelayedTimes', id: 'showDelayedTimes',
title: 'Show delayed times', title: 'Show delayed times',
@@ -60,6 +69,8 @@ export const cuesheetOptions: ViewOption[] = [
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
type CuesheetOptions = { type CuesheetOptions = {
@@ -1,7 +1,11 @@
import { OptionTitle } from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/types'; import { ViewOption } from '../../common/components/view-params-editor/types';
export const projectInfoOptions: ViewOption[] = [ export const projectInfoOptions: ViewOption[] = [
{ section: 'Data visibility' }, {
title: OptionTitle.BehaviourOptions,
collapsible: true,
options: [
{ {
id: 'showBackstage', id: 'showBackstage',
title: 'Show backstage Data', title: 'Show backstage Data',
@@ -16,4 +20,6 @@ export const projectInfoOptions: ViewOption[] = [
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
@@ -1,9 +1,13 @@
import { getTimeOption } from '../../common/components/view-params-editor/constants'; import { getTimeOption, OptionTitle } from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/types'; import { ViewOption } from '../../common/components/view-params-editor/types';
export const getTimelineOptions = (timeFormat: string): ViewOption[] => { export const getTimelineOptions = (timeFormat: string): ViewOption[] => {
return [ return [
getTimeOption(timeFormat), { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
{
title: OptionTitle.ElementVisibility,
collapsible: true,
options: [
{ {
id: 'hidePast', id: 'hidePast',
title: 'Hide Past Events', title: 'Hide Past Events',
@@ -18,5 +22,7 @@ export const getTimelineOptions = (timeFormat: string): ViewOption[] => {
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
}; };
+21 -5
View File
@@ -7,6 +7,7 @@ import {
getTimeOption, getTimeOption,
hideTimerSeconds, hideTimerSeconds,
makeOptionsFromCustomFields, makeOptionsFromCustomFields,
OptionTitle,
showLeadingZeros, showLeadingZeros,
} from '../../common/components/view-params-editor/constants'; } from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/types'; import { ViewOption } from '../../common/components/view-params-editor/types';
@@ -25,9 +26,11 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
const secondaryOptions = makeOptionsFromCustomFields(customFields, { title: 'Title', note: 'Note' }); const secondaryOptions = makeOptionsFromCustomFields(customFields, { title: 'Title', note: 'Note' });
return [ return [
{ section: 'Clock Options' }, { title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
getTimeOption(timeFormat), {
{ section: 'Timer Options' }, title: OptionTitle.TimerOptions,
collapsible: true,
options: [
hideTimerSeconds, hideTimerSeconds,
showLeadingZeros, showLeadingZeros,
{ {
@@ -38,7 +41,12 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
values: timerDisplayOptions, values: timerDisplayOptions,
defaultValue: 'no-overrides', defaultValue: 'no-overrides',
}, },
{ section: 'Data sources' }, ],
},
{
title: OptionTitle.DataSources,
collapsible: true,
options: [
{ {
id: 'main', id: 'main',
title: 'Main text', title: 'Main text',
@@ -55,7 +63,13 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
values: secondaryOptions, values: secondaryOptions,
defaultValue: '', defaultValue: '',
}, },
{ section: 'Element visibility' }, ],
},
{
title: OptionTitle.ElementVisibility,
collapsible: true,
options: [
{ {
id: 'hideClock', id: 'hideClock',
title: 'Hide Time Now', title: 'Hide Time Now',
@@ -91,6 +105,8 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
],
},
]; ];
}; };