From fb7035e7b1c8a32494d2f8c7f49c98ffb43b6374 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 26 Jul 2022 12:33:10 +0800 Subject: [PATCH] fix(gui-v2): json template adapter --- .../utils/parsers/JSONTemplateAdapter.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/nc-gui-v2/utils/parsers/JSONTemplateAdapter.ts b/packages/nc-gui-v2/utils/parsers/JSONTemplateAdapter.ts index 1194e2df32..e397584e1b 100644 --- a/packages/nc-gui-v2/utils/parsers/JSONTemplateAdapter.ts +++ b/packages/nc-gui-v2/utils/parsers/JSONTemplateAdapter.ts @@ -23,11 +23,11 @@ const extractNestedData: any = (obj: any, path: any) => path.reduce((val: any, k export default class JSONTemplateAdapter extends TemplateGenerator { config: Record name: string - _jsonData: string | object - project: Record data: Record + _jsonData: string | Record + jsonData: Record + project: Record columns: object - csv: Record constructor(name = 'test', data: object, parserConfig = {}) { super() this.config = { @@ -40,16 +40,13 @@ export default class JSONTemplateAdapter extends TemplateGenerator { title: this.name, tables: [], } + this.jsonData = [] + this.data = [] this.columns = {} - this.data = {} - this.csv = {} } - async init() {} - - parseData(): any { - this.columns = this.csv.meta.fields - this.data = this.csv.data + async init() { + this.jsonData = JSON.parse(new TextDecoder().decode(this._jsonData as BufferSource)) } getColumns(): any { @@ -60,10 +57,6 @@ export default class JSONTemplateAdapter extends TemplateGenerator { return this.data } - get jsonData(): any { - return Array.isArray(this._jsonData) ? this._jsonData : [this._jsonData] - } - parse(): any { const jsonData = this.jsonData const tn = 'table' @@ -148,7 +141,7 @@ export default class JSONTemplateAdapter extends TemplateGenerator { } _parseTableData(tableMeta: any) { - for (const row of this.jsonData) { + for (const row of this.jsonData as any) { const rowData: any = {} for (let i = 0; i < tableMeta.columns.length; i++) { const value = extractNestedData(row, tableMeta.columns[i].path || [])