Browse Source

fix(nc-gui): import to existing table issue

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
c513997014
  1. 5
      packages/nc-gui/components/dlg/QuickImport.vue
  2. 36
      packages/nc-gui/utils/parsers/CSVTemplateAdapter.ts

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

@ -169,9 +169,7 @@ async function handleImport() {
message.error(t('msg.error.templateGeneratorNotFound'))
return
}
importLoading.value = true
importData.value = templateGenerator.getData()
await templateEditorRef.value.importTemplate()
} catch (e: any) {
return message.error(await extractSdkResponseErrorMsg(e))
@ -200,7 +198,8 @@ async function parseAndExtractStreamData(val: UploadFile[]) {
templateData.value = templateGenerator!.getTemplate()
// TODO(import): remove
// templateData.value.tables[0].table_name = populateUniqueTableName()
// if (importOnly) importColumns.value = templateGenerator.getColumns()
if (importOnly) importColumns.value = templateGenerator!.getColumns()
importData.value = templateGenerator!.getData()
templateEditorModal.value = true
isParsingData.value = false
preImportLoading.value = false

36
packages/nc-gui/utils/parsers/CSVTemplateAdapter.ts

@ -204,6 +204,9 @@ export default class CSVTemplateAdapter {
for (const [tableIdx, file] of this.files.entries()) {
let steppers = 0
const tn = file.name.replace(/[` ~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/g, '_').trim()
this.data[tn] = []
// parse column meta
parse(file.originFileObj as File, {
worker: true,
skipEmptyLines: 'greedy',
@ -238,23 +241,10 @@ export default class CSVTemplateAdapter {
console.log('complete')
console.log(`steppers: ${steppers}`)
that.updateTemplate(tableIdx)
callback()
},
})
}
}
getColumns() {
// return this.columns
}
getData() {
const that = this
for (const [tableIdx, file] of this.files.entries()) {
let steppers = 0
const tn = file.name.replace(/[` ~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/g, '_').trim()
this.data[tn] = []
if (this.config.importData) {
// parse table data
if (that.config.importData) {
steppers = 0
parse(file.originFileObj as File, {
worker: true,
skipEmptyLines: 'greedy',
@ -281,10 +271,24 @@ export default class CSVTemplateAdapter {
complete() {
console.log('getData(): complete')
console.log(`getData(): steppers: ${steppers}`)
callback()
},
// TODO(import): add error
})
} else {
callback()
}
},
})
}
}
getColumns() {
console.log(this.project.tables.map((t: Record<string, any>) => t.columns))
return this.project.tables.map((t: Record<string, any>) => t.columns)
}
getData() {
return this.data
}

Loading…
Cancel
Save