mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-07 23:39:09 +00:00
refactor: op cannot subscribe to image fields
This commit is contained in:
committed by
Carlos Valente
parent
9167a50eda
commit
4859026989
@@ -126,9 +126,9 @@ function MultiOption(props: EditFormMultiOptionProps) {
|
|||||||
onChange={(value) => setParamState(Array.isArray(value) ? value : [value])}
|
onChange={(value) => setParamState(Array.isArray(value) ? value : [value])}
|
||||||
>
|
>
|
||||||
{Object.values(paramField.values).map((option) => {
|
{Object.values(paramField.values).map((option) => {
|
||||||
const { value, label } = option;
|
const { value, label, colour } = option;
|
||||||
return (
|
return (
|
||||||
<MenuItemOption value={value} key={value}>
|
<MenuItemOption value={value} key={value} style={{ borderRight: `8px solid ${colour}` }}>
|
||||||
{label}
|
{label}
|
||||||
</MenuItemOption>
|
</MenuItemOption>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CustomFields } from 'ontime-types';
|
import { CustomFields } from 'ontime-types';
|
||||||
|
|
||||||
import type { ParamField } from './types';
|
import type { MultiselectOptions, ParamField } from './types';
|
||||||
|
|
||||||
export const makeOptionsFromCustomFields = (
|
export const makeOptionsFromCustomFields = (
|
||||||
customFields: CustomFields,
|
customFields: CustomFields,
|
||||||
@@ -18,6 +18,17 @@ export const makeOptionsFromCustomFields = (
|
|||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function makeCustomFieldSelectOptions(customFields: CustomFields, filterImageType = true): MultiselectOptions {
|
||||||
|
const options: MultiselectOptions = {};
|
||||||
|
for (const [key, value] of Object.entries(customFields)) {
|
||||||
|
if (filterImageType && value.type === 'image') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
options[key] = { value: key, label: value.label, colour: value.colour };
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
export const getTimeOption = (timeFormat: string): ParamField => {
|
export const getTimeOption = (timeFormat: string): ParamField => {
|
||||||
const placeholder = `${timeFormat} (default)`;
|
const placeholder = `${timeFormat} (default)`;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -12,9 +12,11 @@ type OptionsField = {
|
|||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type MultiselectOption = { value: string; label: string; colour: string };
|
||||||
|
export type MultiselectOptions = Record<string, MultiselectOption>;
|
||||||
type MultiOptionsField = {
|
type MultiOptionsField = {
|
||||||
type: 'multi-option';
|
type: 'multi-option';
|
||||||
values: Record<string, { value: string; label: string; colour: string }>;
|
values: MultiselectOptions;
|
||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ export default function Operator() {
|
|||||||
|
|
||||||
// subscriptions is a MultiSelect and may have multiple values
|
// subscriptions is a MultiSelect and may have multiple values
|
||||||
const subscriptions = searchParams.getAll('subscribe').filter((value) => Object.hasOwn(customFields, value));
|
const subscriptions = searchParams.getAll('subscribe').filter((value) => Object.hasOwn(customFields, value));
|
||||||
const canEdit = shouldEdit && subscriptions;
|
const canEdit = shouldEdit && subscriptions.length;
|
||||||
|
|
||||||
const main = searchParams.get('main') as keyof TitleFields | null;
|
const main = searchParams.get('main') as keyof TitleFields | null;
|
||||||
const secondary = searchParams.get('secondary');
|
const secondary = searchParams.get('secondary');
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { CustomFields } from 'ontime-types';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getTimeOption,
|
getTimeOption,
|
||||||
|
makeCustomFieldSelectOptions,
|
||||||
makeOptionsFromCustomFields,
|
makeOptionsFromCustomFields,
|
||||||
OptionTitle,
|
OptionTitle,
|
||||||
} from '../../common/components/view-params-editor/constants';
|
} from '../../common/components/view-params-editor/constants';
|
||||||
@@ -9,13 +10,7 @@ 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[] => {
|
||||||
const fieldOptions = makeOptionsFromCustomFields(customFields, { title: 'Title', note: 'Note' });
|
const fieldOptions = makeOptionsFromCustomFields(customFields, { title: 'Title', note: 'Note' });
|
||||||
|
const customFieldSelect = makeCustomFieldSelectOptions(customFields);
|
||||||
const customFieldSelect = Object.entries(customFields).reduce<
|
|
||||||
Record<string, { value: string; label: string; colour: string }>
|
|
||||||
>((acc, [key, field]) => {
|
|
||||||
acc[key] = { value: key, label: field.label, colour: field.colour };
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
|
{ title: OptionTitle.ClockOptions, collapsible: true, options: [getTimeOption(timeFormat)] },
|
||||||
@@ -46,6 +41,13 @@ export const getOperatorOptions = (customFields: CustomFields, timeFormat: strin
|
|||||||
type: 'multi-option',
|
type: 'multi-option',
|
||||||
values: customFieldSelect,
|
values: customFieldSelect,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'shouldEdit',
|
||||||
|
title: 'Edit custom field',
|
||||||
|
description: 'Allows editing an highlighted custom field by long pressing',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -59,13 +61,6 @@ export const getOperatorOptions = (customFields: CustomFields, timeFormat: strin
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'shouldEdit',
|
|
||||||
title: 'Edit custom field',
|
|
||||||
description: 'Allows editing an events selected custom field by long pressing.',
|
|
||||||
type: 'boolean',
|
|
||||||
defaultValue: false,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user