From 2b5a47db2e31ecae15ef0628f99b51064cff6e0e Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 25 Nov 2023 11:03:14 +0100 Subject: [PATCH] fix: expand enum type narrowing to forms --- frontend/src/lib/common.ts | 17 +- .../lib/components/LightweightArgInput.svelte | 150 ++++++++++-------- .../components/LightweightSchemaForm.svelte | 4 +- .../src/lib/components/SchemaModal.svelte | 29 ++++ 4 files changed, 131 insertions(+), 69 deletions(-) diff --git a/frontend/src/lib/common.ts b/frontend/src/lib/common.ts index 2a7830eaa4..674199643d 100644 --- a/frontend/src/lib/common.ts +++ b/frontend/src/lib/common.ts @@ -28,6 +28,11 @@ export interface SchemaProperty { contentEncoding?: 'base64' enum?: string[] } + min?: number + max?: number + currency?: string + currencyLocale?: string + multiselect?: boolean customErrorMessage?: string properties?: { [name: string]: SchemaProperty } required?: string[] @@ -38,6 +43,11 @@ export interface ModalSchemaProperty { description: string name: string required: boolean + min?: number + max?: number + currency?: string + currencyLocale?: string + multiselect?: boolean format?: string pattern?: string enum_?: string[] @@ -60,7 +70,12 @@ export function modalToSchema(schema: ModalSchemaProperty): SchemaProperty { format: schema.format, customErrorMessage: schema.customErrorMessage, properties: schema.schema?.properties, - required: schema.schema?.required + required: schema.schema?.required, + min: schema.min, + max: schema.max, + currency: schema.currency, + currencyLocale: schema.currencyLocale, + multiselect: schema.multiselect } } export type Schema = { diff --git a/frontend/src/lib/components/LightweightArgInput.svelte b/frontend/src/lib/components/LightweightArgInput.svelte index ac347e9912..ffb06cda58 100644 --- a/frontend/src/lib/components/LightweightArgInput.svelte +++ b/frontend/src/lib/components/LightweightArgInput.svelte @@ -16,6 +16,7 @@ import LightweightObjectResourceInput from './LightweightObjectResourceInput.svelte' import DateTimeInput from './DateTimeInput.svelte' import CurrencyInput from './apps/components/inputs/currency/CurrencyInput.svelte' + import Multiselect from 'svelte-multiselect' export let css: ComponentCustomCSS<'schemaformcomponent'> | undefined = undefined export let label: string = '' @@ -37,6 +38,7 @@ type?: 'string' | 'number' | 'bytes' | 'object' contentEncoding?: 'base64' enum?: string[] + multiselect?: string[] } | undefined = undefined export let displayHeader = true @@ -226,73 +228,91 @@ {/if} {:else if inputCat == 'list'}
-
- {#if Array.isArray(value)} - {#each value ?? [] as v, i} -
- {#if itemsType?.type == 'number'} - - {:else if itemsType?.type == 'string' && itemsType?.contentEncoding == 'base64'} - fileChanged(x, (val) => (value[i] = val))} - multiple={false} - /> - {:else if Array.isArray(itemsType?.enum)} - + {:else if itemsType?.type == 'string' && itemsType?.contentEncoding == 'base64'} + fileChanged(x, (val) => (value[i] = val))} + multiple={false} + /> + {:else if Array.isArray(itemsType?.enum)} + + {:else} + + {/if} + -
- {/each} - {:else} - List is not an array - {/if} -
-
- -
- - {(value ?? []).length} item{(value ?? []).length != 1 ? 's' : ''} - + + +
+ {/each} + {:else} + List is not an array + {/if} + +
+ +
+ + {(value ?? []).length} item{(value ?? []).length != 1 ? 's' : ''} + + {/if} {:else if inputCat == 'resource-object'} diff --git a/frontend/src/lib/components/LightweightSchemaForm.svelte b/frontend/src/lib/components/LightweightSchemaForm.svelte index be9ae2ff18..6ca6a345a1 100644 --- a/frontend/src/lib/components/LightweightSchemaForm.svelte +++ b/frontend/src/lib/components/LightweightSchemaForm.svelte @@ -57,9 +57,7 @@ } -
+
{#each Object.keys(schema.properties ?? {}) as argName (argName)} {#if typeof args == 'object' && schema?.properties[argName] && args} {:else if property.selectedType == 'array'} +
+ + {:else if property.selectedType == 'number' || property.selectedType == 'integer'} + {:else if property.selectedType == 'object'} Custom Object