2021-01-08 13:06:37 +01:00
|
|
|
<script>
|
2021-01-20 14:20:08 +01:00
|
|
|
import { Button, Label, Input, Heading } from "@budibase/bbui"
|
|
|
|
import BindableInput from "components/common/BindableInput.svelte"
|
2021-01-12 11:28:41 +01:00
|
|
|
import {
|
|
|
|
readableToRuntimeBinding,
|
|
|
|
runtimeToReadableBinding,
|
2021-01-20 14:20:08 +01:00
|
|
|
} from "builderStore/dataBinding"
|
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-01-08 19:22:03 +01:00
|
|
|
<section>
|
|
|
|
<Heading extraSmall black>Parameters</Heading>
|
2021-01-11 21:17:56 +01:00
|
|
|
<div class="parameters" class:bindable>
|
2021-01-08 19:22:03 +01:00
|
|
|
<Label extraSmall grey>Parameter Name</Label>
|
|
|
|
<Label extraSmall grey>Default</Label>
|
2021-01-11 21:17:56 +01:00
|
|
|
{#if bindable}
|
|
|
|
<Label extraSmall grey>Value</Label>
|
2021-01-12 17:49:11 +01:00
|
|
|
{:else}
|
|
|
|
<div />
|
2021-01-11 21:17:56 +01:00
|
|
|
{/if}
|
2021-01-08 19:22:03 +01:00
|
|
|
{#each parameters as parameter, idx}
|
2021-01-14 15:22:24 +01:00
|
|
|
<Input thin disabled={bindable} bind:value={parameter.name} />
|
|
|
|
<Input thin disabled={bindable} bind:value={parameter.default} />
|
2021-01-11 21:17:56 +01:00
|
|
|
{#if bindable}
|
|
|
|
<BindableInput
|
|
|
|
type="string"
|
|
|
|
thin
|
2021-01-12 17:49:11 +01:00
|
|
|
on:change={evt => onBindingChange(parameter.name, evt.detail)}
|
2021-01-12 11:28:41 +01:00
|
|
|
value={runtimeToReadableBinding(bindings, customParams[parameter.name])}
|
2021-01-11 21:17:56 +01:00
|
|
|
{bindings} />
|
2021-01-12 17:49:11 +01:00
|
|
|
{:else}
|
|
|
|
<i
|
|
|
|
class="ri-close-circle-line delete"
|
|
|
|
on:click={() => deleteQueryParameter(idx)} />
|
2021-01-11 21:17:56 +01:00
|
|
|
{/if}
|
2021-01-08 19:22:03 +01:00
|
|
|
{/each}
|
|
|
|
</div>
|
2021-01-12 17:49:11 +01:00
|
|
|
{#if !bindable}
|
|
|
|
<Button thin secondary small on:click={newQueryParameter}>
|
|
|
|
Add Parameter
|
|
|
|
</Button>
|
|
|
|
{/if}
|
2021-01-08 19:22:03 +01:00
|
|
|
</section>
|
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-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-08 19:22:03 +01:00
|
|
|
margin-bottom: var(--spacing-xl);
|
2021-01-08 13:06:37 +01:00
|
|
|
}
|
2021-01-12 17:49:11 +01:00
|
|
|
|
|
|
|
.delete {
|
|
|
|
transition: all 0.2s;
|
|
|
|
}
|
|
|
|
|
|
|
|
.delete:hover {
|
|
|
|
transform: scale(1.1);
|
|
|
|
font-weight: 500;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2021-01-08 13:06:37 +01:00
|
|
|
</style>
|