From b4a8109cf0e37ca36ebe1da746936a611d5fbf9d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 29 Jul 2022 14:12:04 +0100 Subject: [PATCH] Adding the examples and helper add functionality for JS as well as hiding button to convert outside of development environment. --- .../common/bindings/BindingPanel.svelte | 48 ++++++++++++---- .../src/components/common/bindings/utils.js | 8 ++- packages/string-templates/manifest.json | 2 +- .../scripts/gen-collection-info.js | 6 +- .../string-templates/src/conversion/index.js | 55 ++++++++++++++++--- .../string-templates/test/hbsToJs.spec.js | 36 +++++++++++- 6 files changed, 129 insertions(+), 26 deletions(-) diff --git a/packages/builder/src/components/common/bindings/BindingPanel.svelte b/packages/builder/src/components/common/bindings/BindingPanel.svelte index 2a9a64b455..4dc9d9700e 100644 --- a/packages/builder/src/components/common/bindings/BindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/BindingPanel.svelte @@ -24,6 +24,7 @@ import { addHBSBinding, addJSBinding } from "./utils" import CodeMirrorEditor from "components/common/CodeMirrorEditor.svelte" import { convertToJS } from "@budibase/string-templates" + import { admin } from "stores/portal" const dispatch = createEventDispatcher() @@ -62,16 +63,24 @@ const updateValue = val => { valid = isValid(readableToRuntimeBinding(bindings, val)) - console.log(readableToRuntimeBinding(bindings, val)) if (valid) { dispatch("change", val) } } - // Adds a HBS helper to the expression - const addHelper = helper => { - hbsValue = addHBSBinding(hbsValue, getCaretPosition(), helper.text) - updateValue(hbsValue) + // Adds a JS/HBS helper to the expression + const addHelper = (helper, js) => { + let value + const pos = getCaretPosition() + if (js) { + const decoded = decodeJSBinding(jsValue) + value = jsValue = encodeJSBinding( + addJSBinding(decoded, pos, helper.text, { helper: true }) + ) + } else { + value = hbsValue = addHBSBinding(hbsValue, pos, helper.text) + } + updateValue(value) } // Adds a data binding to the expression @@ -108,7 +117,6 @@ const convert = () => { const runtime = readableToRuntimeBinding(bindings, hbsValue) - console.log(runtime) const runtimeJs = encodeJSBinding(convertToJS(runtime)) jsValue = runtimeToReadableBinding(bindings, runtimeJs) hbsValue = null @@ -116,6 +124,17 @@ addBinding("", { forceJS: true }) } + const getHelperExample = (helper, js) => { + let example = helper.example || "" + if (js) { + example = convertToJS(example).split("\n")[0].split("= ")[1] + if (example === "null;") { + example = "" + } + } + return example || "" + } + onMount(() => { valid = isValid(readableToRuntimeBinding(bindings, value)) }) @@ -151,18 +170,21 @@ {/if} {/each} - {#if filteredHelpers?.length && !usingJS} + {#if filteredHelpers?.length}
Helpers