From a5b4087f64cbb8e1157af1dfb776918ff835a365 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 6 Dec 2021 18:12:27 +0000 Subject: [PATCH] Enable support for handling shallow non-object arrays in JSON fields --- packages/builder/src/builderStore/jsonUtils.js | 4 ++++ .../client/src/components/app/DataProvider.svelte | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/builderStore/jsonUtils.js b/packages/builder/src/builderStore/jsonUtils.js index 4b03a67234..6f6db763a6 100644 --- a/packages/builder/src/builderStore/jsonUtils.js +++ b/packages/builder/src/builderStore/jsonUtils.js @@ -7,6 +7,10 @@ export const convertJSONSchemaToTableSchema = ( } if (jsonSchema.schema) { jsonSchema = jsonSchema.schema + } else { + jsonSchema = { + value: jsonSchema, + } } const keys = extractJSONSchemaKeys(jsonSchema, squashObjects) let schema = {} diff --git a/packages/client/src/components/app/DataProvider.svelte b/packages/client/src/components/app/DataProvider.svelte index 291bb6fcf8..7c3aab6275 100644 --- a/packages/client/src/components/app/DataProvider.svelte +++ b/packages/client/src/components/app/DataProvider.svelte @@ -194,18 +194,18 @@ // For providers referencing another provider, just use the rows it // provides allRows = dataSource?.value?.rows || [] - } else if (dataSource?.type === "field") { - // Field sources will be available from context. - // Enrich non object elements into object to ensure a valid schema. + } else if ( + dataSource?.type === "field" || + dataSource?.type === "jsonarray" + ) { + // These sources will be available directly from context. + // Enrich non object elements into objects to ensure a valid schema. const data = dataSource?.value || [] if (Array.isArray(data) && data[0] && typeof data[0] !== "object") { allRows = data.map(value => ({ value })) } else { allRows = data } - } else if (dataSource?.type === "jsonarray") { - // JSON array sources will be available from context - allRows = dataSource?.value || [] } else { // For other data sources like queries or views, fetch all rows from the // server