Moving drawers around to be a common component as they are utilised in a few places, keep all the binding work together, as well as some fixing for readable/runtime binding detection and conversion.
This commit is contained in:
parent
b7a767a571
commit
a7022de9b5
|
@ -340,8 +340,16 @@ function shouldReplaceBinding(currentValue, from, convertTo) {
|
||||||
if (convertTo === "readableBinding") {
|
if (convertTo === "readableBinding") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// remove all the spaces, if the input is surrounded by spaces e.g. [ Auto ID ] then
|
||||||
|
// this makes sure it is detected
|
||||||
const noSpaces = currentValue.replace(/\s+/g, "")
|
const noSpaces = currentValue.replace(/\s+/g, "")
|
||||||
return !noSpaces.includes(`[${from}]`)
|
const fromNoSpaces = from.replace(/\s+/g, "")
|
||||||
|
const invalids = [
|
||||||
|
`[${fromNoSpaces}]`,
|
||||||
|
`"${fromNoSpaces}"`,
|
||||||
|
`'${fromNoSpaces}'`,
|
||||||
|
]
|
||||||
|
return !invalids.find(invalid => noSpaces.includes(invalid))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
import { Button, Input, Select, Label } from "@budibase/bbui"
|
import { Button, Input, Select, Label } from "@budibase/bbui"
|
||||||
import { automationStore } from "builderStore"
|
import { automationStore } from "builderStore"
|
||||||
import WebhookDisplay from "../Shared/WebhookDisplay.svelte"
|
import WebhookDisplay from "../Shared/WebhookDisplay.svelte"
|
||||||
import DrawerBindableInput from "../../common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "../../common/bindings/DrawerBindableInput.svelte"
|
||||||
import AutomationBindingPanel from "../../common/ServerBindingPanel.svelte"
|
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
|
||||||
|
|
||||||
export let block
|
export let block
|
||||||
export let webhookModal
|
export let webhookModal
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<script>
|
<script>
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
import { Select } from "@budibase/bbui"
|
import { Select } from "@budibase/bbui"
|
||||||
import DrawerBindableInput from "../../common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "../../common/bindings/DrawerBindableInput.svelte"
|
||||||
import AutomationBindingPanel from "../../common/ServerBindingPanel.svelte"
|
import AutomationBindingPanel from "../../common/bindings/ServerBindingPanel.svelte"
|
||||||
|
|
||||||
export let value
|
export let value
|
||||||
export let bindings
|
export let bindings
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
import DatePicker from "components/common/DatePicker.svelte"
|
import DatePicker from "components/common/DatePicker.svelte"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { truncate } from "lodash"
|
import { truncate } from "lodash"
|
||||||
import ModalBindableInput from "components/common/ModalBindableInput.svelte"
|
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
||||||
import { getBindings } from "components/backend/DataTable/formula"
|
import { getBindings } from "components/backend/DataTable/formula"
|
||||||
|
|
||||||
const AUTO_TYPE = "auto"
|
const AUTO_TYPE = "auto"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import { currentAsset, store } from "../../../builderStore"
|
import { currentAsset, store } from "../../../builderStore"
|
||||||
import { handlebarsCompletions } from "constants/completions"
|
import { handlebarsCompletions } from "constants/completions"
|
||||||
|
import { addToText } from "./utils"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -37,20 +38,6 @@
|
||||||
valid = isValid(runtimeBinding)
|
valid = isValid(runtimeBinding)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToText(readableBinding) {
|
|
||||||
const position = getCaretPosition()
|
|
||||||
const toAdd = `{{ ${readableBinding} }}`
|
|
||||||
|
|
||||||
if (position.start) {
|
|
||||||
value =
|
|
||||||
value.substring(0, position.start) +
|
|
||||||
toAdd +
|
|
||||||
value.substring(position.end, value.length)
|
|
||||||
} else {
|
|
||||||
value = toAdd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function cancel() {
|
export function cancel() {
|
||||||
dispatch("update", originalValue)
|
dispatch("update", originalValue)
|
||||||
bindingDrawer.close()
|
bindingDrawer.close()
|
||||||
|
@ -69,7 +56,10 @@
|
||||||
{#each context.filter(context =>
|
{#each context.filter(context =>
|
||||||
context.readableBinding.match(searchRgx)
|
context.readableBinding.match(searchRgx)
|
||||||
) as { readableBinding }}
|
) as { readableBinding }}
|
||||||
<li on:click={() => addToText(readableBinding)}>
|
<li
|
||||||
|
on:click={() => {
|
||||||
|
value = addToText(value, getCaretPosition(), readableBinding)
|
||||||
|
}}>
|
||||||
{readableBinding}
|
{readableBinding}
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -83,7 +73,10 @@
|
||||||
{#each instance.filter(instance =>
|
{#each instance.filter(instance =>
|
||||||
instance.readableBinding.match(searchRgx)
|
instance.readableBinding.match(searchRgx)
|
||||||
) as { readableBinding }}
|
) as { readableBinding }}
|
||||||
<li on:click={() => addToText(readableBinding)}>
|
<li
|
||||||
|
on:click={() => {
|
||||||
|
value = addToText(value, getCaretPosition(), readableBinding)
|
||||||
|
}}>
|
||||||
{readableBinding}
|
{readableBinding}
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -94,7 +87,10 @@
|
||||||
<Spacer small />
|
<Spacer small />
|
||||||
<ul>
|
<ul>
|
||||||
{#each helpers.filter(helper => helper.label.match(searchRgx) || helper.description.match(searchRgx)) as helper}
|
{#each helpers.filter(helper => helper.label.match(searchRgx) || helper.description.match(searchRgx)) as helper}
|
||||||
<li on:click={() => addToText(helper.text)}>
|
<li
|
||||||
|
on:click={() => {
|
||||||
|
value = addToText(value, getCaretPosition(), helper.text)
|
||||||
|
}}>
|
||||||
<div>
|
<div>
|
||||||
<Label extraSmall>{helper.displayText}</Label>
|
<Label extraSmall>{helper.displayText}</Label>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
|
@ -152,7 +148,6 @@
|
||||||
}
|
}
|
||||||
ul {
|
ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding-left: 0;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
|
@ -4,8 +4,8 @@
|
||||||
readableToRuntimeBinding,
|
readableToRuntimeBinding,
|
||||||
runtimeToReadableBinding,
|
runtimeToReadableBinding,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import BindingPanel from "components/design/PropertiesPanel/BindingPanel.svelte"
|
import BindingPanel from "components/common/bindings/BindingPanel.svelte"
|
||||||
import ServerBindingPanel from "components/common/ServerBindingPanel.svelte"
|
import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
readableToRuntimeBinding,
|
readableToRuntimeBinding,
|
||||||
runtimeToReadableBinding,
|
runtimeToReadableBinding,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import ServerBindingPanel from "components/common/ServerBindingPanel.svelte"
|
import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { isValid } from "@budibase/string-templates"
|
import { isValid } from "@budibase/string-templates"
|
||||||
import { handlebarsCompletions } from "constants/completions"
|
import { handlebarsCompletions } from "constants/completions"
|
||||||
import { readableToRuntimeBinding } from "../../builderStore/dataBinding"
|
import { readableToRuntimeBinding } from "../../../builderStore/dataBinding"
|
||||||
|
import { addToText } from "./utils"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
@ -26,24 +27,14 @@
|
||||||
|
|
||||||
function checkValid() {
|
function checkValid() {
|
||||||
if (hasReadable) {
|
if (hasReadable) {
|
||||||
validity = isValid(readableToRuntimeBinding(bindableProperties, value))
|
const runtime = readableToRuntimeBinding(bindableProperties, value)
|
||||||
|
console.log(runtime)
|
||||||
|
validity = isValid(runtime)
|
||||||
} else {
|
} else {
|
||||||
validity = isValid(value)
|
validity = isValid(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToText(binding) {
|
|
||||||
const position = getCaretPosition()
|
|
||||||
const toAdd = `{{ ${binding.path} }}`
|
|
||||||
if (position.start) {
|
|
||||||
value =
|
|
||||||
value.substring(0, position.start) +
|
|
||||||
toAdd +
|
|
||||||
value.substring(position.end, value.length)
|
|
||||||
} else {
|
|
||||||
value += toAdd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export function cancel() {
|
export function cancel() {
|
||||||
dispatch("update", originalValue)
|
dispatch("update", originalValue)
|
||||||
if (bindingContainer && bindingContainer.close) {
|
if (bindingContainer && bindingContainer.close) {
|
||||||
|
@ -64,7 +55,11 @@
|
||||||
{#each bindings.filter(binding =>
|
{#each bindings.filter(binding =>
|
||||||
binding.label.match(searchRgx)
|
binding.label.match(searchRgx)
|
||||||
) as binding}
|
) as binding}
|
||||||
<div class="binding" on:click={() => addToText(binding)}>
|
<div
|
||||||
|
class="binding"
|
||||||
|
on:click={() => {
|
||||||
|
value = addToText(value, getCaretPosition(), binding)
|
||||||
|
}}>
|
||||||
<span class="binding__label">{binding.label}</span>
|
<span class="binding__label">{binding.label}</span>
|
||||||
<span class="binding__type">{binding.type}</span>
|
<span class="binding__type">{binding.type}</span>
|
||||||
<br />
|
<br />
|
||||||
|
@ -77,7 +72,11 @@
|
||||||
<Heading extraSmall>Helpers</Heading>
|
<Heading extraSmall>Helpers</Heading>
|
||||||
<Spacer extraSmall />
|
<Spacer extraSmall />
|
||||||
{#each helpers.filter(helper => helper.label.match(searchRgx) || helper.description.match(searchRgx)) as helper}
|
{#each helpers.filter(helper => helper.label.match(searchRgx) || helper.description.match(searchRgx)) as helper}
|
||||||
<div class="binding" on:click={() => addToText(helper)}>
|
<div
|
||||||
|
class="binding"
|
||||||
|
on:click={() => {
|
||||||
|
value = addToText(value, getCaretPosition(), helper)
|
||||||
|
}}>
|
||||||
<span class="binding__label">{helper.label}</span>
|
<span class="binding__label">{helper.label}</span>
|
||||||
<br />
|
<br />
|
||||||
<div class="binding__description">
|
<div class="binding__description">
|
|
@ -0,0 +1,15 @@
|
||||||
|
export function addToText(value, caretPos, binding) {
|
||||||
|
let toAdd = binding.path
|
||||||
|
if (!value.includes("{{") && !value.includes("}}")) {
|
||||||
|
toAdd = `{{ ${binding.path} }}`
|
||||||
|
}
|
||||||
|
if (caretPos.start) {
|
||||||
|
value =
|
||||||
|
value.substring(0, caretPos.start) +
|
||||||
|
toAdd +
|
||||||
|
value.substring(caretPos.end, value.length)
|
||||||
|
} else {
|
||||||
|
value += toAdd
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
import { store, currentAsset } from "builderStore"
|
import { store, currentAsset } from "builderStore"
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
import { getBindableProperties } from "builderStore/dataBinding"
|
import { getBindableProperties } from "builderStore/dataBinding"
|
||||||
import DrawerBindableInput from "components/common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
export let parameters
|
export let parameters
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { Label } from "@budibase/bbui"
|
import { Label } from "@budibase/bbui"
|
||||||
import { getBindableProperties } from "builderStore/dataBinding"
|
import { getBindableProperties } from "builderStore/dataBinding"
|
||||||
import { currentAsset, store } from "builderStore"
|
import { currentAsset, store } from "builderStore"
|
||||||
import DrawerBindableInput from "components/common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
export let parameters
|
export let parameters
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { Label } from "@budibase/bbui"
|
import { Label } from "@budibase/bbui"
|
||||||
import { getBindableProperties } from "builderStore/dataBinding"
|
import { getBindableProperties } from "builderStore/dataBinding"
|
||||||
import { currentAsset, store } from "builderStore"
|
import { currentAsset, store } from "builderStore"
|
||||||
import DrawerBindableInput from "components/common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
export let parameters
|
export let parameters
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { getBindableProperties } from "builderStore/dataBinding"
|
import { getBindableProperties } from "builderStore/dataBinding"
|
||||||
import { CloseCircleIcon, AddIcon } from "components/common/Icons"
|
import { CloseCircleIcon, AddIcon } from "components/common/Icons"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import DrawerBindableInput from "components/common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
readableToRuntimeBinding,
|
readableToRuntimeBinding,
|
||||||
runtimeToReadableBinding,
|
runtimeToReadableBinding,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import BindingPanel from "components/design/PropertiesPanel/BindingPanel.svelte"
|
import BindingPanel from "components/common/bindings/BindingPanel.svelte"
|
||||||
import { capitalise } from "../../../../helpers"
|
import { capitalise } from "../../../../helpers"
|
||||||
|
|
||||||
export let label = ""
|
export let label = ""
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
readableToRuntimeBinding,
|
readableToRuntimeBinding,
|
||||||
runtimeToReadableBinding,
|
runtimeToReadableBinding,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import DrawerBindableInput from "components/common/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
|
|
||||||
export let bindable = true
|
export let bindable = true
|
||||||
export let parameters = []
|
export let parameters = []
|
||||||
|
|
|
@ -273,6 +273,19 @@ describe("test the comparison helpers", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("Test the object/array helper", () => {
|
||||||
|
it("should allow plucking from an array of objects", async () => {
|
||||||
|
const context = {
|
||||||
|
items: [
|
||||||
|
{ price: 20 },
|
||||||
|
{ price: 30 },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
const output = await processString("{{ sum ( pluck items 'price' ) }}", context)
|
||||||
|
expect(output).toBe(50)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("Test the literal helper", () => {
|
describe("Test the literal helper", () => {
|
||||||
it("should allow use of the literal specifier for a number", async () => {
|
it("should allow use of the literal specifier for a number", async () => {
|
||||||
const output = await processString(`{{literal a}}`, {
|
const output = await processString(`{{literal a}}`, {
|
||||||
|
|
Loading…
Reference in New Issue