mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
refactor: simplify custom field shape
This commit is contained in:
committed by
Carlos Valente
parent
cf14b0b427
commit
c4136a0ec7
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user