Browse Source

refactor(nc-gui): pass tn & delete column values after it is used

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
c43233ebd7
  1. 10
      packages/nc-gui/utils/parsers/CSVTemplateAdapter.ts

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

@ -20,6 +20,7 @@ export default class CSVTemplateAdapter {
tables: Record<string, any>[] tables: Record<string, any>[]
} }
data: Record<string, any> = {}
columnValues: Record<number, []> columnValues: Record<number, []>
constructor(files: UploadFile[], parserConfig = {}) { constructor(files: UploadFile[], parserConfig = {}) {
@ -39,10 +40,9 @@ export default class CSVTemplateAdapter {
async init() {} async init() {}
initTemplate(tableIdx: number, fileName: string, columnNames: string[]) { initTemplate(tableIdx: number, tn: string, columnNames: string[]) {
const columnNameRowExist = +columnNames.every((v: any) => v === null || typeof v === 'string') const columnNameRowExist = +columnNames.every((v: any) => v === null || typeof v === 'string')
const columnNamePrefixRef: Record<string, any> = { id: 0 } const columnNamePrefixRef: Record<string, any> = { id: 0 }
const tn = fileName.replace(/[` ~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/g, '_').trim()
this.project.tables.push({ this.project.tables.push({
table_name: tn, table_name: tn,
@ -156,6 +156,7 @@ export default class CSVTemplateAdapter {
} else { } else {
this.project.tables[tableIdx].columns[columnIdx].uidt = this.getMaxPossibleUidt(columnIdx) this.project.tables[tableIdx].columns[columnIdx].uidt = this.getMaxPossibleUidt(columnIdx)
} }
delete this.columnValues[columnIdx]
} }
} }
@ -163,13 +164,14 @@ export default class CSVTemplateAdapter {
const that = this const that = this
for (const [tableIdx, file] of this.files.entries()) { for (const [tableIdx, file] of this.files.entries()) {
let steppers = 0 let steppers = 0
const tn = file.name.replace(/[` ~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/g, '_').trim()
parse(file.originFileObj as File, { parse(file.originFileObj as File, {
worker: true, worker: true,
step(row) { step(row) {
steppers += 1 steppers += 1
if (row) { if (row) {
if (steppers === 1) { if (steppers === 1) {
that.initTemplate(tableIdx, file.name!, row.data as []) that.initTemplate(tableIdx, tn, row.data as [])
} else { } else {
that.detectColumnType(row.data as []) that.detectColumnType(row.data as [])
} }
@ -197,7 +199,7 @@ export default class CSVTemplateAdapter {
} }
getData() { getData() {
// return this.data return this.data
} }
getTemplate() { getTemplate() {

Loading…
Cancel
Save