Browse Source

feat(nc-gui): add callback & push non-nullable data to columnValues

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

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

@ -1,5 +1,4 @@
import { parse } from 'papaparse' import { parse } from 'papaparse'
import TemplateGenerator from './TemplateGenerator'
import { UploadFile } from 'ant-design-vue' import { UploadFile } from 'ant-design-vue'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { import {
@ -11,7 +10,7 @@ import {
isUrlType, isUrlType,
} from '#imports' } from '#imports'
export default class CSVTemplateAdapter extends TemplateGenerator { export default class CSVTemplateAdapter {
config: Record<string, any> config: Record<string, any>
fileName: string fileName: string
files: UploadFile[] files: UploadFile[]
@ -25,7 +24,6 @@ export default class CSVTemplateAdapter extends TemplateGenerator {
columnValues: Record<number, []> columnValues: Record<number, []>
constructor(fileName: string, files: UploadFile[], parserConfig = {}) { constructor(fileName: string, files: UploadFile[], parserConfig = {}) {
super()
this.config = { this.config = {
maxRowsToParse: 500, maxRowsToParse: 500,
...parserConfig, ...parserConfig,
@ -107,7 +105,7 @@ export default class CSVTemplateAdapter extends TemplateGenerator {
if (checkboxType.length === 1) { if (checkboxType.length === 1) {
colProps.uidt = UITypes.Checkbox colProps.uidt = UITypes.Checkbox
} else { } else {
if (columnIdx < this.config.maxRowsToParse) { if (data[columnIdx] && columnIdx < this.config.maxRowsToParse) {
this.columnValues[columnIdx].push(data[columnIdx]) this.columnValues[columnIdx].push(data[columnIdx])
} }
} }
@ -117,7 +115,7 @@ export default class CSVTemplateAdapter extends TemplateGenerator {
colProps.uidt = UITypes.Decimal colProps.uidt = UITypes.Decimal
} }
} else if (colProps.uidt === UITypes.DateTime) { } else if (colProps.uidt === UITypes.DateTime) {
if (columnIdx < this.config.maxRowsToParse) { if (data[columnIdx] && columnIdx < this.config.maxRowsToParse) {
this.columnValues[columnIdx].push(data[columnIdx]) this.columnValues[columnIdx].push(data[columnIdx])
} }
} }
@ -163,7 +161,7 @@ export default class CSVTemplateAdapter extends TemplateGenerator {
} }
} }
parse() { parse(callback: Function) {
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
@ -190,6 +188,7 @@ export default class CSVTemplateAdapter extends TemplateGenerator {
console.log(that.project.tables) console.log(that.project.tables)
// TODO: enable import button // TODO: enable import button
// TODO: put info.file.originFileObj to list // TODO: put info.file.originFileObj to list
callback()
}, },
}) })
} }

Loading…
Cancel
Save