2020-06-01 23:55:44 +02:00
|
|
|
<script>
|
|
|
|
import { backendUiStore } from "builderStore"
|
2020-09-16 15:38:18 +02:00
|
|
|
import { Input, Select, Label } from "@budibase/bbui"
|
2020-10-26 13:18:34 +01:00
|
|
|
import BindableInput from "../../userInterface/BindableInput.svelte"
|
2020-06-01 23:55:44 +02:00
|
|
|
|
|
|
|
export let value
|
2020-09-17 15:05:53 +02:00
|
|
|
export let bindings
|
|
|
|
|
2020-10-27 16:28:13 +01:00
|
|
|
$: table = $backendUiStore.tables.find(table => table._id === value?.tableId)
|
2020-10-09 19:49:23 +02:00
|
|
|
$: schemaFields = Object.entries(table?.schema ?? {})
|
2020-09-03 13:02:15 +02:00
|
|
|
|
2020-10-09 19:49:23 +02:00
|
|
|
// Ensure any nullish tableId values get set to empty string so
|
2020-09-17 14:44:18 +02:00
|
|
|
// that the select works
|
2020-10-09 19:49:23 +02:00
|
|
|
$: if (value?.tableId == null) value = { tableId: "" }
|
2020-09-21 17:45:55 +02:00
|
|
|
|
|
|
|
function schemaHasOptions(schema) {
|
|
|
|
return !!schema.constraints?.inclusion?.length
|
|
|
|
}
|
2020-06-01 23:55:44 +02:00
|
|
|
</script>
|
|
|
|
|
2020-09-10 08:46:01 +02:00
|
|
|
<div class="block-field">
|
2020-10-26 13:18:34 +01:00
|
|
|
<Select bind:value={value.tableId} extraThin secondary>
|
2020-09-11 22:14:58 +02:00
|
|
|
<option value="">Choose an option</option>
|
2020-10-09 19:49:23 +02:00
|
|
|
{#each $backendUiStore.tables as table}
|
|
|
|
<option value={table._id}>{table.name}</option>
|
2020-08-30 15:49:25 +02:00
|
|
|
{/each}
|
2020-09-16 15:38:18 +02:00
|
|
|
</Select>
|
2020-06-01 23:55:44 +02:00
|
|
|
</div>
|
|
|
|
|
2020-09-14 12:51:52 +02:00
|
|
|
{#if schemaFields.length}
|
2020-09-25 16:01:48 +02:00
|
|
|
<div class="schema-fields">
|
2020-09-16 15:38:18 +02:00
|
|
|
{#each schemaFields as [field, schema]}
|
2020-09-30 10:28:18 +02:00
|
|
|
{#if schemaHasOptions(schema)}
|
2020-10-26 13:18:34 +01:00
|
|
|
<Select label={field} extraThin secondary bind:value={value[field]}>
|
2020-09-30 10:28:18 +02:00
|
|
|
<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
|
2020-10-26 13:18:34 +01:00
|
|
|
extraThin
|
2020-09-30 10:28:18 +02:00
|
|
|
bind:value={value[field]}
|
|
|
|
label={field}
|
|
|
|
type="string"
|
|
|
|
{bindings} />
|
|
|
|
{/if}
|
2020-06-01 23:55:44 +02:00
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
2020-09-16 14:55:28 +02:00
|
|
|
|
|
|
|
<style>
|
2020-09-25 16:01:48 +02:00
|
|
|
.schema-fields {
|
|
|
|
display: grid;
|
|
|
|
grid-gap: var(--spacing-xl);
|
|
|
|
margin-top: var(--spacing-xl);
|
|
|
|
}
|
2020-09-30 10:28:18 +02:00
|
|
|
.schema-fields :global(label) {
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
2020-09-16 14:55:28 +02:00
|
|
|
</style>
|