1
0
Fork 0
mirror of synced 2024-08-25 06:51:29 +12:00
budibase/packages/builder/src/components/automation/SetupPanel/ParamInputs/RecordSelector.svelte

70 lines
1.9 KiB
Svelte
Raw Normal View History

2020-06-02 09:55:44 +12:00
<script>
import { backendUiStore } from "builderStore"
import { Input, Select, Label } from "@budibase/bbui"
import BindableInput from "../../../userInterface/BindableInput.svelte"
2020-06-02 09:55:44 +12:00
export let value
export let bindings
$: model = $backendUiStore.models.find(model => model._id === value?.modelId)
$: schemaFields = Object.entries(model?.schema ?? {})
2020-09-18 00:44:18 +12:00
// Ensure any nullish modelId values get set to empty string so
// that the select works
$: if (value?.modelId == null) value = { modelId: "" }
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.modelId} thin secondary>
<option value="">Choose an option</option>
{#each $backendUiStore.models as model}
<option value={model._id}>{model.name}</option>
{/each}
</Select>
2020-06-02 09:55:44 +12:00
</div>
{#if schemaFields.length}
<div class="bb-margin-xl block-field">
{#each schemaFields as [field, schema]}
<div class="bb-margin-xl capitalise">
2020-09-22 03:45:55 +12:00
{#if schemaHasOptions(schema)}
<div class="field-label">{field}</div>
2020-09-22 03:45:55 +12:00
<Select thin secondary bind:value={value[field]}>
<option value="">Choose an option</option>
{#each schema.constraints.inclusion as option}
<option value={option}>{option}</option>
{/each}
</Select>
2020-09-22 03:45:55 +12:00
{:else if schema.type === 'string' || schema.type === 'number'}
<BindableInput
thin
bind:value={value[field]}
label={field}
type="string"
{bindings} />
{/if}
2020-06-02 09:55:44 +12:00
</div>
{/each}
</div>
{/if}
<style>
.field-label {
color: var(--ink);
margin-bottom: 12px;
display: flex;
font-size: 14px;
font-weight: 500;
font-family: sans-serif;
}
2020-09-22 03:45:55 +12:00
.capitalise :global(label),
.field-label {
text-transform: capitalize;
}
</style>