2021-01-08 13:06:37 +01:00
|
|
|
<script>
|
2021-12-08 18:58:30 +01:00
|
|
|
import { Body, Button, Heading, Icon, Input, Layout } from "@budibase/bbui"
|
2021-01-12 11:28:41 +01:00
|
|
|
import {
|
|
|
|
readableToRuntimeBinding,
|
|
|
|
runtimeToReadableBinding,
|
2021-01-20 14:20:08 +01:00
|
|
|
} from "builderStore/dataBinding"
|
2021-04-30 17:17:57 +02:00
|
|
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
2021-01-08 13:06:37 +01:00
|
|
|
|
2021-01-11 21:17:56 +01:00
|
|
|
export let bindable = true
|
2022-01-20 17:12:32 +01:00
|
|
|
export let queryBindings = []
|
2021-01-08 13:06:37 +01:00
|
|
|
export let bindings = []
|
|
|
|
export let customParams = {}
|
|
|
|
|
2021-12-08 18:58:30 +01:00
|
|
|
function newQueryBinding() {
|
2022-01-20 17:12:32 +01:00
|
|
|
queryBindings = [...queryBindings, {}]
|
2021-01-08 13:06:37 +01:00
|
|
|
}
|
|
|
|
|
2021-12-08 18:58:30 +01:00
|
|
|
function deleteQueryBinding(idx) {
|
2022-01-20 17:12:32 +01:00
|
|
|
queryBindings.splice(idx, 1)
|
|
|
|
queryBindings = queryBindings
|
2021-01-08 13:06:37 +01:00
|
|
|
}
|
2021-01-12 11:28:41 +01:00
|
|
|
|
2021-01-12 17:49:11 +01: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 11:28:41 +01:00
|
|
|
function onBindingChange(param, valueToParse) {
|
2022-01-20 17:12:32 +01:00
|
|
|
customParams[param] = readableToRuntimeBinding(bindings, valueToParse)
|
2021-01-12 11:28:41 +01:00
|
|
|
}
|
2021-01-08 13:06:37 +01:00
|
|
|
</script>
|
|
|
|
|
2021-12-08 18:58:30 +01:00
|
|
|
<Layout noPadding={bindable} gap="S">
|
|
|
|
<div class="controls" class:height={!bindable}>
|
|
|
|
<Heading size="XS">Bindings</Heading>
|
2021-02-18 17:58:10 +01:00
|
|
|
{#if !bindable}
|
2021-12-08 18:58:30 +01:00
|
|
|
<Button secondary on:click={newQueryBinding}>Add Binding</Button>
|
2021-02-18 17:58:10 +01:00
|
|
|
{/if}
|
|
|
|
</div>
|
2021-04-30 13:31:45 +02:00
|
|
|
<Body size="S">
|
2021-02-22 13:23:46 +01:00
|
|
|
{#if !bindable}
|
2021-12-08 18:58:30 +01:00
|
|
|
Bindings come in two parts: the binding name, and a default/fallback
|
|
|
|
value. These bindings can be used as Handlebars expressions throughout the
|
|
|
|
query.
|
2021-02-22 13:23:46 +01:00
|
|
|
{:else}
|
2021-12-08 18:58:30 +01:00
|
|
|
Enter a value for each binding. The default values will be used for any
|
2021-02-22 13:23:46 +01:00
|
|
|
values left blank.
|
|
|
|
{/if}
|
2021-02-18 17:58:10 +01:00
|
|
|
</Body>
|
2021-12-08 18:58:30 +01:00
|
|
|
<div class="bindings" class:bindable>
|
2022-01-20 17:12:32 +01:00
|
|
|
{#each queryBindings as binding, idx}
|
2021-01-22 17:49:22 +01:00
|
|
|
<Input
|
2021-12-08 18:58:30 +01:00
|
|
|
placeholder="Binding Name"
|
2021-01-22 17:49:22 +01:00
|
|
|
thin
|
|
|
|
disabled={bindable}
|
2021-12-08 18:58:30 +01:00
|
|
|
bind:value={binding.name}
|
2021-04-27 15:26:03 +02:00
|
|
|
/>
|
2021-01-22 17:49:22 +01:00
|
|
|
<Input
|
|
|
|
placeholder="Default"
|
|
|
|
thin
|
|
|
|
disabled={bindable}
|
2022-06-14 11:14:05 +02:00
|
|
|
on:change={evt => onBindingChange(binding.name, evt.detail)}
|
2022-07-18 16:58:17 +02:00
|
|
|
bind:value={binding.default}
|
2021-04-27 15:26:03 +02:00
|
|
|
/>
|
2021-01-11 21:17:56 +01:00
|
|
|
{#if bindable}
|
2021-02-18 18:44:56 +01:00
|
|
|
<DrawerBindableInput
|
2021-12-08 18:58:30 +01:00
|
|
|
title={`Query binding "${binding.name}"`}
|
2021-01-22 17:49:22 +01:00
|
|
|
placeholder="Value"
|
2021-01-11 21:17:56 +01:00
|
|
|
thin
|
2021-12-08 18:58:30 +01:00
|
|
|
on:change={evt => onBindingChange(binding.name, evt.detail)}
|
2021-04-27 15:26:03 +02:00
|
|
|
value={runtimeToReadableBinding(
|
2022-01-20 17:12:32 +01:00
|
|
|
bindings,
|
2021-12-08 18:58:30 +01:00
|
|
|
customParams?.[binding.name]
|
2021-04-27 15:26:03 +02:00
|
|
|
)}
|
2022-01-20 17:12:32 +01:00
|
|
|
{bindings}
|
2021-04-27 15:26:03 +02:00
|
|
|
/>
|
2021-01-12 17:49:11 +01:00
|
|
|
{:else}
|
2021-12-08 18:58:30 +01:00
|
|
|
<Icon hoverable name="Close" on:click={() => deleteQueryBinding(idx)} />
|
2021-01-11 21:17:56 +01:00
|
|
|
{/if}
|
2021-01-08 19:22:03 +01:00
|
|
|
{/each}
|
|
|
|
</div>
|
2021-04-28 15:40:15 +02:00
|
|
|
</Layout>
|
2021-01-08 13:06:37 +01:00
|
|
|
|
|
|
|
<style>
|
2021-12-08 18:58:30 +01:00
|
|
|
.bindings.bindable {
|
2021-01-12 17:49:11 +01:00
|
|
|
grid-template-columns: 1fr 1fr 1fr;
|
2021-01-11 21:17:56 +01:00
|
|
|
}
|
|
|
|
|
2021-02-18 17:58:10 +01:00
|
|
|
.controls {
|
|
|
|
display: flex;
|
2021-02-18 19:55:08 +01:00
|
|
|
align-items: center;
|
2021-02-18 17:58:10 +01:00
|
|
|
justify-content: space-between;
|
|
|
|
}
|
|
|
|
|
2021-12-08 18:58:30 +01:00
|
|
|
.bindings {
|
2021-01-08 13:06:37 +01:00
|
|
|
display: grid;
|
2021-01-11 21:17:56 +01:00
|
|
|
grid-template-columns: 1fr 1fr 5%;
|
2021-01-08 13:06:37 +01:00
|
|
|
grid-gap: 10px;
|
|
|
|
align-items: center;
|
2021-01-12 17:49:11 +01:00
|
|
|
}
|
2021-12-08 18:58:30 +01:00
|
|
|
|
|
|
|
.height {
|
|
|
|
height: 40px;
|
|
|
|
}
|
2021-01-08 13:06:37 +01:00
|
|
|
</style>
|