From ffd98b117566ffbb272f32a1e3f899dc0985a51f Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 10 Aug 2022 15:29:22 +0800 Subject: [PATCH] feat(gui-v2): add maxRowsToParse --- .../nc-gui-v2/components/dlg/QuickImport.vue | 1 + .../nc-gui-v2/components/template/Editor.vue | 28 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/QuickImport.vue b/packages/nc-gui-v2/components/dlg/QuickImport.vue index 27f5045660..00e212b2e4 100644 --- a/packages/nc-gui-v2/components/dlg/QuickImport.vue +++ b/packages/nc-gui-v2/components/dlg/QuickImport.vue @@ -279,6 +279,7 @@ function getAdapter(name: string, val: any) { :import-columns="importColumns" :import-only="importOnly" :quick-import-type="importType" + :max-rows-to-parse="importState.parserConfig.maxRowsToParse" @import="handleImport" /> diff --git a/packages/nc-gui-v2/components/template/Editor.vue b/packages/nc-gui-v2/components/template/Editor.vue index 6038bf26c5..d72670d943 100644 --- a/packages/nc-gui-v2/components/template/Editor.vue +++ b/packages/nc-gui-v2/components/template/Editor.vue @@ -21,6 +21,7 @@ interface Props { importData: Record[] importColumns: any[] importOnly: boolean + maxRowsToParse: number } interface Option { @@ -28,7 +29,7 @@ interface Option { value: string } -const { quickImportType, projectTemplate, importData, importColumns, importOnly } = defineProps() +const { quickImportType, projectTemplate, importData, importColumns, importOnly, maxRowsToParse } = defineProps() const emit = defineEmits(['import']) @@ -211,7 +212,6 @@ function atLeastOneEnabledValidation() { } function fieldsValidation(table: Record, record: Record) { - console.log(importData[table.ref_table_name].slice(0, 500)) // if it is not selected, then pass validation if (!record.enabled) { return true @@ -231,7 +231,7 @@ function fieldsValidation(table: Record, record: Record) => r[record.srcCn] === null || r[record.srcCn] === undefined || r[record.srcCn] === '') ) { notification.error({ @@ -245,7 +245,7 @@ function fieldsValidation(table: Record, record: Record) => r[record.sourceCn] !== null && r[record.srcCn] !== undefined && isNaN(+r[record.srcCn]), ) @@ -259,7 +259,7 @@ function fieldsValidation(table: Record, record: Record) => { + importData[table.ref_table_name].slice(0, maxRowsToParse).some((r: Record) => { if ((r: Record) => r[record.srcCn] !== null && r[record.srcCn] !== undefined) { let input = r[record.srcCn] if (typeof input === 'string') { @@ -292,7 +292,6 @@ function fieldsValidation(table: Record, record: Record) => + const projectName = project.value.title as string + const tableName = meta?.value.title as string + const total = data.length + for (let i = 0, progress = 0; i < total; i += maxRowsToParse) { + const batchData = data.slice(i, i + maxRowsToParse).map((row: Record) => srcDestMapping.value.reduce((res: Record, col: Record) => { - console.log(col) if (col.enabled && col.destCn) { const v = columns.value.find((c: Record) => c.title === col.destCn) as Record let input = row[col.srcCn] @@ -333,10 +332,9 @@ async function importTemplate() { return res }, {}), ) - await $api.dbTableRow.bulkCreate('noco', project.value.title as string, meta?.value.title as string, batchData) + await $api.dbTableRow.bulkCreate('noco', projectName, tableName, batchData) + importingTip.value = `Importing data to ${projectName}: ${progress}/${total} records` progress += batchData.length - // this.$store.commit('loader/MutMessage', `Importing data : ${progress}/${data.length}`); - // this.$store.commit('loader/MutProgress', Math.round((100 * progress) / data.length)); } // reload table @@ -415,7 +413,7 @@ async function importTemplate() { if (importData) { let total = 0 let progress = 0 - const offset = 500 + const offset = maxRowsToParse const projectName = project.value.title as string await Promise.all( data.tables.map((table: Record) =>