refactor: remove userFields (#791)

* refactor: process custom fields on cache generate

* refactor: remove userFields
This commit is contained in:
Carlos Valente
2024-02-27 13:23:12 +01:00
committed by GitHub
parent 429df21557
commit d7392b93d2
73 changed files with 1580 additions and 2290 deletions
@@ -1,42 +0,0 @@
import { isExcelImportMap } from '../excelImport';
describe('isExcelImportMap', () => {
test('migrate v2 map', () => {
const v2ImportMap = {
worksheet: 'event schedule',
projectName: 'project name',
projectDescription: 'project description',
publicUrl: 'public url',
publicInfo: 'public info',
backstageUrl: 'backstage url',
backstageInfo: 'backstage info',
timeStart: 'time start',
timeEnd: 'time end',
duration: 'duration',
cue: 'cue',
title: 'title',
presenter: 'presenter',
subtitle: 'subtitle',
isPublic: 'public',
skip: 'skip',
note: 'notes',
colour: 'colour',
endAction: 'end action',
timerType: 'timer type',
user0: 'header',
user1: 'user1',
user2: 'user2',
user3: 'user3',
user4: 'user4',
user5: 'user5',
user6: 'user6',
user7: 'user7',
user8: 'user8',
user9: 'user9',
timeWarning: 'warning time',
timeDanger: 'danger time',
};
expect(isExcelImportMap(v2ImportMap)).toBe(true);
});
});
@@ -0,0 +1,54 @@
import { isImportMap } from '../spreadsheetImport';
describe('isImportMap()', () => {
it('validates a v3 default import map', () => {
const v3ImportMap = {
worksheet: 'event schedule',
timeStart: 'time start',
timeEnd: 'time end',
duration: 'duration',
cue: 'cue',
title: 'title',
presenter: 'presenter',
subtitle: 'subtitle',
isPublic: 'public',
skip: 'skip',
note: 'notes',
colour: 'colour',
endAction: 'end action',
timerType: 'timer type',
timeWarning: 'warning time',
timeDanger: 'danger time',
custom: {},
};
expect(isImportMap(v3ImportMap)).toBe(true);
});
it('handles custom properties', () => {
const v3ImportMap = {
worksheet: 'event schedule',
timeStart: 'time start',
timeEnd: 'time end',
duration: 'duration',
cue: 'cue',
title: 'title',
presenter: 'presenter',
subtitle: 'subtitle',
isPublic: 'public',
skip: 'skip',
note: 'notes',
colour: 'colour',
endAction: 'end action',
timerType: 'timer type',
timeWarning: 'warning time',
timeDanger: 'danger time',
custom: {
userDefined: 'userDefined',
anotherOne: 'anotherOne',
},
};
expect(isImportMap(v3ImportMap)).toBe(true);
});
});
@@ -1,7 +1,9 @@
export type ExcelImportOptions = keyof typeof defaultExcelImportMap;
export type ExcelImportMap = typeof defaultExcelImportMap;
export type ImportOptions = keyof typeof defaultImportMap | 'custom';
export type ImportCustom = Record<string, string>;
export type ImportMap = typeof defaultImportMap & { custom: ImportCustom };
export const defaultExcelImportMap = {
// Record of ontime name and import name
export const defaultImportMap = {
worksheet: 'event schedule',
timeStart: 'time start',
timeEnd: 'time end',
@@ -16,25 +18,20 @@ export const defaultExcelImportMap = {
colour: 'colour',
endAction: 'end action',
timerType: 'timer type',
user0: 'user0',
user1: 'user1',
user2: 'user2',
user3: 'user3',
user4: 'user4',
user5: 'user5',
user6: 'user6',
user7: 'user7',
user8: 'user8',
user9: 'user9',
timeWarning: 'warning time',
timeDanger: 'danger time',
custom: {},
};
export function isExcelImportMap(obj: unknown): obj is ExcelImportMap {
/**
* Validates whether an object is an Import Map
* @param obj
*/
export function isImportMap(obj: unknown): obj is ImportMap {
if (typeof obj !== 'object' || obj === null) {
return false;
}
const keys = Object.keys(defaultExcelImportMap);
const keys = Object.keys(defaultImportMap);
return keys.every((key) => Object.hasOwn(obj, key));
}
+6
View File
@@ -0,0 +1,6 @@
export function unpackError(error: unknown): string {
if (error instanceof Error) {
return error.message;
}
return String(error);
}