Use user readable enums in workflow block setup fields

This commit is contained in:
Andrew Kingston 2020-09-17 14:18:22 +01:00
parent 57a8dcf595
commit 1e099b9b5a
1 changed files with 17 additions and 12 deletions

View File

@ -7,7 +7,7 @@
export let block export let block
$: inputs = Object.entries(block.schema?.inputs?.properties || {}) $: inputs = Object.entries(block.schema?.inputs?.properties || {})
$: availableBindings = getAvailableBindings( $: bindings = getAvailableBindings(
block, block,
$workflowStore.selectedWorkflow?.workflow?.definition $workflowStore.selectedWorkflow?.workflow?.definition
) )
@ -16,8 +16,15 @@
if (!block || !workflow) { if (!block || !workflow) {
return [] return []
} }
const allSteps = [workflow.trigger, ...workflow.steps]
// Find previous steps to the selected one
let allSteps = [...workflow.steps]
if (workflow.trigger) {
allSteps = [workflow.trigger, ...allSteps]
}
const blockIdx = allSteps.findIndex(step => step.id === block.id) const blockIdx = allSteps.findIndex(step => step.id === block.id)
// Extract all outputs from all previous steps as available bindings
let bindings = [] let bindings = []
for (let idx = 0; idx < blockIdx; idx++) { for (let idx = 0; idx < blockIdx; idx++) {
const outputs = Object.entries(allSteps[idx].schema?.outputs?.properties) const outputs = Object.entries(allSteps[idx].schema?.outputs?.properties)
@ -43,26 +50,24 @@
{#if value.type === 'string' && value.enum} {#if value.type === 'string' && value.enum}
<Select bind:value={block.inputs[key]} thin secondary> <Select bind:value={block.inputs[key]} thin secondary>
<option value="">Choose an option</option> <option value="">Choose an option</option>
{#each value.enum as option} {#each value.enum as option, idx}
<option value={option}>{option}</option> <option value={option}>
{value.pretty ? value.pretty[idx] : option}
</option>
{/each} {/each}
</Select> </Select>
{:else if value.customType === 'password'} {:else if value.customType === 'password'}
<Input type="password" thin bind:value={block.inputs[key]} /> <Input type="password" thin bind:value={block.inputs[key]} />
{:else if value.type === 'number'}
<Input type="number" thin bind:value={block.inputs[key]} />
{:else if value.customType === 'longText'}
<TextArea type="text" thin bind:value={block.inputs[key]} />
{:else if value.customType === 'model'} {:else if value.customType === 'model'}
<ModelSelector bind:value={block.inputs[key]} /> <ModelSelector bind:value={block.inputs[key]} />
{:else if value.customType === 'record'} {:else if value.customType === 'record'}
<RecordSelector bind:value={block.inputs[key]} /> <RecordSelector bind:value={block.inputs[key]} {bindings} />
{:else if value.type === 'string'} {:else if value.type === 'string' || value.type === 'number'}
<BindableInput <BindableInput
type="text" type={value.type}
thin thin
bind:value={block.inputs[key]} bind:value={block.inputs[key]}
bindings={availableBindings} /> {bindings} />
{/if} {/if}
</div> </div>
{/each} {/each}