From c997a928e9980a6fa278a2c634d62250200eae4e Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Tue, 20 Sep 2022 11:15:23 +0200 Subject: [PATCH] chore(nc-gui): cleanup types --- .../utils/parsers/ExcelTemplateAdapter.ts | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts b/packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts index e606b885a0..71a6168d5c 100644 --- a/packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts +++ b/packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts @@ -3,7 +3,7 @@ import { UITypes } from 'nocodb-sdk' import TemplateGenerator from './TemplateGenerator' import { getCheckboxValue, isCheckboxType } from './parserHelpers' -const excelTypeToUidt: Record = { +const excelTypeToUidt: Record = { d: UITypes.DateTime, b: UITypes.Checkbox, n: UITypes.Number, @@ -11,32 +11,46 @@ const excelTypeToUidt: Record = { } export default class ExcelTemplateAdapter extends TemplateGenerator { - config: Record + config: { + maxRowsToParse: number + } & Record + name: string + excelData: any - project: Record - data: Record + + project: { + title: string + tables: any[] + } + + data: Record = {} + wb: any + constructor(name = '', data = {}, parserConfig = {}) { super() this.config = { maxRowsToParse: 500, ...parserConfig, } + this.name = name + this.excelData = data + this.project = { title: this.name, tables: [], } - this.data = {} } async init() { - const options: Record = { + const options = { cellText: true, cellDates: true, } + if (this.name.slice(-3) === 'csv') { this.wb = read(new TextDecoder().decode(new Uint8Array(this.excelData)), { type: 'string', @@ -51,9 +65,10 @@ export default class ExcelTemplateAdapter extends TemplateGenerator { } parse() { - const tableNamePrefixRef: any = {} + const tableNamePrefixRef: Record = {} + for (let i = 0; i < this.wb.SheetNames.length; i++) { - const columnNamePrefixRef: Record = { id: 0 } + const columnNamePrefixRef: Record = { id: 0 } const sheet: any = this.wb.SheetNames[i] let tn: string = (sheet || 'table').replace(/[` ~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/g, '_').trim() @@ -62,7 +77,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator { } tableNamePrefixRef[tn] = 0 - const table: Record = { table_name: tn, ref_table_name: tn, columns: [] } + const table = { table_name: tn, ref_table_name: tn, columns: [] as any[] } this.data[tn] = [] const ws: any = this.wb.Sheets[sheet] const range = utils.decode_range(ws['!ref'])