Browse Source

fix(gui-v2): handle json with single / multiple records

pull/2795/head
Wing-Kam Wong 2 years ago
parent
commit
895bfe95ea
  1. 10
      packages/nc-gui-v2/utils/parsers/JSONTemplateAdapter.ts

10
packages/nc-gui-v2/utils/parsers/JSONTemplateAdapter.ts

@ -35,7 +35,7 @@ export default class JSONTemplateAdapter extends TemplateGenerator {
...parserConfig,
}
this.name = name
this._jsonData = typeof data === 'string' ? JSON.parse(data) : data
this._jsonData = data
this.project = {
title: this.name,
tables: [],
@ -46,7 +46,13 @@ export default class JSONTemplateAdapter extends TemplateGenerator {
}
async init() {
this.jsonData = JSON.parse(new TextDecoder().decode(this._jsonData as BufferSource))
const parsedJsonData =
typeof this._jsonData === 'string'
? // for json editor
JSON.parse(this._jsonData)
: // for file upload
JSON.parse(new TextDecoder().decode(this._jsonData as BufferSource))
this.jsonData = Array.isArray(parsedJsonData) ? parsedJsonData : [parsedJsonData]
}
getColumns(): any {

Loading…
Cancel
Save