From 931ebde3f7d41aa48fae7edad88b137bd8d501b6 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 28 Oct 2024 21:12:33 +0000 Subject: [PATCH 1/2] Add settings and user bindings to drawer --- .../FlowChart/StepNode.svelte | 11 ++++- packages/builder/src/dataBinding.js | 37 ++++++++++++++++ .../builder/src/stores/builder/automations.js | 43 ++++++++++++++++++- 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/StepNode.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/StepNode.svelte index b420ecacb8..323dbaf739 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/StepNode.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/StepNode.svelte @@ -36,9 +36,16 @@ $: environmentBindings = automationStore.actions.buildEnvironmentBindings($memoEnvVariables) - // Combine all bindings for the step - $: bindings = [...availableBindings, ...environmentBindings] + $: userBindings = automationStore.actions.buildUserBindings() + $: settingBindings = automationStore.actions.buildSettingBindings() + // Combine all bindings for the step + $: bindings = [ + ...availableBindings, + ...environmentBindings, + ...userBindings, + ...settingBindings, + ] onMount(() => { // Register the trigger as the focus element for the automation // Onload, the canvas will use the dimensions to center the step diff --git a/packages/builder/src/dataBinding.js b/packages/builder/src/dataBinding.js index e15c4c4b0d..95b91109a7 100644 --- a/packages/builder/src/dataBinding.js +++ b/packages/builder/src/dataBinding.js @@ -614,6 +614,43 @@ const getDeviceBindings = () => { return bindings } +/** + * Gets all device bindings that are globally available. + */ +export const getSettingBindings = () => { + let bindings = [] + const safeSetting = makePropSafe("settings") + + bindings = [ + { + type: "context", + runtimeBinding: `${safeSetting}.${makePropSafe("url")}`, + readableBinding: `Settings.url`, + category: "Settings", + icon: "Settings", + display: { type: "string", name: "url" }, + }, + { + type: "context", + runtimeBinding: `${safeSetting}.${makePropSafe("logo")}`, + readableBinding: `Settings.logo`, + category: "Settings", + icon: "Settings", + display: { type: "string", name: "logo" }, + }, + { + type: "context", + runtimeBinding: `${safeSetting}.${makePropSafe("company")}`, + readableBinding: `Settings.company`, + category: "Settings", + icon: "Settings", + display: { type: "string", name: "company" }, + }, + ] + + return bindings +} + /** * Gets all selected rows bindings for tables in the current asset. * TODO: remove in future because we don't need a separate store for this diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 8eedb12734..81a6784e21 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -6,7 +6,12 @@ import { createHistoryStore } from "stores/builder/history" import { licensing } from "stores/portal" import { tables } from "stores/builder" import { notifications } from "@budibase/bbui" -import { getEnvironmentBindings, migrateReferencesInObject } from "dataBinding" +import { + getEnvironmentBindings, + migrateReferencesInObject, + getUserBindings, + getSettingBindings, +} from "dataBinding" import { AutomationTriggerStepId, AutomationEventType, @@ -334,6 +339,42 @@ const automationActions = store => ({ } return [] }, + + /** + * Get user bindings + * + * @returns {Array} all available user bindings + */ + buildUserBindings: () => { + return getUserBindings().map(binding => { + return { + ...binding, + category: "User", + display: { + ...binding.display, + rank: 98, + }, + } + }) + }, + + /** + * Get user bindings + * + * @returns {Array} all available user bindings + */ + buildSettingBindings: () => { + return getSettingBindings().map(binding => { + return { + ...binding, + display: { + ...binding.display, + rank: 98, + }, + } + }) + }, + /** * Take the supplied step id and aggregate all bindings for every * step preceding it. From b999741f4d47e2566f855cf09781918d94cd8cf1 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 28 Oct 2024 21:14:52 +0000 Subject: [PATCH 2/2] some lint --- packages/builder/src/dataBinding.js | 3 --- packages/builder/src/stores/builder/automations.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/dataBinding.js b/packages/builder/src/dataBinding.js index 95b91109a7..8adc27ee59 100644 --- a/packages/builder/src/dataBinding.js +++ b/packages/builder/src/dataBinding.js @@ -614,9 +614,6 @@ const getDeviceBindings = () => { return bindings } -/** - * Gets all device bindings that are globally available. - */ export const getSettingBindings = () => { let bindings = [] const safeSetting = makePropSafe("settings") diff --git a/packages/builder/src/stores/builder/automations.js b/packages/builder/src/stores/builder/automations.js index 81a6784e21..fb6a865f29 100644 --- a/packages/builder/src/stores/builder/automations.js +++ b/packages/builder/src/stores/builder/automations.js @@ -359,9 +359,9 @@ const automationActions = store => ({ }, /** - * Get user bindings + * Get settings bindings * - * @returns {Array} all available user bindings + * @returns {Array} all available settings bindings */ buildSettingBindings: () => { return getSettingBindings().map(binding => {