From 4404232d4d1231429a13da31aba534c382aebf82 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 10 Feb 2022 13:15:11 +0800 Subject: [PATCH] fix: allow different boolean values for checkbox type Signed-off-by: Wing-Kam Wong --- .../importExport/columnMappingModal.vue | 22 ++++++++++++++++++- .../spreadsheet/components/moreActions.vue | 15 +++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/components/importExport/columnMappingModal.vue b/packages/nc-gui/components/project/spreadsheet/components/importExport/columnMappingModal.vue index 740342d0f5..c86b7afa86 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/importExport/columnMappingModal.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/importExport/columnMappingModal.vue @@ -158,8 +158,28 @@ export default { return 'Source data contains some invalid numbers' } break + case UITypes.Checkbox: + if ( + this.parsedCsv && this.parsedCsv.data && this.parsedCsv.data.slice(0, 500) + .some((r) => { + if (r => r[row.sourceCn] !== null && r[row.sourceCn] !== undefined) { + var input = r[row.sourceCn] + if (typeof input === 'string') { + input = input.replace(/["']/g, "").toLowerCase().trim() + return ( + input == "false" || input == "no" || input == "n" || input == "0" || + input == "true" || input == "yes" || input == "y" || input == "1" + ) ? false : true + } + return input != 1 && input != 0 && input != true && input != false + } + return false + }) + ) { + return 'Source data contains some invalid boolean values' + } + break } - return true }, mapDefaultColumns() { diff --git a/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue b/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue index d7dd20868f..756c041e29 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/moreActions.vue @@ -106,6 +106,7 @@ import FileSaver from 'file-saver' import DropOrSelectFileModal from '~/components/import/dropOrSelectFileModal' import ColumnMappingModal from '~/components/project/spreadsheet/components/importExport/columnMappingModal' import CSVTemplateAdapter from '~/components/import/templateParsers/CSVTemplateAdapter' +import { UITypes } from '~/components/project/spreadsheet/helpers/uiTypes' export default { name: 'ExportImport', @@ -276,9 +277,19 @@ export default { for (let i = 0, progress = 0; i < data.length; i += 500) { const batchData = data.slice(i, i + 500).map(row => columnMappings.reduce((res, col) => { // todo: parse data - if (col.enabled && col.destCn) { - res[col.destCn] = row[col.sourceCn] + const v = this.meta && this.meta.columns.find(c => c._cn === col.destCn) + var input = row[col.sourceCn] + // parse potential boolean values + if (v.uidt == UITypes.Checkbox) { + input = input.replace(/["']/g, "").toLowerCase().trim() + if (input == "false" || input == "no" || input == "n") { + input = "0" + } else if (input == "true" || input == "yes" || input == "y") { + input = "1" + } + } + res[col.destCn] = input } return res }, {}))