Fix issue with validity checking binding expressions

This commit is contained in:
Andrew Kingston 2021-10-14 12:53:56 +01:00
parent e43af1afaa
commit 6f67a8f20e
2 changed files with 34 additions and 794 deletions

View File

@ -9,7 +9,7 @@
Body, Body,
Layout, Layout,
} from "@budibase/bbui" } from "@budibase/bbui"
import { createEventDispatcher } from "svelte" import { createEventDispatcher, onMount } from "svelte"
import { import {
isValid, isValid,
decodeJSBinding, decodeJSBinding,
@ -36,7 +36,6 @@
let hbsValue = initialValueJS ? null : value let hbsValue = initialValueJS ? null : value
$: usingJS = mode === "JavaScript" $: usingJS = mode === "JavaScript"
$: valid = isValid(readableToRuntimeBinding(bindableProperties, value))
$: ({ context } = groupBy("type", bindableProperties)) $: ({ context } = groupBy("type", bindableProperties))
$: searchRgx = new RegExp(search, "ig") $: searchRgx = new RegExp(search, "ig")
$: filteredBindings = context?.filter(context => { $: filteredBindings = context?.filter(context => {
@ -46,10 +45,17 @@
return helper.label.match(searchRgx) || helper.description.match(searchRgx) return helper.label.match(searchRgx) || helper.description.match(searchRgx)
}) })
const updateValue = value => {
valid = isValid(readableToRuntimeBinding(bindableProperties, value))
if (valid) {
dispatch("change", value)
}
}
// Adds a HBS helper to the expression // Adds a HBS helper to the expression
const addHelper = helper => { const addHelper = helper => {
hbsValue = addHBSBinding(value, getCaretPosition(), helper.text) hbsValue = addHBSBinding(value, getCaretPosition(), helper.text)
dispatch("change", hbsValue) updateValue(hbsValue)
} }
// Adds a data binding to the expression // Adds a data binding to the expression
@ -58,31 +64,35 @@
let js = decodeJSBinding(jsValue) let js = decodeJSBinding(jsValue)
js = addJSBinding(js, getCaretPosition(), binding.readableBinding) js = addJSBinding(js, getCaretPosition(), binding.readableBinding)
jsValue = encodeJSBinding(js) jsValue = encodeJSBinding(js)
dispatch("change", jsValue) updateValue(jsValue)
} else { } else {
hbsValue = addHBSBinding( hbsValue = addHBSBinding(
hbsValue, hbsValue,
getCaretPosition(), getCaretPosition(),
binding.readableBinding binding.readableBinding
) )
dispatch("change", hbsValue) updateValue(hbsValue)
} }
} }
const onChangeMode = e => { const onChangeMode = e => {
mode = e.detail mode = e.detail
dispatch("change", mode === "JavaScript" ? jsValue : hbsValue) updateValue(mode === "JavaScript" ? jsValue : hbsValue)
} }
const onChangeHBSValue = e => { const onChangeHBSValue = e => {
hbsValue = e.detail hbsValue = e.detail
dispatch("change", hbsValue) updateValue(hbsValue)
} }
const onChangeJSValue = e => { const onChangeJSValue = e => {
jsValue = encodeJSBinding(e.detail) jsValue = encodeJSBinding(e.detail)
dispatch("change", jsValue) updateValue(jsValue)
} }
onMount(() => {
valid = isValid(readableToRuntimeBinding(bindableProperties, value))
})
</script> </script>
<DrawerContent> <DrawerContent>

File diff suppressed because it is too large Load Diff