mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 00:43:54 +00:00
refactor: simplify custom field shape
This commit is contained in:
committed by
Carlos Valente
parent
cf14b0b427
commit
c4136a0ec7
@@ -155,7 +155,7 @@ export const useEventAction = () => {
|
||||
|
||||
const updateCustomField = useCallback(
|
||||
async (eventId: string, field: string, value: string) => {
|
||||
updateEvent({ id: eventId, custom: { [field]: { value } } });
|
||||
updateEvent({ id: eventId, custom: { [field]: value } });
|
||||
},
|
||||
[updateEvent],
|
||||
);
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('cloneEvent()', () => {
|
||||
timeWarning: 120000,
|
||||
timeDanger: 60000,
|
||||
custom: {
|
||||
lighting: { value: '3' },
|
||||
lighting: '3',
|
||||
} as EventCustomFields,
|
||||
} as OntimeEvent;
|
||||
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ export default function PreviewRundown(props: PreviewRundownProps) {
|
||||
fieldHeaders.map((field) => {
|
||||
let value = '';
|
||||
if (field in event.custom) {
|
||||
value = event.custom[field].value;
|
||||
value = event.custom[field];
|
||||
}
|
||||
return <td key={field}>{value}</td>;
|
||||
})}
|
||||
|
||||
@@ -53,7 +53,7 @@ export default function CuesheetWrapper() {
|
||||
return;
|
||||
}
|
||||
|
||||
const previousValue = event.custom[accessor]?.value;
|
||||
const previousValue = event.custom[accessor];
|
||||
|
||||
if (previousValue === payload) {
|
||||
return;
|
||||
|
||||
@@ -49,7 +49,7 @@ function MakeCustomField({ row, column, table }: CellContext<OntimeRundownEntry,
|
||||
}
|
||||
|
||||
// events dont necessarily contain all custom fields
|
||||
const initialValue = event.custom[column.id]?.value ?? '';
|
||||
const initialValue = event.custom[column.id] ?? '';
|
||||
|
||||
return <EditableCell value={initialValue} handleUpdate={update} />;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export const makeTable = (headerData: ProjectData, rundown: OntimeRundown, custo
|
||||
// for custom fields, we need to extract the value from the custom object
|
||||
if (field.startsWith('custom-')) {
|
||||
const fieldLabel = field.split('custom-')[1];
|
||||
const value = entry.custom[fieldLabel]?.value;
|
||||
const value = entry.custom[fieldLabel];
|
||||
row.push(parseField(fieldLabel, value));
|
||||
} else {
|
||||
// @ts-expect-error -- it is ok, we will just not have the data for other fields
|
||||
|
||||
@@ -173,7 +173,7 @@ export default function Operator() {
|
||||
|
||||
const mainField = main ? entry?.[main] || entry.title : entry.title;
|
||||
const secondaryField = getPropertyValue(entry, secondary) ?? '';
|
||||
const subscribedData = entry.custom[subscribe]?.value;
|
||||
const subscribedData = entry.custom[subscribe];
|
||||
|
||||
return (
|
||||
<OperatorEvent
|
||||
|
||||
@@ -54,7 +54,7 @@ export default function EventEditor() {
|
||||
(field: EditorUpdateFields, value: string) => {
|
||||
if (field.startsWith('custom-')) {
|
||||
const fieldLabel = field.split('custom-')[1];
|
||||
updateEvent({ id: event?.id, custom: { [fieldLabel]: { value } } });
|
||||
updateEvent({ id: event?.id, custom: { [fieldLabel]: value } });
|
||||
} else {
|
||||
updateEvent({ id: event?.id, [field]: value });
|
||||
}
|
||||
@@ -111,7 +111,7 @@ export default function EventEditor() {
|
||||
{Object.keys(customFields).map((label) => {
|
||||
const key = `${event.id}-${label}`;
|
||||
const fieldName = `custom-${label}`;
|
||||
const initialValue = event.custom[label]?.value ?? '';
|
||||
const initialValue = event.custom[label] ?? '';
|
||||
const { backgroundColor, color } = getAccessibleColour(customFields[label].colour);
|
||||
|
||||
return (
|
||||
|
||||
@@ -50,7 +50,7 @@ export function getPropertyValue(event: OntimeEvent | null, property: MaybeStrin
|
||||
|
||||
if (property.startsWith('custom-')) {
|
||||
const field = property.split('custom-')[1];
|
||||
return event.custom?.[field]?.value;
|
||||
return event.custom?.[field];
|
||||
}
|
||||
|
||||
return event[property as keyof OntimeEvent] as string;
|
||||
|
||||
@@ -304,15 +304,15 @@ describe('generate()', () => {
|
||||
type: SupportedEvent.Event,
|
||||
id: '1',
|
||||
custom: {
|
||||
lighting: { value: 'event 1 lx' },
|
||||
lighting: 'event 1 lx',
|
||||
} as EventCustomFields,
|
||||
} as OntimeEvent,
|
||||
{
|
||||
type: SupportedEvent.Event,
|
||||
id: '2',
|
||||
custom: {
|
||||
lighting: { value: 'event 2 lx' },
|
||||
sound: { value: 'event 2 sound' },
|
||||
lighting: 'event 2 lx',
|
||||
sound: 'event 2 sound',
|
||||
} as EventCustomFields,
|
||||
} as OntimeEvent,
|
||||
];
|
||||
@@ -322,10 +322,10 @@ describe('generate()', () => {
|
||||
lighting: ['1', '2'],
|
||||
sound: ['2'],
|
||||
});
|
||||
expect((initResult.rundown['1'] as OntimeEvent).custom).toMatchObject({ lighting: { value: 'event 1 lx' } });
|
||||
expect((initResult.rundown['1'] as OntimeEvent).custom).toMatchObject({ lighting: 'event 1 lx' });
|
||||
expect((initResult.rundown['2'] as OntimeEvent).custom).toMatchObject({
|
||||
lighting: { value: 'event 2 lx' },
|
||||
sound: { value: 'event 2 sound' },
|
||||
lighting: 'event 2 lx',
|
||||
sound: 'event 2 sound',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -105,7 +105,7 @@ describe('handleCustomField()', () => {
|
||||
timeStart: 0,
|
||||
linkStart: '1',
|
||||
custom: {
|
||||
lighting: { value: 'on' },
|
||||
lighting: 'on',
|
||||
},
|
||||
};
|
||||
const assignedCustomFields = {};
|
||||
@@ -114,7 +114,7 @@ describe('handleCustomField()', () => {
|
||||
expect(result).toBeUndefined();
|
||||
expect(assignedCustomFields).toStrictEqual({ lighting: ['2'] });
|
||||
expect(event.custom).toStrictEqual({
|
||||
lighting: { value: 'on' },
|
||||
lighting: 'on',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -143,7 +143,7 @@ describe('handleCustomField()', () => {
|
||||
timeStart: 0,
|
||||
linkStart: '1',
|
||||
custom: {
|
||||
sound: { value: 'on' },
|
||||
sound: 'on',
|
||||
},
|
||||
};
|
||||
const assignedCustomFields = {};
|
||||
@@ -152,7 +152,7 @@ describe('handleCustomField()', () => {
|
||||
expect(result).toBeUndefined();
|
||||
expect(assignedCustomFields).toStrictEqual({ video: ['2'] });
|
||||
expect(event.custom).toStrictEqual({
|
||||
video: { value: 'on' },
|
||||
video: 'on',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -179,8 +179,8 @@ describe('handleCustomField()', () => {
|
||||
type: SupportedEvent.Event,
|
||||
id: 'event1',
|
||||
custom: {
|
||||
field1: { value: 'value1' },
|
||||
field2: { value: 'value2' },
|
||||
field1: 'value1',
|
||||
field2: 'value2',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -189,11 +189,11 @@ describe('handleCustomField()', () => {
|
||||
handleCustomField(customFields, customFieldChangelog, mutableEvent, assignedCustomFields);
|
||||
|
||||
// Check that field1 has been renamed to newField1 and the value reassigned
|
||||
expect(mutableEvent.custom['newField1']).toStrictEqual({ value: 'value1' });
|
||||
expect(mutableEvent.custom['newField1']).toStrictEqual('value1');
|
||||
expect(mutableEvent.custom['field1']).toBeUndefined();
|
||||
|
||||
// Check that field2 has been processed
|
||||
expect(mutableEvent.custom['field2']).toStrictEqual({ value: 'value2' });
|
||||
expect(mutableEvent.custom['field2']).toStrictEqual('value2');
|
||||
|
||||
// Check that assignedCustomFields has been updated correctly
|
||||
expect(assignedCustomFields).toStrictEqual({
|
||||
@@ -232,7 +232,7 @@ describe('isDataStale()', () => {
|
||||
timeWarning: 1,
|
||||
timeDanger: 2,
|
||||
custom: {
|
||||
lighting: { value: '3' },
|
||||
lighting: '3',
|
||||
},
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
@@ -83,7 +83,7 @@ export function handleCustomField(
|
||||
const oldData = mutableEvent.custom[field];
|
||||
const newLabel = customFieldChangelog[field];
|
||||
|
||||
mutableEvent.custom[newLabel] = { ...oldData };
|
||||
mutableEvent.custom[newLabel] = oldData;
|
||||
delete mutableEvent.custom[field];
|
||||
addToCustomAssignment(newLabel, mutableEvent.id, assignedCustomFields);
|
||||
continue;
|
||||
|
||||
@@ -883,16 +883,16 @@ describe('parseExcel()', () => {
|
||||
skip: false,
|
||||
note: 'Ballyhoo',
|
||||
custom: {
|
||||
user0: { value: 'a0' },
|
||||
user1: { value: 'a1' },
|
||||
user2: { value: 'a2' },
|
||||
user3: { value: 'a3' },
|
||||
user4: { value: 'a4' },
|
||||
user5: { value: 'a5' },
|
||||
user6: { value: 'a6' },
|
||||
user7: { value: 'a7' },
|
||||
user8: { value: 'a8' },
|
||||
user9: { value: 'a9' },
|
||||
user0: 'a0',
|
||||
user1: 'a1',
|
||||
user2: 'a2',
|
||||
user3: 'a3',
|
||||
user4: 'a4',
|
||||
user5: 'a5',
|
||||
user6: 'a6',
|
||||
user7: 'a7',
|
||||
user8: 'a8',
|
||||
user9: 'a9',
|
||||
},
|
||||
colour: 'red',
|
||||
type: 'event',
|
||||
@@ -908,8 +908,8 @@ describe('parseExcel()', () => {
|
||||
skip: true,
|
||||
note: 'Rainbow chase',
|
||||
custom: {
|
||||
user0: { value: 'b0' },
|
||||
user5: { value: 'b5' },
|
||||
user0: 'b0',
|
||||
user5: 'b5',
|
||||
},
|
||||
colour: '#F00',
|
||||
type: 'event',
|
||||
|
||||
@@ -214,7 +214,7 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
|
||||
} else if (j in customFieldIndexes) {
|
||||
const importKey = customFieldIndexes[j];
|
||||
const ontimeKey = customFieldImportKeys[importKey];
|
||||
eventCustomFields[ontimeKey] = { value: makeString(column, '') };
|
||||
eventCustomFields[ontimeKey] = makeString(column, '');
|
||||
} else {
|
||||
// 2. if there is no flag, lets see if we know the field type
|
||||
if (typeof column === 'string') {
|
||||
|
||||
@@ -7,4 +7,4 @@ export type CustomField = {
|
||||
};
|
||||
|
||||
export type CustomFields = Record<CustomFieldLabel, CustomField>;
|
||||
export type EventCustomFields = Record<CustomFieldLabel, { value: string }>;
|
||||
export type EventCustomFields = Record<CustomFieldLabel, string>;
|
||||
|
||||
Reference in New Issue
Block a user