From d61d6f520bd52df23f020cd12cbaf666cfe0097b Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 6 Apr 2024 15:00:49 +0200 Subject: [PATCH] fix: improve list static input --- frontend/src/lib/components/ArgInput.svelte | 229 ++++++++++-------- .../lib/components/InputTransformForm.svelte | 27 ++- frontend/src/lib/components/flows/utils.ts | 4 +- 3 files changed, 154 insertions(+), 106 deletions(-) diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index 0fb4e8d256..212a823c40 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -80,6 +80,7 @@ let s3FilePicker: S3FilePicker let s3FileUploadRawMode: false + let isListJson = false let el: HTMLTextAreaElement | undefined = undefined @@ -125,7 +126,7 @@ function evalValueToRaw() { rawValue = - inputCat === 'object' || inputCat === 'resource-object' + inputCat === 'object' || inputCat === 'resource-object' || (inputCat == 'list' && !isListJson) ? JSON.stringify(value, null, 2) : undefined } @@ -303,7 +304,6 @@ {/if} Preview: {/if} - {#if description}
{description}
@@ -370,107 +370,121 @@ {#if type == 'boolean' && value == undefined}   Not set {/if} - {:else if inputCat == 'list'} -
- {#if Array.isArray(itemsType?.multiselect) && Array.isArray(value)} -
- -
- {:else if itemsType?.enum != undefined && Array.isArray(itemsType?.enum) && Array.isArray(value)} -
- -
- {:else} -
- {#key redraw} - {#if Array.isArray(value)} - {#each value ?? [] as v, i} - {#if i < itemsLimit} -
- {#if itemsType?.type == 'number'} - - {:else if itemsType?.type == 'string' && itemsType?.contentEncoding == 'base64'} - fileChanged(x, (val) => (value[i] = val))} - multiple={false} - /> - {:else if itemsType?.type == 'object'} - - {:else if Array.isArray(itemsType?.enum)} - { - dispatch('focus') + {:else if inputCat == 'list' && !isListJson} +
+
+ {#if Array.isArray(itemsType?.multiselect) && Array.isArray(value)} +
+ +
+ {:else if itemsType?.enum != undefined && Array.isArray(itemsType?.enum) && Array.isArray(value)} +
+ +
+ {:else} +
+ {#key redraw} + {#if Array.isArray(value)} + {#each value ?? [] as v, i} + {#if i < itemsLimit} +
+ {#if itemsType?.type == 'number'} + + {:else if itemsType?.type == 'string' && itemsType?.contentEncoding == 'base64'} + fileChanged(x, (val) => (value[i] = val))} + multiple={false} + /> + {:else if itemsType?.type == 'object'} + + {:else if Array.isArray(itemsType?.enum)} + { + dispatch('focus') + }} + on:blur={(e) => { + dispatch('blur') + }} + {defaultValue} + {valid} + {disabled} + {autofocus} + bind:value={v} + enum_={itemsType?.enum ?? []} + /> + {:else} + + {/if} + -
+ > + + +
+ {/if} + {/each} + {#if value.length > itemsLimit} + {/if} - {/each} - {#if value.length > itemsLimit} - {/if} - {/if} - {/key} -
-
- -
- {/if} + {/key} +
+
+ +
+ {/if} +
+
+ { + evalValueToRaw() + isListJson = !isListJson + }} + checked={isListJson} + textClass="text-secondary" + size="xs" + options={{ right: 'json' }} + /> +
{:else if inputCat == 'resource-object' && resourceTypes == undefined} Loading resource types... @@ -529,7 +543,7 @@ /> {/if}
- {:else if inputCat == 'object' || inputCat == 'resource-object'} + {:else if inputCat == 'object' || inputCat == 'resource-object' || isListJson} {#if properties && Object.keys(properties).length > 0}
{/if} + {#if inputCat == 'list'} +
+ { + isListJson = !isListJson + }} + checked={isListJson} + textClass="text-secondary" + size="xs" + options={{ right: 'json' }} + /> +
+ {/if} {:else if inputCat == 'enum'}
@@ -419,6 +433,15 @@
{:else} Not recognized input type {argName} ({arg.expr}, {propertyType}) +
+
{/if}
diff --git a/frontend/src/lib/components/flows/utils.ts b/frontend/src/lib/components/flows/utils.ts index 19852e8e77..0c35ce9c60 100644 --- a/frontend/src/lib/components/flows/utils.ts +++ b/frontend/src/lib/components/flows/utils.ts @@ -68,9 +68,7 @@ export function evalValue( return v } -export function cleanInputs( - flow: OpenFlow | any -): OpenFlow & { +export function cleanInputs(flow: OpenFlow | any): OpenFlow & { tag?: string ws_error_handler_muted?: boolean dedicated_worker?: boolean