From e14289abee26854256fd9d39d1e3099072fa50c1 Mon Sep 17 00:00:00 2001 From: Dean Date: Sun, 3 Jul 2022 17:33:25 +0100 Subject: [PATCH] Added fixes for query body binding. Query parameter fixes and pretty bindings added --- .../builder/src/builderStore/dataBinding.js | 12 ++- .../rest/RestExtraConfigForm.svelte | 1 + .../rest/auth/RestAuthenticationModal.svelte | 4 +- .../common/bindings/BindableCombobox.svelte | 68 +++++++++++++++ .../bindings/DrawerBindableCombobox.svelte | 36 ++++---- .../rest/[query]/index.svelte | 86 ++++++++++++------- 6 files changed, 150 insertions(+), 57 deletions(-) create mode 100644 packages/builder/src/components/common/bindings/BindableCombobox.svelte diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 05d17ecf38..234f83d7cc 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -97,13 +97,17 @@ export const toBindingsArray = (valueMap, prefix) => { if (!valueMap) { return [] } - return Object.keys(valueMap).map(binding => { - return { + return Object.keys(valueMap).reduce((acc, binding) => { + if (!binding || !valueMap[binding]) { + return acc + } + acc.push({ type: "context", runtimeBinding: binding, readableBinding: `${prefix}.${binding}`, - } - }) + }) + return acc + }, []) } /** diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte index e049e0cbdf..0165d83dcb 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte @@ -53,6 +53,7 @@ bind:object={parsedHeaders} on:change={evt => onDefaultHeaderUpdate(evt.detail)} noAddButton + bindings={getRestBindings()} />
addHeader.addEntry()}> diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte index d80b60e96c..b754f878ce 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte @@ -2,7 +2,7 @@ import { onMount } from "svelte" import { ModalContent, Layout, Select, Body, Input } from "@budibase/bbui" import { AUTH_TYPE_LABELS, AUTH_TYPES } from "./authTypes" - import DrawerBindableCombobox from "components/common/bindings/DrawerBindableCombobox.svelte" + import BindableCombobox from "components/common/bindings/BindableCombobox.svelte" import { getAuthBindings } from "builderStore/dataBinding" export let configs @@ -205,7 +205,7 @@ /> {/if} {#if form.type === AUTH_TYPES.BEARER} - + import { Combobox } from "@budibase/bbui" + import { + readableToRuntimeBinding, + runtimeToReadableBinding, + } from "builderStore/dataBinding" + import { createEventDispatcher } from "svelte" + import { isJSBinding } from "@budibase/string-templates" + + export let value = "" + export let bindings = [] + export let placeholder + export let label + export let disabled = false + export let options + export let appendBindingsAsOptions = true + export let error + + const dispatch = createEventDispatcher() + + $: readableValue = runtimeToReadableBinding(bindings, value) + $: isJS = isJSBinding(value) + $: allOptions = buildOptions(options, bindings, appendBindingsAsOptions) + + const onChange = (value, optionPicked) => { + // Add HBS braces if picking binding + if (optionPicked && !options?.includes(value)) { + value = `{{ ${value} }}` + } + + dispatch("change", readableToRuntimeBinding(bindings, value)) + } + + const buildOptions = (options, bindings, appendBindingsAsOptions) => { + if (!appendBindingsAsOptions) { + return options + } + return [] + .concat(options || []) + .concat(bindings?.map(binding => binding.readableBinding) || []) + } + + +
+ onChange(e.detail, false)} + on:pick={e => onChange(e.detail, true)} + on:blur={() => dispatch("blur")} + {placeholder} + options={allOptions} + {error} + /> +
+ + diff --git a/packages/builder/src/components/common/bindings/DrawerBindableCombobox.svelte b/packages/builder/src/components/common/bindings/DrawerBindableCombobox.svelte index 2d235c8026..9033844dd0 100644 --- a/packages/builder/src/components/common/bindings/DrawerBindableCombobox.svelte +++ b/packages/builder/src/components/common/bindings/DrawerBindableCombobox.svelte @@ -18,7 +18,6 @@ export let options export let allowJS = true export let appendBindingsAsOptions = true - export let drawerEnabled = false export let error const dispatch = createEventDispatcher() @@ -66,7 +65,7 @@ options={allOptions} {error} /> - {#if !disabled && drawerEnabled} + {#if !disabled}
{/if}
-{#if !drawerEnabled} - - - Add the objects on the left to enrich your text. - - - (tempValue = event.detail)} - {bindings} - {allowJS} - /> - -{/if} + + + + Add the objects on the left to enrich your text. + + + (tempValue = event.detail)} + {bindings} + {allowJS} + /> +