mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 16:01:42 +00:00
fix: support specialization of list of strings to list of enums
This commit is contained in:
@@ -489,6 +489,7 @@
|
||||
<div class="items-start">
|
||||
<Multiselect
|
||||
ulOptionsClass={'p-2 !bg-surface-secondary'}
|
||||
outerDivClass={'dark:!border-gray-500 !border-gray-300'}
|
||||
{disabled}
|
||||
bind:selected={value}
|
||||
options={itemsType?.multiselect ?? []}
|
||||
@@ -502,6 +503,7 @@
|
||||
<div class="items-start">
|
||||
<Multiselect
|
||||
ulOptionsClass={'p-2 !bg-surface-secondary'}
|
||||
outerDivClass={'dark:!border-gray-500 !border-gray-300'}
|
||||
{disabled}
|
||||
bind:selected={value}
|
||||
options={itemsType?.enum ?? []}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import type { SchemaProperty } from '$lib/common'
|
||||
|
||||
export let canEditResourceType: boolean = false
|
||||
export let originalType: string | undefined = undefined
|
||||
export let itemsType:
|
||||
| {
|
||||
type?: 'string' | 'number' | 'bytes' | 'object' | 'resource'
|
||||
@@ -42,7 +43,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if canEditResourceType}
|
||||
{#if canEditResourceType || originalType == 'string[]' || originalType == 'object[]'}
|
||||
<Label label="Items type">
|
||||
<select
|
||||
bind:value={selected}
|
||||
@@ -67,10 +68,12 @@
|
||||
>
|
||||
<option value="string"> Items are strings</option>
|
||||
<option value="enum">Items are strings from an enum</option>
|
||||
<option value="object"> Items are objects (JSON)</option>
|
||||
<option value="resource"> Items are resources</option>
|
||||
<option value="number">Items are numbers</option>
|
||||
<option value="bytes">Items are bytes</option>
|
||||
{#if originalType != 'string[]'}
|
||||
<option value="object"> Items are objects (JSON)</option>
|
||||
<option value="resource"> Items are resources</option>
|
||||
<option value="number">Items are numbers</option>
|
||||
<option value="bytes">Items are bytes</option>
|
||||
{/if}
|
||||
</select>
|
||||
</Label>
|
||||
{:else if itemsType?.resourceType}
|
||||
@@ -121,31 +124,33 @@
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="flex flex-row mb-1 mt-2">
|
||||
<Button
|
||||
color="light"
|
||||
variant="border"
|
||||
size="sm"
|
||||
on:click={() => {
|
||||
if (itemsType?.enum) {
|
||||
let enum_ = itemsType.enum
|
||||
let choice = `choice ${enum_?.length ? enum_?.length + 1 : 1}`
|
||||
itemsType.enum = itemsType.enum ? itemsType.enum.concat(choice) : [choice]
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Plus size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
color="light"
|
||||
variant="border"
|
||||
size="sm"
|
||||
btnClasses="ml-2"
|
||||
on:click={() => itemsType?.enum && (itemsType.enum = undefined)}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
</div>
|
||||
{#if canEditResourceType || originalType == 'string[]'}
|
||||
<div class="flex flex-row mb-1 mt-2">
|
||||
<Button
|
||||
color="light"
|
||||
variant="border"
|
||||
size="sm"
|
||||
on:click={() => {
|
||||
if (itemsType?.enum) {
|
||||
let enum_ = itemsType.enum
|
||||
let choice = `choice ${enum_?.length ? enum_?.length + 1 : 1}`
|
||||
itemsType.enum = itemsType.enum ? itemsType.enum.concat(choice) : [choice]
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Plus size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
color="light"
|
||||
variant="border"
|
||||
size="sm"
|
||||
btnClasses="ml-2"
|
||||
on:click={() => itemsType?.enum && (itemsType.enum = undefined)}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</label>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -160,7 +160,11 @@
|
||||
</Label>
|
||||
|
||||
{#if type == 'array'}
|
||||
<ArrayTypeNarrowing bind:itemsType canEditResourceType={isFlowInput || isAppInput} />
|
||||
<ArrayTypeNarrowing
|
||||
originalType={extra['originalType']}
|
||||
bind:itemsType
|
||||
canEditResourceType={isFlowInput || isAppInput}
|
||||
/>
|
||||
{:else if type == 'string' || ['number', 'integer', 'object'].includes(type ?? '')}
|
||||
<div>
|
||||
<Label label="Field settings">
|
||||
|
||||
@@ -5,23 +5,23 @@ export function argSigToJsonSchemaType(
|
||||
| string
|
||||
| { resource: string | null }
|
||||
| {
|
||||
list:
|
||||
| (string | { object: { key: string; typ: any }[] })
|
||||
| { str: any }
|
||||
| { object: { key: string; typ: any }[] }
|
||||
| null
|
||||
}
|
||||
list:
|
||||
| (string | { object: { key: string; typ: any }[] })
|
||||
| { str: any }
|
||||
| { object: { key: string; typ: any }[] }
|
||||
| null
|
||||
}
|
||||
| { dynselect: string }
|
||||
| { str: string[] | null }
|
||||
| { object: { key: string; typ: any }[] }
|
||||
| {
|
||||
oneof: [
|
||||
{
|
||||
label: string
|
||||
properties: { key: string; typ: any }[]
|
||||
}
|
||||
]
|
||||
},
|
||||
oneof: [
|
||||
{
|
||||
label: string
|
||||
properties: { key: string; typ: any }[]
|
||||
}
|
||||
]
|
||||
},
|
||||
oldS: SchemaProperty
|
||||
): void {
|
||||
const newS: SchemaProperty = { type: '' }
|
||||
@@ -103,19 +103,26 @@ export function argSigToJsonSchemaType(
|
||||
newS.format = `dynselect-${t.dynselect}`
|
||||
} else if (typeof t !== 'string' && `list` in t) {
|
||||
newS.type = 'array'
|
||||
console.log(t.list)
|
||||
if (t.list === 'int' || t.list === 'float') {
|
||||
newS.items = { type: 'number' }
|
||||
newS.originalType = 'number[]'
|
||||
} else if (t.list === 'bytes') {
|
||||
newS.items = { type: 'string', contentEncoding: 'base64' }
|
||||
} else if (t.list == 'string') {
|
||||
newS.items = { type: 'string' }
|
||||
} else if (t.list && typeof t.list == 'object' && 'str' in t.list) {
|
||||
newS.originalType = 'bytes[]'
|
||||
} else if (t.list && typeof t.list == 'object' && 'str' in t.list && t.list.str) {
|
||||
console.log('str', t.list.str)
|
||||
newS.items = { type: 'string', enum: t.list.str }
|
||||
newS.originalType = 'enum[]'
|
||||
} else if (t.list == 'string' || (t.list && typeof t.list == 'object' && 'str' in t.list)) {
|
||||
newS.items = { type: 'string', enum: oldS.items?.enum }
|
||||
newS.originalType = 'string[]'
|
||||
} else if (t.list && typeof t.list == 'object' && 'resource' in t.list && t.list.resource) {
|
||||
newS.items = {
|
||||
type: 'resource',
|
||||
resourceType: t.list.resource as string
|
||||
}
|
||||
newS.originalType = 'resource[]'
|
||||
} else if (
|
||||
t.list &&
|
||||
typeof t.list == 'object' &&
|
||||
@@ -131,8 +138,10 @@ export function argSigToJsonSchemaType(
|
||||
}
|
||||
|
||||
newS.items = { type: 'object', properties: properties }
|
||||
newS.originalType = 'record[]'
|
||||
} else {
|
||||
newS.items = { type: 'object' }
|
||||
newS.originalType = 'object[]'
|
||||
}
|
||||
} else {
|
||||
newS.type = 'object'
|
||||
|
||||
Reference in New Issue
Block a user