From 2d6bc0c998379eb3971c5cd81c7becb8b9eb705f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 22 Mar 2021 17:57:19 +0000 Subject: [PATCH] Fix data binding not generating bindable properties for components referencing a data provider ID wrapped for handlebars --- .../builder/src/builderStore/dataBinding.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 3da15de746..880f245667 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -74,13 +74,9 @@ export const getDatasourceForProvider = (asset, component) => { }) if (dataProviderSetting) { const settingValue = component[dataProviderSetting.key] - const providerId = settingValue?.match(/{{\s*literal\s+(\S+)\s*}}/)[1] - if (providerId) { - const provider = findComponent(asset.props, providerId) - return getDatasourceForProvider(asset, provider) - } else { - return null - } + const providerId = extractLiteralHandlebarsID(settingValue) + const provider = findComponent(asset.props, providerId) + return getDatasourceForProvider(asset, provider) } // Extract datasource from component instance @@ -135,11 +131,9 @@ const getContextBindings = (asset, componentId) => { let datasource const setting = contextDefinition.dataProviderSetting const settingValue = component[setting] - if (settingValue) { - const providerId = settingValue.match(/{{\s*literal\s+(\S+)\s*}}/)[1] - const provider = findComponent(asset.props, providerId) - datasource = getDatasourceForProvider(asset, provider) - } + const providerId = extractLiteralHandlebarsID(settingValue) + const provider = findComponent(asset.props, providerId) + datasource = getDatasourceForProvider(asset, provider) if (!datasource) { return } @@ -367,6 +361,17 @@ function bindingReplacement(bindableProperties, textWithBindings, convertTo) { return result } +/** + * Extracts a component ID from a handlebars expression setting of + * {{ literal [componentId] }} + */ +function extractLiteralHandlebarsID(value) { + if (!value) { + return null + } + return value.match(/{{\s*literal[\s\[]+([a-fA-F0-9]+)[\s\]]*}}/)[1] +} + /** * Converts a readable data binding into a runtime data binding */