mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 19:03:47 +00:00
custom fields (#744)
--------- Co-authored-by: Carlos Valente <carlosvalente@pm.me>
This commit is contained in:
committed by
GitHub
parent
1a420a1ddd
commit
c1377544a0
@@ -11,6 +11,7 @@ import {
|
||||
UserFields,
|
||||
Alias,
|
||||
Settings,
|
||||
CustomFields,
|
||||
HttpSettings,
|
||||
} from 'ontime-types';
|
||||
|
||||
@@ -32,6 +33,16 @@ export class DataProvider {
|
||||
return data.project;
|
||||
}
|
||||
|
||||
static async setCustomFields(newData: CustomFields): Promise<CustomFields> {
|
||||
data.customFields = { ...newData };
|
||||
await this.persist();
|
||||
return data.customFields;
|
||||
}
|
||||
|
||||
static getCustomFields(): CustomFields {
|
||||
return data.customFields;
|
||||
}
|
||||
|
||||
static async setRundown(newData: OntimeRundown) {
|
||||
data.rundown = [...newData];
|
||||
await this.persist();
|
||||
@@ -110,6 +121,7 @@ export class DataProvider {
|
||||
data.http = mergedData.http;
|
||||
data.aliases = mergedData.aliases;
|
||||
data.userFields = mergedData.userFields;
|
||||
data.customFields = mergedData.customFields;
|
||||
data.rundown = mergedData.rundown;
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DatabaseModel } from 'ontime-types';
|
||||
* @param {object} newData
|
||||
*/
|
||||
export function safeMerge(existing: DatabaseModel, newData: Partial<DatabaseModel>) {
|
||||
const { rundown, project, settings, viewSettings, aliases, userFields, osc, http } = newData || {};
|
||||
const { rundown, project, settings, viewSettings, aliases, customFields, userFields, osc, http } = newData || {};
|
||||
|
||||
return {
|
||||
...existing,
|
||||
@@ -15,6 +15,7 @@ export function safeMerge(existing: DatabaseModel, newData: Partial<DatabaseMode
|
||||
settings: { ...existing.settings, ...settings },
|
||||
viewSettings: { ...existing.viewSettings, ...viewSettings },
|
||||
aliases: aliases ?? existing.aliases,
|
||||
customFields: customFields ?? existing.customFields,
|
||||
userFields: {
|
||||
...existing.userFields,
|
||||
...(userFields && Object.fromEntries(Object.entries(userFields).filter(([_, value]) => value !== null))),
|
||||
|
||||
@@ -24,11 +24,26 @@ describe('safeMerge', () => {
|
||||
viewSettings: {
|
||||
overrideStyles: false,
|
||||
endMessage: 'existing endMessage',
|
||||
normalColor: '#ffffffcc',
|
||||
warningColor: '#FFAB33',
|
||||
dangerColor: '#ED3333',
|
||||
},
|
||||
aliases: [],
|
||||
userFields: {
|
||||
user0: 'existing user0',
|
||||
user1: 'existing user1',
|
||||
user2: 'existing user2',
|
||||
user3: 'existing user3',
|
||||
user4: 'existing user4',
|
||||
user5: 'existing user5',
|
||||
user6: 'existing user6',
|
||||
user7: 'existing user7',
|
||||
user8: 'existing user8',
|
||||
user9: 'existing user9',
|
||||
},
|
||||
customFields: {
|
||||
lighting: { type: 'string', label: 'lighting' },
|
||||
vfx: { type: 'string', label: 'vfx' },
|
||||
},
|
||||
osc: {
|
||||
portIn: 8888,
|
||||
@@ -212,4 +227,29 @@ describe('safeMerge', () => {
|
||||
const result = safeMerge(existing, newData);
|
||||
expect(result.userFields).toEqual(expected);
|
||||
});
|
||||
|
||||
it('merges customFields into existing object', () => {
|
||||
const existing = {
|
||||
customFields: {
|
||||
lighting: { type: 'string', label: 'lighting' },
|
||||
sound: { type: 'string', label: 'sound' },
|
||||
},
|
||||
};
|
||||
|
||||
const newData = {
|
||||
customFields: {
|
||||
switcher: { type: 'string', label: 'switcher' },
|
||||
vfx: { type: 'string', label: 'vfx' },
|
||||
},
|
||||
};
|
||||
|
||||
const expected = {
|
||||
switcher: { type: 'string', label: 'switcher' },
|
||||
vfx: { type: 'string', label: 'vfx' },
|
||||
};
|
||||
|
||||
//@ts-expect-error -- testing partial merge
|
||||
const result = safeMerge(existing, newData);
|
||||
expect(result.customFields).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user