mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 23:19:09 +00:00
import id's from sheet (#1516)
* import id's from sheet * fix test * fix test in utils * remove comment * ensure uri safe ids
This commit is contained in:
committed by
GitHub
parent
e90161aa33
commit
d0b4c6a279
@@ -20,6 +20,7 @@ export const namedImportMap = {
|
|||||||
'Timer type': 'timer type',
|
'Timer type': 'timer type',
|
||||||
'Time warning': 'warning time',
|
'Time warning': 'warning time',
|
||||||
'Time danger': 'danger time',
|
'Time danger': 'danger time',
|
||||||
|
ID: 'id',
|
||||||
custom: [] as ImportCustom[],
|
custom: [] as ImportCustom[],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ export function convertToImportMap(namedImportMap: NamedImportMap): ImportMap {
|
|||||||
timeWarning: namedImportMap['Time warning'],
|
timeWarning: namedImportMap['Time warning'],
|
||||||
timeDanger: namedImportMap['Time danger'],
|
timeDanger: namedImportMap['Time danger'],
|
||||||
custom,
|
custom,
|
||||||
|
entryId: namedImportMap.ID,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export default function PreviewRundown(props: PreviewRundownProps) {
|
|||||||
{fieldLabels.map((label) => (
|
{fieldLabels.map((label) => (
|
||||||
<th key={label}>{label}</th>
|
<th key={label}>{label}</th>
|
||||||
))}
|
))}
|
||||||
|
<th>ID</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -113,6 +114,9 @@ export default function PreviewRundown(props: PreviewRundownProps) {
|
|||||||
}
|
}
|
||||||
return <td key={field}>{value}</td>;
|
return <td key={field}>{value}</td>;
|
||||||
})}
|
})}
|
||||||
|
<td className={style.center}>
|
||||||
|
<Tag>{event.id}</Tag>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{event.note && (
|
{event.note && (
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -787,6 +787,7 @@ describe('getCustomFieldData()', () => {
|
|||||||
sound: 'sound',
|
sound: 'sound',
|
||||||
video: 'av',
|
video: 'av',
|
||||||
},
|
},
|
||||||
|
entryId: 'id',
|
||||||
} as ImportMap;
|
} as ImportMap;
|
||||||
|
|
||||||
const result = getCustomFieldData(importMap, {});
|
const result = getCustomFieldData(importMap, {});
|
||||||
@@ -838,6 +839,7 @@ describe('getCustomFieldData()', () => {
|
|||||||
sound: 'sound',
|
sound: 'sound',
|
||||||
video: 'av',
|
video: 'av',
|
||||||
},
|
},
|
||||||
|
entryId: 'id',
|
||||||
} as ImportMap;
|
} as ImportMap;
|
||||||
|
|
||||||
const customFields: CustomFields = {
|
const customFields: CustomFields = {
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ export const parseExcel = (
|
|||||||
let endActionIndex: number | null = null;
|
let endActionIndex: number | null = null;
|
||||||
let timerTypeIndex: number | null = null;
|
let timerTypeIndex: number | null = null;
|
||||||
|
|
||||||
|
//ID
|
||||||
|
let entryIdIndex: number | null = null;
|
||||||
|
|
||||||
// record of column index and the name of the field
|
// record of column index and the name of the field
|
||||||
const customFieldIndexes: Record<number, string> = {};
|
const customFieldIndexes: Record<number, string> = {};
|
||||||
|
|
||||||
@@ -185,11 +188,15 @@ export const parseExcel = (
|
|||||||
},
|
},
|
||||||
[importMap.timeWarning]: (row: number, col: number) => {
|
[importMap.timeWarning]: (row: number, col: number) => {
|
||||||
timeWarningIndex = col;
|
timeWarningIndex = col;
|
||||||
rundownMetadata['timeWarningIndex'] = { row, col };
|
rundownMetadata['timeWarning'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.timeDanger]: (row: number, col: number) => {
|
[importMap.timeDanger]: (row: number, col: number) => {
|
||||||
timeDangerIndex = col;
|
timeDangerIndex = col;
|
||||||
rundownMetadata['timeDangerIndex'] = { row, col };
|
rundownMetadata['timeDanger'] = { row, col };
|
||||||
|
},
|
||||||
|
[importMap.entryId]: (row: number, col: number) => {
|
||||||
|
entryIdIndex = col;
|
||||||
|
rundownMetadata['id'] = { row, col };
|
||||||
},
|
},
|
||||||
custom: (row: number, col: number, columnText: string) => {
|
custom: (row: number, col: number, columnText: string) => {
|
||||||
customFieldIndexes[col] = columnText;
|
customFieldIndexes[col] = columnText;
|
||||||
@@ -242,6 +249,8 @@ export const parseExcel = (
|
|||||||
event.timeDanger = parseExcelDate(column);
|
event.timeDanger = parseExcelDate(column);
|
||||||
} else if (j === colourIndex) {
|
} else if (j === colourIndex) {
|
||||||
event.colour = makeString(column, '');
|
event.colour = makeString(column, '');
|
||||||
|
} else if (j === entryIdIndex) {
|
||||||
|
event.id = encodeURIComponent(makeString(column, undefined));
|
||||||
} else if (j in customFieldIndexes) {
|
} else if (j in customFieldIndexes) {
|
||||||
const importKey = customFieldIndexes[j];
|
const importKey = customFieldIndexes[j];
|
||||||
const ontimeKey = customFieldImportKeys[importKey];
|
const ontimeKey = customFieldImportKeys[importKey];
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { isImportMap } from '../spreadsheetImport';
|
|||||||
|
|
||||||
describe('isImportMap()', () => {
|
describe('isImportMap()', () => {
|
||||||
it('validates a v3 default import map', () => {
|
it('validates a v3 default import map', () => {
|
||||||
const v3ImportMap = {
|
const v3ImportMap: ImportMap = {
|
||||||
worksheet: 'event schedule',
|
worksheet: 'event schedule',
|
||||||
timeStart: 'time start',
|
timeStart: 'time start',
|
||||||
linkStart: 'link start',
|
linkStart: 'link start',
|
||||||
@@ -21,13 +21,38 @@ describe('isImportMap()', () => {
|
|||||||
timeWarning: 'warning time',
|
timeWarning: 'warning time',
|
||||||
timeDanger: 'danger time',
|
timeDanger: 'danger time',
|
||||||
custom: {},
|
custom: {},
|
||||||
} as ImportMap;
|
entryId: 'id',
|
||||||
|
};
|
||||||
|
|
||||||
expect(isImportMap(v3ImportMap)).toBe(true);
|
expect(isImportMap(v3ImportMap)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rejects map missing keys', () => {
|
||||||
|
const importMap = {
|
||||||
|
worksheet: 'event schedule',
|
||||||
|
timeStart: 'time start',
|
||||||
|
linkStart: 'link start',
|
||||||
|
timeEnd: 'time end',
|
||||||
|
duration: 'duration',
|
||||||
|
cue: 'cue',
|
||||||
|
title: 'title',
|
||||||
|
countToEnd: 'count to end',
|
||||||
|
isPublic: 'public',
|
||||||
|
skip: 'skip',
|
||||||
|
note: 'notes',
|
||||||
|
colour: 'colour',
|
||||||
|
endAction: 'end action',
|
||||||
|
timerType: 'timer type',
|
||||||
|
timeWarning: 'warning time',
|
||||||
|
timeDanger: 'danger time',
|
||||||
|
custom: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(isImportMap(importMap)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('handles custom properties', () => {
|
it('handles custom properties', () => {
|
||||||
const v3ImportMap = {
|
const v3ImportMap: ImportMap = {
|
||||||
worksheet: 'event schedule',
|
worksheet: 'event schedule',
|
||||||
timeStart: 'time start',
|
timeStart: 'time start',
|
||||||
linkStart: 'link start',
|
linkStart: 'link start',
|
||||||
@@ -48,7 +73,8 @@ describe('isImportMap()', () => {
|
|||||||
userDefined: 'userDefined',
|
userDefined: 'userDefined',
|
||||||
anotherOne: 'anotherOne',
|
anotherOne: 'anotherOne',
|
||||||
},
|
},
|
||||||
} as ImportMap;
|
entryId: 'id',
|
||||||
|
};
|
||||||
|
|
||||||
expect(isImportMap(v3ImportMap)).toBe(true);
|
expect(isImportMap(v3ImportMap)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export const defaultImportMap = {
|
|||||||
timeWarning: 'warning time',
|
timeWarning: 'warning time',
|
||||||
timeDanger: 'danger time',
|
timeDanger: 'danger time',
|
||||||
custom: {},
|
custom: {},
|
||||||
|
entryId: 'id',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user