From c980801579ba2e5bde3cbc190e5361f47f3c9f60 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 5 Apr 2022 16:05:29 +0100 Subject: [PATCH 1/2] Add role IDs as bindings --- .../builder/src/builderStore/dataBinding.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index c8b4ae8de9..de16cef2ef 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -7,7 +7,11 @@ import { getComponentSettings, } from "./componentUtils" import { store } from "builderStore" -import { queries as queriesStores, tables as tablesStore } from "stores/backend" +import { + queries as queriesStores, + tables as tablesStore, + roles as rolesStore, +} from "stores/backend" import { makePropSafe, isJSBinding, @@ -33,6 +37,7 @@ export const getBindableProperties = (asset, componentId) => { const deviceBindings = getDeviceBindings() const stateBindings = getStateBindings() const selectedRowsBindings = getSelectedRowsBindings(asset) + const roleBindings = getRoleBindings() return [ ...contextBindings, ...urlBindings, @@ -40,6 +45,7 @@ export const getBindableProperties = (asset, componentId) => { ...userBindings, ...deviceBindings, ...selectedRowsBindings, + ...roleBindings, ] } @@ -391,6 +397,16 @@ const getUrlBindings = asset => { })) } +const getRoleBindings = () => { + return (get(rolesStore) || []).map(role => { + return { + type: "context", + runtimeBinding: `trim "${role._id}"`, + readableBinding: `Roles.${role.name}`, + } + }) +} + /** * Gets all bindable properties exposed in a button actions flow up until * the specified action ID, as well as context provided for the action From e5678d9b2701068506909c9d642751f8b1d84f2f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 6 Apr 2022 08:22:10 +0100 Subject: [PATCH 2/2] Update role bindings to use Role prefix rather than Roles --- packages/builder/src/builderStore/dataBinding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index de16cef2ef..8dff56dd6b 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -402,7 +402,7 @@ const getRoleBindings = () => { return { type: "context", runtimeBinding: `trim "${role._id}"`, - readableBinding: `Roles.${role.name}`, + readableBinding: `Role.${role.name}`, } }) }