Skip to content

Commit

Permalink
refactor: simplify logic dynamic menus
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Jul 9, 2024
1 parent b54f3c4 commit e4d7040
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { CustomFields } from 'ontime-types';

import type { ParamField } from './types';

export const makeOptionsFromCustomFields = (customFields: CustomFields, additionalOptions?: Record<string, string>) => {
const customFieldOptions = Object.entries(customFields).reduce((acc, [key, value]) => {
return { ...acc, [`custom-${key}`]: `Custom: ${value.label}` };
}, additionalOptions ?? {});
return customFieldOptions;
export const makeOptionsFromCustomFields = (
customFields: CustomFields,
additionalOptions: Record<string, string> = {},
) => {
return Object.entries(customFields).reduce((options, [key, value]) => {
options[`custom-${key}`] = `Custom: ${value.label}`;
return options;
}, additionalOptions);
};

export const getTimeOption = (timeFormat: string): ParamField => {
Expand Down
7 changes: 5 additions & 2 deletions apps/client/src/features/operator/operator.options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { ViewOption } from '../../common/components/view-params-editor/types';
export const getOperatorOptions = (customFields: CustomFields, timeFormat: string): ViewOption[] => {
const fieldOptions = makeOptionsFromCustomFields(customFields, { title: 'Title', note: 'Note' });

const customFieldSelect = Object.entries(customFields).reduce((acc, [key, field]) => {
return { ...acc, [key]: { value: key, label: field.label, colour: field.colour } };
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 [
Expand Down

0 comments on commit e4d7040

Please sign in to comment.