Link start times from excel import (#903)

* add test for linking start time in excel import

* link ids

* add link to UI

* ensure times with cachedRundown

---------

Co-authored-by: Carlos Valente <carlosvalente@pm.me>
This commit is contained in:
Alex Christoffer Rasmussen
2024-04-26 17:09:59 +01:00
committed by GitHub
parent d8a8f0ad92
commit 74418ce17e
9 changed files with 157 additions and 22 deletions
+18 -3
View File
@@ -34,7 +34,6 @@ import {
parseViewSettings,
} from './parserFunctions.js';
import { parseExcelDate } from './time.js';
import { coerceBoolean } from './coerceType.js';
export const EXCEL_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
export const JSON_MIME = 'application/json';
@@ -43,6 +42,14 @@ type ExcelData = Pick<DatabaseModel, 'rundown' | 'customFields'> & {
rundownMetadata: Record<string, { row: number; col: number }>;
};
function parseBooleanString(value: unknown): boolean {
// falsy values would be nullish or empty string
if (!value || typeof value !== 'string') {
return false;
}
return value.toLowerCase() !== 'false';
}
export function getCustomFieldData(importMap: ImportMap): {
customFields: CustomFields;
customFieldImportKeys: Record<keyof CustomFields, string>;
@@ -91,6 +98,8 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
let isPublicIndex: number | null = null;
let skipIndex: number | null = null;
let linkStartIndex: number | null = null;
// times: numbers
let timeStartIndex: number | null = null;
let timeEndIndex: number | null = null;
@@ -116,6 +125,10 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
timeStartIndex = col;
rundownMetadata['timeStart'] = { row, col };
},
[importMap.linkStart]: (row: number, col: number) => {
linkStartIndex = col;
rundownMetadata['linkStart'] = { row, col };
},
[importMap.timeEnd]: (row: number, col: number) => {
timeEndIndex = col;
rundownMetadata['timeEnd'] = { row, col };
@@ -191,6 +204,8 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
event.title = makeString(column, '');
} else if (j === timeStartIndex) {
event.timeStart = parseExcelDate(column);
} else if (j === linkStartIndex) {
event.linkStart = parseBooleanString(column);
} else if (j === timeEndIndex) {
event.timeEnd = parseExcelDate(column);
} else if (j === durationIndex) {
@@ -198,9 +213,9 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
} else if (j === cueIndex) {
event.cue = makeString(column, '');
} else if (j === isPublicIndex) {
event.isPublic = column == 'x' ? true : coerceBoolean(column);
event.isPublic = parseBooleanString(column);
} else if (j === skipIndex) {
event.skip = column == 'x' ? true : coerceBoolean(column);
event.skip = parseBooleanString(column);
} else if (j === notesIndex) {
event.note = makeString(column, '');
} else if (j === endActionIndex) {