1
0
Fork 0
mirror of synced 2024-08-25 15:01:31 +12:00
budibase/packages/builder/src/components/automation/SetupPanel/RowSelector.svelte

62 lines
1.7 KiB
Svelte
Raw Normal View History

2020-06-02 09:55:44 +12:00
<script>
import { backendUiStore } from "builderStore"
import { Select } from "@budibase/bbui"
2021-01-21 02:20:08 +13:00
import BindableInput from "../../common/BindableInput.svelte"
2020-06-02 09:55:44 +12:00
export let value
export let bindings
2020-10-28 04:28:13 +13:00
$: table = $backendUiStore.tables.find(table => table._id === value?.tableId)
$: schemaFields = Object.entries(table?.schema ?? {})
// Ensure any nullish tableId values get set to empty string so
2020-09-18 00:44:18 +12:00
// that the select works
$: if (value?.tableId == null) value = { tableId: "" }
2020-09-22 03:45:55 +12:00
function schemaHasOptions(schema) {
return !!schema.constraints?.inclusion?.length
}
2020-06-02 09:55:44 +12:00
</script>
<div class="block-field">
<Select bind:value={value.tableId} extraThin secondary>
<option value="">Choose an option</option>
{#each $backendUiStore.tables as table}
<option value={table._id}>{table.name}</option>
{/each}
</Select>
2020-06-02 09:55:44 +12:00
</div>
{#if schemaFields.length}
<div class="schema-fields">
{#each schemaFields as [field, schema]}
{#if schemaHasOptions(schema)}
<Select label={field} extraThin secondary bind:value={value[field]}>
<option value="">Choose an option</option>
{#each schema.constraints.inclusion as option}
<option value={option}>{option}</option>
{/each}
</Select>
{:else if schema.type === 'string' || schema.type === 'number'}
<BindableInput
extraThin
bind:value={value[field]}
label={field}
type="string"
{bindings} />
{/if}
2020-06-02 09:55:44 +12:00
{/each}
</div>
{/if}
<style>
.schema-fields {
display: grid;
grid-gap: var(--spacing-xl);
margin-top: var(--spacing-xl);
}
.schema-fields :global(label) {
text-transform: capitalize;
}
</style>