refactor: simplify custom field shape

This commit is contained in:
Carlos Valente
2024-04-16 22:58:46 +02:00
committed by Carlos Valente
parent cf14b0b427
commit c4136a0ec7
15 changed files with 40 additions and 40 deletions
@@ -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;
@@ -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;