From 999d8f3d55b474b9ea957ff5f4e74ecec14cb57f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 6 Dec 2021 19:55:21 +0000 Subject: [PATCH] Add data bindings for top level properties within JSON fields --- packages/builder/src/builderStore/dataBinding.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index ee1e62d4ef..ab7ca2cc7d 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -213,6 +213,21 @@ const getProviderContextBindings = (asset, dataProviders) => { schema = info.schema table = info.table + // Check for any JSON fields so we can add any top level properties + let jsonAdditions = {} + Object.keys(schema).forEach(fieldKey => { + const fieldSchema = schema[fieldKey] + if (fieldSchema.type === "json") { + const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, true) + Object.keys(jsonSchema).forEach(jsonKey => { + jsonAdditions[`${fieldKey}.${jsonKey}`] = { + type: jsonSchema[jsonKey].type, + } + }) + } + }) + schema = { ...schema, ...jsonAdditions } + // For JSON arrays, use the array name as the readable prefix. // Otherwise use the table name if (datasource.type === "jsonarray") {