From e38cc1c079dbe8d4bf56756936f41af9cd6fd309 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 24 Feb 2022 09:17:27 +0000 Subject: [PATCH] Fix table row selection bindings not being generated, add row selection bindings for table blocks, update readable text for row selection bindings --- .../builder/src/builderStore/dataBinding.js | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 4ff608b480..b4d1c0d1c1 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -32,7 +32,7 @@ export const getBindableProperties = (asset, componentId) => { const urlBindings = getUrlBindings(asset) const deviceBindings = getDeviceBindings() const stateBindings = getStateBindings() - const rowBindings = getRowBindings(asset, componentId) + const rowBindings = getRowBindings(asset) return [ ...contextBindings, ...urlBindings, @@ -320,22 +320,33 @@ const getDeviceBindings = () => { /** * Gets all row bindings that are globally available. */ -const getRowBindings = () => { - let tables = [] - getAllAssets().forEach(asset => { - tables = findAllMatchingComponents(asset.props, component => - component._component.endsWith("table") - ) - }) - +const getRowBindings = asset => { let bindings = [] if (get(store).clientFeatures?.rowSelection) { + // Add bindings for table components + let tables = findAllMatchingComponents(asset.props, component => + component._component.endsWith("table") + ) const safeState = makePropSafe("rowSelection") - bindings = tables.map(table => ({ - type: "context", - runtimeBinding: `${safeState}.${makePropSafe(table._id)}`, - readableBinding: `${table._instanceName}.Rows`, - })) + bindings = bindings.concat( + tables.map(table => ({ + type: "context", + runtimeBinding: `${safeState}.${makePropSafe(table._id)}`, + readableBinding: `${table._instanceName}.Selected rows`, + })) + ) + + // Add bindings for table blocks + let tableBlocks = findAllMatchingComponents(asset.props, component => + component._component.endsWith("tableblock") + ) + bindings = bindings.concat( + tableBlocks.map(block => ({ + type: "context", + runtimeBinding: `${safeState}.${makePropSafe(block._id + "-table")}`, + readableBinding: `${block._instanceName}.Selected rows`, + })) + ) } return bindings }