Improve handling of nullish expression to provide a more reliable match to the real evaluation
This commit is contained in:
parent
d11e0a8e62
commit
5010c4fe4e
|
@ -12,13 +12,9 @@
|
||||||
isValid,
|
isValid,
|
||||||
decodeJSBinding,
|
decodeJSBinding,
|
||||||
encodeJSBinding,
|
encodeJSBinding,
|
||||||
convertToJS,
|
|
||||||
processStringSync,
|
processStringSync,
|
||||||
} from "@budibase/string-templates"
|
} from "@budibase/string-templates"
|
||||||
import {
|
import { readableToRuntimeBinding } from "dataBinding"
|
||||||
readableToRuntimeBinding,
|
|
||||||
runtimeToReadableBinding,
|
|
||||||
} from "dataBinding"
|
|
||||||
import CodeEditor from "../CodeEditor/CodeEditor.svelte"
|
import CodeEditor from "../CodeEditor/CodeEditor.svelte"
|
||||||
import {
|
import {
|
||||||
getHelperCompletions,
|
getHelperCompletions,
|
||||||
|
@ -93,7 +89,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const getBindingValue = (binding, context) => {
|
const getBindingValue = (binding, context) => {
|
||||||
const hbs = `{{ literal ${binding.runtimeBinding} }}`
|
const js = `return $("${binding.runtimeBinding}")`
|
||||||
|
const hbs = encodeJSBinding(js)
|
||||||
const res = processStringSync(hbs, context)
|
const res = processStringSync(hbs, context)
|
||||||
return JSON.stringify(res, null, 2)
|
return JSON.stringify(res, null, 2)
|
||||||
}
|
}
|
||||||
|
@ -171,15 +168,6 @@
|
||||||
updateValue(jsValue)
|
updateValue(jsValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
const convert = () => {
|
|
||||||
const runtime = readableToRuntimeBinding(enrichedBindings, hbsValue)
|
|
||||||
const runtimeJs = encodeJSBinding(convertToJS(runtime))
|
|
||||||
jsValue = runtimeToReadableBinding(enrichedBindings, runtimeJs)
|
|
||||||
hbsValue = null
|
|
||||||
mode = "JavaScript"
|
|
||||||
onSelectBinding("", { forceJS: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
valid = isValid(readableToRuntimeBinding(enrichedBindings, value))
|
valid = isValid(readableToRuntimeBinding(enrichedBindings, value))
|
||||||
})
|
})
|
||||||
|
@ -296,7 +284,11 @@
|
||||||
mode={editorMode}
|
mode={editorMode}
|
||||||
/>
|
/>
|
||||||
{:else if sidePanel === SidePanels.Evaluation}
|
{:else if sidePanel === SidePanels.Evaluation}
|
||||||
<EvaluationSidePanel {expressionResult} {evaluating} />
|
<EvaluationSidePanel
|
||||||
|
{expressionResult}
|
||||||
|
{evaluating}
|
||||||
|
expression={editorValue}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const showBindingPopover = (binding, target) => {
|
const showBindingPopover = (binding, target) => {
|
||||||
if (!context) {
|
if (!context || !binding.value || binding.value === "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
stopHidingPopover()
|
stopHidingPopover()
|
||||||
|
|
|
@ -6,13 +6,17 @@
|
||||||
|
|
||||||
export let expressionResult
|
export let expressionResult
|
||||||
export let evaluating = false
|
export let evaluating = false
|
||||||
|
export let expression = null
|
||||||
|
|
||||||
$: error = expressionResult === "Error while executing JS"
|
$: error = expressionResult === "Error while executing JS"
|
||||||
$: empty = expressionResult == null || expressionResult === ""
|
$: empty = expression == null || expression?.trim() === ""
|
||||||
$: success = !error && !empty
|
$: success = !error && !empty
|
||||||
$: highlightedResult = highlight(expressionResult)
|
$: highlightedResult = highlight(expressionResult)
|
||||||
|
|
||||||
const highlight = json => {
|
const highlight = json => {
|
||||||
|
if (json == null) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
// Attempt to parse and then stringify, in case this is valid JSON
|
// Attempt to parse and then stringify, in case this is valid JSON
|
||||||
try {
|
try {
|
||||||
json = JSON.stringify(JSON.parse(json), null, 2)
|
json = JSON.stringify(JSON.parse(json), null, 2)
|
||||||
|
@ -67,10 +71,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
{#if expressionResult}
|
{#if empty}
|
||||||
{@html highlightedResult}
|
|
||||||
{:else}
|
|
||||||
Your expression will be evaluated here
|
Your expression will be evaluated here
|
||||||
|
{:else}
|
||||||
|
{@html highlightedResult}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue