From c486a311b1da77c841bcfa5081358ecec63194a2 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 29 Mar 2021 16:37:17 +0100 Subject: [PATCH] Update search component to work with new data bindings. Simplify manifest context entries for data bindings --- .../builder/src/builderStore/dataBinding.js | 18 +++++++----------- packages/standard-components/manifest.json | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index d68b0868e2..01bf5a063e 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -35,7 +35,7 @@ export const getDataProviderComponents = (asset, componentId) => { // Filter by only data provider components return path.filter(component => { const def = store.actions.components.getDefinition(component._component) - return def?.dataContext != null + return def?.context != null }) } @@ -113,32 +113,28 @@ const getContextBindings = (asset, componentId) => { // Create bindings for each data provider dataProviders.forEach(component => { const def = store.actions.components.getDefinition(component._component) - const contextDefinition = def.dataContext + const contextDefinition = def.context let schema let readablePrefix - // Forms are an edge case which do not need table schemas if (contextDefinition.type === "form") { + // Forms do not need table schemas + // Their schemas are built from their component field names schema = buildFormSchema(component) readablePrefix = "Fields" } else if (contextDefinition.type === "static") { + // Static contexts are fully defined by the components schema = {} const values = contextDefinition.values || [] values.forEach(value => { schema[value.key] = { name: value.label, type: "string" } }) } else if (contextDefinition.type === "schema") { - let datasource - const setting = contextDefinition.dataProviderSetting - const settingValue = component[setting] - const providerId = extractLiteralHandlebarsID(settingValue) - const provider = findComponent(asset.props, providerId) - datasource = getDatasourceForProvider(asset, provider) + // Schema contexts are generated dynamically depending on their data + const datasource = getDatasourceForProvider(asset, component) if (!datasource) { return } - - // Get schema and table for the datasource const info = getSchemaForDatasource(datasource) schema = info.schema readablePrefix = info.table?.name diff --git a/packages/standard-components/manifest.json b/packages/standard-components/manifest.json index 1d9b83cf8c..55d86f00ea 100644 --- a/packages/standard-components/manifest.json +++ b/packages/standard-components/manifest.json @@ -61,9 +61,8 @@ "key": "filter" } ], - "dataContext": { - "type": "schema", - "dataProviderSetting": "dataProvider" + "context": { + "type": "schema" } }, "search": { @@ -96,7 +95,10 @@ "key": "noRowsMessage", "defaultValue": "No rows found." } - ] + ], + "context": { + "type": "schema" + } }, "stackedlist": { "name": "Stacked List", @@ -1125,7 +1127,7 @@ "defaultValue": false } ], - "dataContext": { + "context": { "type": "form" } }, @@ -1446,7 +1448,7 @@ "key": "limit" } ], - "dataContext": { + "context": { "type": "static", "values": [ { @@ -1548,9 +1550,8 @@ "defaultValue": false } ], - "dataContext": { - "type": "schema", - "dataProviderSetting": "dataProvider" + "context": { + "type": "schema" } } }