1
0
Fork 0
mirror of synced 2024-09-13 07:53:31 +12:00
budibase/packages/builder/src/components/integration/QueryBindingBuilder.svelte

106 lines
2.7 KiB
Svelte
Raw Normal View History

<script>
import { Body, Button, Heading, Icon, Input, Layout } from "@budibase/bbui"
2021-01-12 23:28:41 +13:00
import {
readableToRuntimeBinding,
runtimeToReadableBinding,
2021-01-21 02:20:08 +13:00
} from "builderStore/dataBinding"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
2021-01-12 09:17:56 +13:00
export let bindable = true
export let bindings = []
export let bindableOptions = []
export let customParams = {}
function newQueryBinding() {
bindings = [...bindings, {}]
}
function deleteQueryBinding(idx) {
bindings.splice(idx, 1)
bindings = bindings
}
2021-01-12 23:28:41 +13:00
2021-01-13 05:49:11 +13:00
// This is necessary due to the way readable and writable bindings are stored.
// The readable binding in the UI gets converted to a UUID value that the client understands
// for parsing, then converted back so we can display it the readable form in the UI
2021-01-12 23:28:41 +13:00
function onBindingChange(param, valueToParse) {
customParams[param] = readableToRuntimeBinding(
bindableOptions,
valueToParse
)
2021-01-12 23:28:41 +13:00
}
</script>
<Layout noPadding={bindable} gap="S">
<div class="controls" class:height={!bindable}>
<Heading size="XS">Bindings</Heading>
{#if !bindable}
<Button secondary on:click={newQueryBinding}>Add Binding</Button>
{/if}
</div>
<Body size="S">
{#if !bindable}
Bindings come in two parts: the binding name, and a default/fallback
value. These bindings can be used as Handlebars expressions throughout the
query.
{:else}
Enter a value for each binding. The default values will be used for any
values left blank.
{/if}
</Body>
<div class="bindings" class:bindable>
{#each bindings as binding, idx}
<Input
placeholder="Binding Name"
thin
disabled={bindable}
bind:value={binding.name}
/>
<Input
placeholder="Default"
thin
disabled={bindable}
bind:value={binding.default}
/>
2021-01-12 09:17:56 +13:00
{#if bindable}
<DrawerBindableInput
title={`Query binding "${binding.name}"`}
placeholder="Value"
2021-01-12 09:17:56 +13:00
thin
on:change={evt => onBindingChange(binding.name, evt.detail)}
value={runtimeToReadableBinding(
bindableOptions,
customParams?.[binding.name]
)}
{bindableOptions}
/>
2021-01-13 05:49:11 +13:00
{:else}
<Icon hoverable name="Close" on:click={() => deleteQueryBinding(idx)} />
2021-01-12 09:17:56 +13:00
{/if}
2021-01-09 07:22:03 +13:00
{/each}
</div>
2021-04-29 01:40:15 +12:00
</Layout>
<style>
.bindings.bindable {
2021-01-13 05:49:11 +13:00
grid-template-columns: 1fr 1fr 1fr;
2021-01-12 09:17:56 +13:00
}
.controls {
display: flex;
2021-02-19 07:55:08 +13:00
align-items: center;
justify-content: space-between;
}
.bindings {
display: grid;
2021-01-12 09:17:56 +13:00
grid-template-columns: 1fr 1fr 5%;
grid-gap: 10px;
align-items: center;
2021-01-13 05:49:11 +13:00
}
.height {
height: 40px;
}
</style>