Browse Source

Enable support for handling shallow non-object arrays in JSON fields

master
Andrew Kingston 5 years ago
parent
commit
39e1e84512
  1. 4
      packages/builder/src/builderStore/jsonUtils.js
  2. 12
      packages/client/src/components/app/DataProvider.svelte

4
packages/builder/src/builderStore/jsonUtils.js

@ -7,6 +7,10 @@ export const convertJSONSchemaToTableSchema = (
} }
if (jsonSchema.schema) { if (jsonSchema.schema) {
jsonSchema = jsonSchema.schema jsonSchema = jsonSchema.schema
} else {
jsonSchema = {
value: jsonSchema,
}
} }
const keys = extractJSONSchemaKeys(jsonSchema, squashObjects) const keys = extractJSONSchemaKeys(jsonSchema, squashObjects)
let schema = {} let schema = {}

12
packages/client/src/components/app/DataProvider.svelte

@ -194,18 +194,18 @@
// For providers referencing another provider, just use the rows it // For providers referencing another provider, just use the rows it
// provides // provides
allRows = dataSource?.value?.rows || [] allRows = dataSource?.value?.rows || []
} else if (dataSource?.type === "field") { } else if (
// Field sources will be available from context. dataSource?.type === "field" ||
// Enrich non object elements into object to ensure a valid schema. 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 || [] const data = dataSource?.value || []
if (Array.isArray(data) && data[0] && typeof data[0] !== "object") { if (Array.isArray(data) && data[0] && typeof data[0] !== "object") {
allRows = data.map(value => ({ value })) allRows = data.map(value => ({ value }))
} else { } else {
allRows = data allRows = data
} }
} else if (dataSource?.type === "jsonarray") {
// JSON array sources will be available from context
allRows = dataSource?.value || []
} else { } else {
// For other data sources like queries or views, fetch all rows from the // For other data sources like queries or views, fetch all rows from the
// server // server

Loading…
Cancel
Save