2021-01-08 13:06:37 +01:00
|
|
|
<script>
|
2021-04-28 15:40:15 +02:00
|
|
|
import { Icon, Body, Button, Input, Heading, 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-02-18 18:44:56 +01:00
|
|
|
import DrawerBindableInput from "components/common/DrawerBindableInput.svelte"
|
2021-01-08 13:06:37 +01:00
|
|
|
|
2021-01-11 21:17:56 +01:00
|
|
|
export let bindable = true
|
2021-01-08 13:06:37 +01:00
|
|
|
export let parameters = []
|
|
|
|
export let bindings = []
|
|
|
|
export let customParams = {}
|
|
|
|
|
|
|
|
function newQueryParameter() {
|
|
|
|
parameters = [...parameters, {}]
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteQueryParameter(idx) {
|
|
|
|
parameters.splice(idx, 1)
|
|
|
|
parameters = parameters
|
|
|
|
}
|
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) {
|
|
|
|
const parsedBindingValue = readableToRuntimeBinding(bindings, valueToParse)
|
|
|
|
customParams[param] = parsedBindingValue
|
|
|
|
}
|
2021-01-08 13:06:37 +01:00
|
|
|
</script>
|
|
|
|
|
2021-04-28 15:40:15 +02:00
|
|
|
<Layout paddingX="none" gap="S">
|
2021-02-18 17:58:10 +01:00
|
|
|
<div class="controls">
|
2021-04-23 12:55:36 +02:00
|
|
|
<Heading s>Parameters</Heading>
|
2021-02-18 17:58:10 +01:00
|
|
|
{#if !bindable}
|
2021-04-20 12:53:19 +02:00
|
|
|
<Button secondary on:click={newQueryParameter}>Add Param</Button>
|
2021-02-18 17:58:10 +01:00
|
|
|
{/if}
|
|
|
|
</div>
|
2021-04-23 12:55:36 +02:00
|
|
|
<Body s>
|
2021-02-22 13:23:46 +01:00
|
|
|
{#if !bindable}
|
|
|
|
Parameters come in two parts: the parameter name, and a default/fallback
|
|
|
|
value.
|
|
|
|
{:else}
|
|
|
|
Enter a value for each parameter. The default values will be used for any
|
|
|
|
values left blank.
|
|
|
|
{/if}
|
2021-02-18 17:58:10 +01:00
|
|
|
</Body>
|
2021-01-11 21:17:56 +01:00
|
|
|
<div class="parameters" class:bindable>
|
2021-01-08 19:22:03 +01:00
|
|
|
{#each parameters as parameter, idx}
|
2021-01-22 17:49:22 +01:00
|
|
|
<Input
|
|
|
|
placeholder="Parameter Name"
|
|
|
|
thin
|
|
|
|
disabled={bindable}
|
2021-04-27 15:26:03 +02:00
|
|
|
bind:value={parameter.name}
|
|
|
|
/>
|
2021-01-22 17:49:22 +01:00
|
|
|
<Input
|
|
|
|
placeholder="Default"
|
|
|
|
thin
|
|
|
|
disabled={bindable}
|
2021-04-27 15:26:03 +02:00
|
|
|
bind:value={parameter.default}
|
|
|
|
/>
|
2021-01-11 21:17:56 +01:00
|
|
|
{#if bindable}
|
2021-02-18 18:44:56 +01:00
|
|
|
<DrawerBindableInput
|
|
|
|
title={`Query parameter "${parameter.name}"`}
|
2021-01-22 17:49:22 +01:00
|
|
|
placeholder="Value"
|
2021-01-11 21:17:56 +01:00
|
|
|
thin
|
2021-04-27 15:26:03 +02:00
|
|
|
on:change={(evt) => onBindingChange(parameter.name, evt.detail)}
|
|
|
|
value={runtimeToReadableBinding(
|
|
|
|
bindings,
|
|
|
|
customParams?.[parameter.name]
|
|
|
|
)}
|
|
|
|
{bindings}
|
|
|
|
/>
|
2021-01-12 17:49:11 +01:00
|
|
|
{:else}
|
2021-04-27 15:26:03 +02:00
|
|
|
<Icon
|
|
|
|
hoverable
|
|
|
|
name="Close"
|
|
|
|
on:click={() => deleteQueryParameter(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-01-11 21:17:56 +01:00
|
|
|
.parameters.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-02-19 15:31:07 +01:00
|
|
|
height: 40px;
|
2021-02-18 17:58:10 +01:00
|
|
|
}
|
|
|
|
|
2021-01-08 13:06:37 +01:00
|
|
|
.parameters {
|
|
|
|
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-01-08 13:06:37 +01:00
|
|
|
</style>
|