Merge pull request #7790 from Budibase/fix/user-bindings-datasource-queries
Expose current user bindings in datasource query UI
This commit is contained in:
commit
165ba4973f
|
@ -78,7 +78,7 @@
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
background: var(--background);
|
background: var(--background);
|
||||||
border-top: var(--border-light);
|
border-top: var(--border-light);
|
||||||
z-index: 2;
|
z-index: 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fillWidth {
|
.fillWidth {
|
||||||
|
|
|
@ -370,7 +370,7 @@ const getProviderContextBindings = (asset, dataProviders) => {
|
||||||
/**
|
/**
|
||||||
* Gets all bindable properties from the logged in user.
|
* Gets all bindable properties from the logged in user.
|
||||||
*/
|
*/
|
||||||
const getUserBindings = () => {
|
export const getUserBindings = () => {
|
||||||
let bindings = []
|
let bindings = []
|
||||||
const { schema } = getSchemaForTable(TableNames.USERS)
|
const { schema } = getSchemaForTable(TableNames.USERS)
|
||||||
const keys = Object.keys(schema).sort()
|
const keys = Object.keys(schema).sort()
|
||||||
|
|
|
@ -1,31 +1,20 @@
|
||||||
<script>
|
<script>
|
||||||
import { Body, Button, Heading, Icon, Input, Layout } from "@budibase/bbui"
|
import { Body, Button, Heading, Layout } from "@budibase/bbui"
|
||||||
import {
|
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
|
||||||
readableToRuntimeBinding,
|
import { getUserBindings } from "builderStore/dataBinding"
|
||||||
runtimeToReadableBinding,
|
|
||||||
} from "builderStore/dataBinding"
|
|
||||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
|
||||||
|
|
||||||
export let bindable = true
|
export let bindable = true
|
||||||
export let queryBindings = []
|
export let queryBindings = []
|
||||||
export let bindings = []
|
|
||||||
export let customParams = {}
|
const userBindings = getUserBindings()
|
||||||
|
|
||||||
|
let internalBindings = queryBindings.reduce((acc, binding) => {
|
||||||
|
acc[binding.name] = binding.default
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
function newQueryBinding() {
|
function newQueryBinding() {
|
||||||
queryBindings = [...queryBindings, {}]
|
queryBindings = [...queryBindings, {}]
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteQueryBinding(idx) {
|
|
||||||
queryBindings.splice(idx, 1)
|
|
||||||
queryBindings = queryBindings
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
function onBindingChange(param, valueToParse) {
|
|
||||||
customParams[param] = readableToRuntimeBinding(bindings, valueToParse)
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Layout noPadding={bindable} gap="S">
|
<Layout noPadding={bindable} gap="S">
|
||||||
|
@ -46,57 +35,34 @@
|
||||||
{/if}
|
{/if}
|
||||||
</Body>
|
</Body>
|
||||||
<div class="bindings" class:bindable>
|
<div class="bindings" class:bindable>
|
||||||
{#each queryBindings as binding, idx}
|
<KeyValueBuilder
|
||||||
<Input
|
bind:object={internalBindings}
|
||||||
placeholder="Binding Name"
|
tooltip="Set the name of the binding which can be used in Handlebars statements throughout your query"
|
||||||
thin
|
name="binding"
|
||||||
disabled={bindable}
|
headings
|
||||||
bind:value={binding.name}
|
keyPlaceholder="Binding name"
|
||||||
/>
|
valuePlaceholder="Default"
|
||||||
<Input
|
bindings={[...userBindings]}
|
||||||
placeholder="Default"
|
bindingDrawerLeft="260px"
|
||||||
thin
|
on:change={e => {
|
||||||
disabled={bindable}
|
queryBindings = e.detail.map(binding => {
|
||||||
on:change={evt => onBindingChange(binding.name, evt.detail)}
|
return {
|
||||||
bind:value={binding.default}
|
name: binding.name,
|
||||||
/>
|
default: binding.value,
|
||||||
{#if bindable}
|
}
|
||||||
<DrawerBindableInput
|
})
|
||||||
title={`Query binding "${binding.name}"`}
|
}}
|
||||||
placeholder="Value"
|
/>
|
||||||
thin
|
|
||||||
on:change={evt => onBindingChange(binding.name, evt.detail)}
|
|
||||||
value={runtimeToReadableBinding(
|
|
||||||
bindings,
|
|
||||||
customParams?.[binding.name]
|
|
||||||
)}
|
|
||||||
{bindings}
|
|
||||||
/>
|
|
||||||
{:else}
|
|
||||||
<Icon hoverable name="Close" on:click={() => deleteQueryBinding(idx)} />
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.bindings.bindable {
|
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.controls {
|
.controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bindings {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr 5%;
|
|
||||||
grid-gap: 10px;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.height {
|
.height {
|
||||||
height: 40px;
|
height: 40px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue