Prefeat/skip (#188)

* refactor: refactor size of event list
* refactor: optimise event mutations
* refactor: prepare skip feature
* refactor: update tests
* refactor: simplify type assertion
This commit is contained in:
Carlos Valente
2022-08-09 14:02:46 +02:00
committed by GitHub
parent 9b5d536378
commit b80ae543a4
10 changed files with 370 additions and 85 deletions
+24 -7
View File
@@ -18,6 +18,19 @@ import { generateId } from './generate_id.js';
export const EXCEL_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
export const JSON_MIME = 'application/json';
/**
* @description Whether a string is considered empty
* @param value
* @return {boolean}
*/
export const isStringEmpty = (value) => {
let v = value;
if (typeof value === 'string') {
v = value.replace(/\s+/g, '');
}
return v === '' || !v;
};
/**
* @description Excel array parser
* @param {array} excelData - array with excel sheet
@@ -36,6 +49,7 @@ export const parseExcel_v1 = async (excelData) => {
let presenterIndex = null;
let subtitleIndex = null;
let isPublicIndex = null;
let skipIndex = null;
let notesIndex = null;
let colourIndex = null;
let user0Index = null;
@@ -75,12 +89,9 @@ export const parseExcel_v1 = async (excelData) => {
} else if (j === subtitleIndex) {
event.subtitle = column;
} else if (j === isPublicIndex) {
// whether column is not empty
let c = column;
if (typeof column === 'string') {
c = column.replace(/\s+/g, '');
}
event.isPublic = c !== '';
event.isPublic = isStringEmpty(column);
} else if (j === skipIndex) {
event.skip = isStringEmpty(column);
} else if (j === notesIndex) {
event.note = column;
} else if (j === colourIndex) {
@@ -144,6 +155,11 @@ export const parseExcel_v1 = async (excelData) => {
case 'public':
isPublicIndex = j;
break;
case 'skip? (x)':
case 'skip?':
case 'skip':
skipIndex = j;
break;
case 'notes':
notesIndex = j;
break;
@@ -278,7 +294,8 @@ export const validateEvent_v1 = (eventArgs) => {
timeEnd: end,
timeType: 'start-end',
duration: validateDuration(start, end),
isPublic: e.isPublic != null && typeof e.isPublic === 'boolean' ? e.isPublic : d.isPublic,
isPublic: typeof e.isPublic === 'boolean' ? e.isPublic : d.isPublic,
skip: typeof e.skip === 'boolean' ? e.skip : d.skip,
note: makeString(e.note, d.note),
user0: makeString(e.user0, d.user0),
user1: makeString(e.user1, d.user1),