1
0
Fork 0
mirror of synced 2024-09-21 11:53:49 +12:00
budibase/packages/builder/src/components/integration/QueryFieldsBuilder.svelte

72 lines
1.7 KiB
Svelte
Raw Normal View History

2021-01-14 03:11:53 +13:00
<script>
import {
Button,
TextArea,
Label,
Input,
Heading,
Spacer,
Select
} from "@budibase/bbui"
export let fields = {}
export let schema
2021-01-15 03:22:24 +13:00
export let editable
2021-01-14 03:11:53 +13:00
let customSchema = {}
let draftField = {}
function addField() {
// Add the new field to custom fields for the query
customSchema[draftField.name] = {
type: draftField.type
}
// reset the draft field
draftField = {}
}
</script>
<form on:submit|preventDefault>
{#each Object.keys(schema.fields) as field}
<Label extraSmall grey>{field}</Label>
<Input
2021-01-15 03:22:24 +13:00
disabled={!editable}
2021-01-14 03:11:53 +13:00
type={schema.fields[field]?.type}
required={schema.fields[field]?.required}
bind:value={fields[field]} />
<Spacer medium />
{/each}
2021-01-15 03:22:24 +13:00
{#if schema.customisable && editable}
2021-01-14 05:39:47 +13:00
<Spacer large />
2021-01-14 03:11:53 +13:00
<Label>Add Custom Field</Label>
{#each Object.keys(customSchema) as field}
<Label extraSmall grey>{field}</Label>
<Input
thin
type={customSchema[field]?.type}
bind:value={fields[field]}
/>
<Spacer medium />
{/each}
<div class="new-field">
<Label extraSmall grey>Name</Label>
<Label extraSmall grey>Type</Label>
<Input thin bind:value={draftField.name} />
<Select thin secondary bind:value={draftField.name}>
<option value={"text"}>String</option>
<option value={"number"}>Number</option>
</Select>
</div>
2021-01-14 05:39:47 +13:00
<Button small thin secondary on:click={addField}>Add Field</Button>
2021-01-14 03:11:53 +13:00
{/if}
</form>
<style>
.new-field {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: var(--spacing-m);
margin-top: var(--spacing-m);
margin-bottom: var(--spacing-m);
}
</style>