mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
refactor: simplify logic dynamic menus
This commit is contained in:
committed by
Carlos Valente
parent
ce4a48cd8d
commit
61280b06b7
@@ -2,11 +2,14 @@ import { CustomFields } from 'ontime-types';
|
|||||||
|
|
||||||
import type { ParamField } from './types';
|
import type { ParamField } from './types';
|
||||||
|
|
||||||
export const makeOptionsFromCustomFields = (customFields: CustomFields, additionalOptions?: Record<string, string>) => {
|
export const makeOptionsFromCustomFields = (
|
||||||
const customFieldOptions = Object.entries(customFields).reduce((acc, [key, value]) => {
|
customFields: CustomFields,
|
||||||
return { ...acc, [`custom-${key}`]: `Custom: ${value.label}` };
|
additionalOptions: Record<string, string> = {},
|
||||||
}, additionalOptions ?? {});
|
) => {
|
||||||
return customFieldOptions;
|
return Object.entries(customFields).reduce((options, [key, value]) => {
|
||||||
|
options[`custom-${key}`] = `Custom: ${value.label}`;
|
||||||
|
return options;
|
||||||
|
}, additionalOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTimeOption = (timeFormat: string): ParamField => {
|
export const getTimeOption = (timeFormat: string): ParamField => {
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ 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 = Object.entries(customFields).reduce((acc, [key, field]) => {
|
const customFieldSelect = Object.entries(customFields).reduce<
|
||||||
return { ...acc, [key]: { value: key, label: field.label, colour: field.colour } };
|
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 [
|
||||||
|
|||||||
Reference in New Issue
Block a user