From 5cfe0f781bc9ea547d218cbfb66ff62a1d35c66e Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 6 Jul 2024 07:08:44 +0530 Subject: [PATCH] Nc feature: Import CSV - skip field mapping during import (#8915) * fix(nc-gui): import csv changes * fix(nc-gui): tooltip alignment issue * fix(nc-gui): duplicate table name issue * fix(nc-gui): uncheck auto select field type checkbox * fix(nc-gui): skip field mapping during csv import * chore(nc-gui): lint * fix(nc-gui): small changes * fix(nc-gui): remove auto mapping option * fix(test): update import excel test cases * fix(nc-gui): review changes * fix(nc-gui): quick import modal width issue * fix(nc-gui): w.replace is not a function --- .../nc-gui/components/dlg/QuickImport.vue | 58 +++-- .../nc-gui/components/template/Editor.vue | 215 ++++++++---------- packages/nc-gui/components/template/utils.ts | 11 +- .../helpers/parsers/ExcelTemplateAdapter.ts | 10 +- packages/nc-gui/lang/en.json | 5 +- .../tests/db/features/import.spec.ts | 5 +- 6 files changed, 142 insertions(+), 162 deletions(-) diff --git a/packages/nc-gui/components/dlg/QuickImport.vue b/packages/nc-gui/components/dlg/QuickImport.vue index c5d045e182..b1cc957012 100644 --- a/packages/nc-gui/components/dlg/QuickImport.vue +++ b/packages/nc-gui/components/dlg/QuickImport.vue @@ -70,6 +70,7 @@ const defaultImportState = { autoSelectFieldTypes: true, firstRowAsHeaders: true, shouldImportData: true, + importDataOnly: true, }, } const importState = reactive(defaultImportState) @@ -84,7 +85,6 @@ const IsImportTypeExcel = computed(() => importType === 'excel') const validators = computed(() => ({ url: [fieldRequiredValidator(), importUrlValidator, isImportTypeCsv.value ? importCsvUrlValidator : importExcelUrlValidator], - maxRowsToParse: [fieldRequiredValidator()], })) const { validate, validateInfos } = useForm(importState, validators) @@ -152,10 +152,6 @@ const disableImportButton = computed(() => !templateEditorRef.value?.isValid || const disableFormatJsonButton = computed(() => !jsonEditorRef.value?.isValid) const modalWidth = computed(() => { - if (importType === 'excel' && templateEditorModal.value) { - return 'max(90vw, 600px)' - } - return 'max(60vw, 600px)' }) @@ -254,9 +250,10 @@ function formatJson() { jsonEditorRef.value?.format() } -function populateUniqueTableName(tn: string) { +function populateUniqueTableName(tn: string, draftTn: string[] = []) { let c = 1 while ( + draftTn.includes(tn) || baseTables.value.get(baseId)?.some((t: TableType) => { const s = t.table_name.split('___') let target = t.table_name @@ -492,10 +489,13 @@ async function parseAndExtractData(val: UploadFile[] | ArrayBuffer | string) { if (importDataOnly) importColumns.value = templateGenerator!.getColumns() else { // ensure the target table name not exist in current table list - templateData.value.tables = templateData.value.tables.map((table: Record) => ({ - ...table, - table_name: populateUniqueTableName(table.table_name), - })) + const draftTableNames = [] as string[] + + templateData.value.tables = templateData.value.tables.map((table: Record) => { + const table_name = populateUniqueTableName(table.table_name, draftTableNames) + draftTableNames.push(table_name) + return { ...table, table_name } + }) } importData.value = templateGenerator!.getData() } @@ -517,6 +517,11 @@ const onError = () => { const onChange = () => { isError.value = false } + +onMounted(() => { + importState.parserConfig.importDataOnly = importDataOnly + importState.parserConfig.autoSelectFieldTypes = importDataOnly +})
- + - +
@@ -625,16 +638,6 @@ const onChange = () => { {{ $t('title.advancedSettings') }} - - - - - - - {{ $t('labels.autoSelectFieldTypes') }} - - - {{ $t('labels.firstRowAsHeaders') }} @@ -699,3 +702,12 @@ const onChange = () => { + + diff --git a/packages/nc-gui/components/template/Editor.vue b/packages/nc-gui/components/template/Editor.vue index ff5842f36d..052b96ff37 100644 --- a/packages/nc-gui/components/template/Editor.vue +++ b/packages/nc-gui/components/template/Editor.vue @@ -101,7 +101,7 @@ const isImporting = ref(false) const importingTips = ref>({}) -const checkAllRecord = ref([]) +const checkAllRecord = ref>({}) const formError = ref() @@ -168,14 +168,20 @@ watch( let res = true if (importDataOnly) { for (const tn of Object.keys(srcDestMapping.value)) { + let flag = false if (!atLeastOneEnabledValidation(tn)) { res = false } for (const record of srcDestMapping.value[tn]) { if (!fieldsValidation(record, tn)) { - return false + res = false + flag = true + break } } + if (flag) { + break + } } } else { for (const [_, o] of Object.entries(validateInfos)) { @@ -258,20 +264,13 @@ function deleteTable(tableIdx: number) { function deleteTableColumn(tableIdx: number, columnKey: number) { const columnIdx = data.tables[tableIdx].columns.findIndex((c: ColumnType & { key: number }) => c.key === columnKey) data.tables[tableIdx].columns.splice(columnIdx, 1) -} - -function addNewColumnRow(tableIdx: number, uidt: string) { - data.tables[tableIdx].columns.push({ - key: data.tables[tableIdx].columns.length, - title: `title${data.tables[tableIdx].columns.length + 1}`, - column_name: `title${data.tables[tableIdx].columns.length + 1}`, - uidt, - }) + let key = 0 - nextTick(() => { - const input = inputRefs.value[data.tables[tableIdx].columns.length - 1] - input.focus() - input.select() + data.tables[tableIdx].columns.forEach((_c: ColumnType & { key: number }, i: number) => { + if (data.tables[tableIdx].columns[i].key !== undefined) { + data.tables[tableIdx].columns[i].key = key + key++ + } }) } @@ -763,7 +762,7 @@ watch(modelRef, async () => { {