Browse Source

feat(nc-gui): populateUniqueTableName

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

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

@ -200,6 +200,10 @@ async function parseAndExtractData(val: UploadFile[] | ArrayBuffer | string) {
await templateGenerator.parse() await templateGenerator.parse()
templateData.value = templateGenerator!.getTemplate() templateData.value = templateGenerator!.getTemplate()
templateData.value.tables = templateData.value.tables.map((table: Record<string, any>) => ({
...table,
table_name: populateUniqueTableName(table.table_name),
}))
if (importDataOnly) importColumns.value = templateGenerator!.getColumns() if (importDataOnly) importColumns.value = templateGenerator!.getColumns()
importData.value = templateGenerator!.getData() importData.value = templateGenerator!.getData()
templateEditorModal.value = true templateEditorModal.value = true
@ -259,14 +263,19 @@ function formatJson() {
jsonEditorRef.value?.format() jsonEditorRef.value?.format()
} }
function populateUniqueTableName() { function populateUniqueTableName(tn: string) {
let c = 1 let c = 1
while (
while (tables.value.some((t: TableType) => t.title === `Sheet${c}`)) { tables.value.some((t: TableType) => {
c++ const s = t.table_name.split('___')
let target = t.table_name
if (s.length > 1) target = s[1]
return target === `${tn}`
})
) {
tn = `${tn}_${c++}`
} }
return tn
return `Sheet${c}`
} }
function getAdapter(val: any) { function getAdapter(val: any) {

Loading…
Cancel
Save