Browse Source

refactor(nc-gui): revise templateGenerator logic & move getData to handleImport

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
b95be12114
  1. 19
      packages/nc-gui/components/dlg/QuickImport.vue

19
packages/nc-gui/components/dlg/QuickImport.vue

@ -2,6 +2,7 @@
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import type { UploadChangeParam, UploadFile } from 'ant-design-vue' import type { UploadChangeParam, UploadFile } from 'ant-design-vue'
import { import {
CSVTemplateAdapter,
ExcelTemplateAdapter, ExcelTemplateAdapter,
ExcelUrlTemplateAdapter, ExcelUrlTemplateAdapter,
Form, Form,
@ -136,6 +137,8 @@ const modalWidth = computed(() => {
return 'max(60vw, 600px)' return 'max(60vw, 600px)'
}) })
let templateGenerator: CSVTemplateAdapter | JSONTemplateAdapter | ExcelTemplateAdapter | null
async function handlePreImport() { async function handlePreImport() {
preImportLoading.value = true preImportLoading.value = true
isParsingData.value = true isParsingData.value = true
@ -161,7 +164,13 @@ async function handlePreImport() {
async function handleImport() { async function handleImport() {
try { try {
if (!templateGenerator) {
message.error(t('msg.error.templateGeneratorNotFound'))
return
}
importLoading.value = true importLoading.value = true
importData.value = templateGenerator.getData()
await templateEditorRef.value.importTemplate() await templateEditorRef.value.importTemplate()
} catch (e: any) { } catch (e: any) {
return message.error(await extractSdkResponseErrorMsg(e)) return message.error(await extractSdkResponseErrorMsg(e))
@ -178,7 +187,7 @@ async function parseAndExtractData2(val: UploadFile[]) {
importData.value = null importData.value = null
importColumns.value = [] importColumns.value = []
const templateGenerator = getAdapter(val) templateGenerator = getAdapter(val)
if (!templateGenerator) { if (!templateGenerator) {
message.error(t('msg.error.templateGeneratorNotFound')) message.error(t('msg.error.templateGeneratorNotFound'))
@ -188,10 +197,9 @@ async function parseAndExtractData2(val: UploadFile[]) {
await templateGenerator.init() await templateGenerator.init()
templateGenerator.parse(() => { templateGenerator.parse(() => {
templateData.value = templateGenerator.getTemplate() templateData.value = templateGenerator!.getTemplate()
// TODO(import): remove
// templateData.value.tables[0].table_name = populateUniqueTableName() // templateData.value.tables[0].table_name = populateUniqueTableName()
// importData.value = templateGenerator.getData()
// if (importOnly) importColumns.value = templateGenerator.getColumns() // if (importOnly) importColumns.value = templateGenerator.getColumns()
templateEditorModal.value = true templateEditorModal.value = true
isParsingData.value = false isParsingData.value = false
@ -218,9 +226,8 @@ async function parseAndExtractData(val: string | ArrayBuffer) {
templateGenerator.parse(() => {}) templateGenerator.parse(() => {})
templateData.value = templateGenerator.getTemplate() templateData.value = templateGenerator.getTemplate()
templateData.value.tables[0].table_name = populateUniqueTableName()
importData.value = templateGenerator.getData()
// TODO(import): check
if (importOnly) importColumns.value = templateGenerator.getColumns() if (importOnly) importColumns.value = templateGenerator.getColumns()
templateEditorModal.value = true templateEditorModal.value = true

Loading…
Cancel
Save