From 2a814abd53319e8e59c8ca2a28e07e9854998d80 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 6 Dec 2021 12:14:06 +0000 Subject: [PATCH] Add more comments to clarify data binding behaviour --- packages/builder/src/builderStore/dataBinding.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index f5b8fcbb5f..ee1e62d4ef 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -404,11 +404,18 @@ export const getSchemaForDatasource = (asset, datasource, isForm = false) => { // "jsonarray" datasources are arrays inside JSON fields else if (type === "jsonarray") { table = tables.find(table => table._id === datasource.tableId) + + // We parse the label of the datasource to work out where we are inside + // the structure. We can use this to know which part of the schema + // is available underneath our current position. const keysToSchema = datasource.label.split(".").slice(2) let jsonSchema = table?.schema for (let i = 0; i < keysToSchema.length; i++) { jsonSchema = jsonSchema[keysToSchema[i]].schema } + + // We need to convert the JSON schema into a more typical looking table + // schema so that it works with the rest of the platform schema = convertJSONSchemaToTableSchema(jsonSchema, true) }