fix: support label + value for dynamic enums of selects

This commit is contained in:
Ruben Fiszel
2025-09-27 08:00:48 +00:00
parent ca4f9ee8c1
commit ec9e5a9acb
16 changed files with 95 additions and 67 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "windmill-utils-internal",
"version": "1.3.0",
"version": "1.3.1",
"description": "Internal utility functions for Windmill",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -21,4 +21,4 @@
"files": [
"dist/**/*"
]
}
}
@@ -1 +1 @@
export * from "./config.ts";
export * from "./config";
+5 -5
View File
@@ -8,8 +8,8 @@
* - Cross-platform path constants
*/
export * from "./inline-scripts.ts";
export * from "./path-utils.ts";
export * from "./parse.ts";
export * from "./config.ts";
export { SEP, DELIMITER } from "./constants.ts";
export * from "./inline-scripts";
export * from "./path-utils";
export * from "./parse";
export * from "./config";
export { SEP, DELIMITER } from "./constants";
@@ -1,5 +1,5 @@
import { newPathAssigner } from "../path-utils/path-assigner.ts";
import { FlowModule } from "../gen/types.gen.ts";
import { newPathAssigner } from "../path-utils/path-assigner";
import { FlowModule } from "../gen/types.gen";
/**
* Represents an inline script extracted from a flow module
@@ -1,2 +1,2 @@
export * from "./replacer.ts";
export * from "./extractor.ts";
export * from "./replacer";
export * from "./extractor";
@@ -1,4 +1,4 @@
import { FlowModule } from "../gen/types.gen.ts";
import { FlowModule } from "../gen/types.gen";
/**
* Replaces inline script references with actual file content from the filesystem.
@@ -1 +1 @@
export * from "./parse-schema.ts";
export * from "./parse-schema";
@@ -1,7 +1,7 @@
/**
* Type alias for enum values - can be an array of strings or undefined
*/
export type EnumType = string[] | undefined;
export type EnumType = string[] | { label: string; value: string }[] | undefined;
/**
* Represents a property in a JSON schema with various validation and display options
@@ -17,7 +17,7 @@ export interface SchemaProperty {
items?: {
type?: "string" | "number" | "bytes" | "object" | "resource";
contentEncoding?: "base64";
enum?: string[];
enum?: EnumType;
resourceType?: string;
properties?: { [name: string]: SchemaProperty };
};
@@ -54,22 +54,22 @@ export function argSigToJsonSchemaType(
| string
| { resource: string | null }
| {
list:
| (string | { name?: string; props?: { key: string; typ: any }[] })
| { str: any }
| { object: { name?: string; props?: { key: string; typ: any }[] } }
| null;
}
list:
| (string | { name?: string; props?: { key: string; typ: any }[] })
| { str: any }
| { object: { name?: string; props?: { key: string; typ: any }[] } }
| null;
}
| { dynselect: string }
| { dynmultiselect: string }
| { str: string[] | null }
| { object: { name?: string; props?: { 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: "" };
@@ -1 +1 @@
export * from "./path-assigner.ts";
export * from "./path-assigner";
@@ -1,4 +1,4 @@
import { RawScript } from "../gen/types.gen.ts";
import { RawScript } from "../gen/types.gen";
const INLINE_SCRIPT_PREFIX = "inline_script";
+4 -4
View File
@@ -86,7 +86,7 @@
"windmill-parser-wasm-ts": "1.538.0",
"windmill-parser-wasm-yaml": "1.510.1",
"windmill-sql-datatype-parser-wasm": "1.512.0",
"windmill-utils-internal": "^1.3.0",
"windmill-utils-internal": "^1.3.1",
"xterm": "^5.3.0",
"xterm-readline": "^1.1.2",
"y-monaco": "^0.1.4",
@@ -13542,9 +13542,9 @@
"integrity": "sha512-uHNL8F72/Tf96xF3hOHnPDjkEyqXw7fNjcPJiUhth9sTQkcwUIoJMOdwm8/cs+j9kKVRJ4tgNYMHEBLylazp6g=="
},
"node_modules/windmill-utils-internal": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/windmill-utils-internal/-/windmill-utils-internal-1.3.0.tgz",
"integrity": "sha512-UH7G+NVODkhm4o3BbjaOrSE2Qu+J6ro7+vpsIs+GvjDZM4ogSN7aJfnQNHW7Ke0VY74BKZVClTKROe/N6I5Reg==",
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/windmill-utils-internal/-/windmill-utils-internal-1.3.1.tgz",
"integrity": "sha512-afRGUDcvaUfGu7FA6DD0xWECQiKnXADs0N4WyQQ+OvaloxZ4oQzdEpLnVab/m3T02hhs29ru4Ilrdxu3ozyT5Q==",
"license": "Apache 2.0"
},
"node_modules/word-wrap": {
+1 -1
View File
@@ -151,7 +151,7 @@
"windmill-parser-wasm-ts": "1.538.0",
"windmill-parser-wasm-yaml": "1.510.1",
"windmill-sql-datatype-parser-wasm": "1.512.0",
"windmill-utils-internal": "^1.3.0",
"windmill-utils-internal": "^1.3.1",
"xterm": "^5.3.0",
"xterm-readline": "^1.1.2",
"y-monaco": "^0.1.4",
+1 -1
View File
@@ -15,7 +15,7 @@ export interface PropertyDisplayInfo {
propertiesNumber: number
}
export type EnumType = string[] | undefined
export type EnumType = string[] | { value: string; label: string }[] | undefined
export interface SchemaProperty {
type: string | undefined
+13 -5
View File
@@ -30,11 +30,19 @@
let customItems: string[] = $state([])
let items = $derived.by(() => {
const l = [...(enum_ ? enum_ : []), ...customItems].map((item) => ({
value: item,
label: enumLabels?.[item] ?? item
}))
if (create && filterText && l.every((i) => i.value !== filterText)) {
const l = [...(enum_ ? enum_ : []), ...customItems]
.map((item) => {
if (typeof item === 'string') {
return {
value: item,
label: enumLabels?.[item] ?? item
}
} else if (typeof item === 'object') {
return item
}
})
.filter((i) => i != undefined)
if (create && filterText && l.every((i) => i?.value !== filterText)) {
l.push({ value: filterText, label: `Add new: ${filterText}` })
}
return l
+6 -1
View File
@@ -248,7 +248,12 @@
if (inputCat === 'string') {
nvalue = nullable ? null : ''
} else if (inputCat == 'enum' && required) {
nvalue = enum_?.[0]
let firstV = enum_?.[0]
if (typeof firstV === 'string') {
nvalue = firstV
} else if (firstV && typeof firstV === 'object') {
nvalue = firstV.value
}
} else if (inputCat == 'boolean') {
nvalue = false
} else if (inputCat == 'list') {
@@ -98,12 +98,12 @@
}
let choice = `choice ${enum_?.length ? enum_?.length + 1 : 1}`
enum_ = enum_ ? enum_.concat(choice) : [choice]
enum_ = enum_ ? (enum_.concat(choice) as EnumType) : [choice]
}
function remove(item: string) {
enum_ = (enum_ || []).filter((el) => el !== item)
if (enum_.length == 0) {
enum_ = (enum_ || []).filter((el) => el !== item) as EnumType
if (enum_?.length == 0) {
enum_ = undefined
}
@@ -230,34 +230,49 @@
<div class="flex flex-col gap-1">
{#if enum_}
{#each enum_ as _, i}
<div class="flex flex-row w-full gap-2 pt-2">
<input
id="input"
type="text"
bind:value={enum_[i]}
oninput={(event) => enum_ && onEnumKeyChange(event?.currentTarget.value, enum_[i])}
/>
{#if enumLabels !== undefined}
{#if typeof enum_[i] === 'string'}
<div class="flex flex-row w-full gap-2 pt-2">
<input
id="input"
type="text"
bind:value={enumLabels[enum_[i]]}
placeholder="Optional title..."
oninput={(event) => {
if (event?.currentTarget.value === '') {
if (enumLabels === undefined) {
enumLabels = {}
}
enum_ && delete enumLabels[enum_[i]]
}
}}
bind:value={enum_[i]}
oninput={(event) =>
enum_ &&
typeof enum_[i] === 'string' &&
onEnumKeyChange(event?.currentTarget.value, enum_[i])}
/>
{/if}
{#if enumLabels !== undefined}
<input
id="input"
type="text"
bind:value={enumLabels[enum_[i]]}
placeholder="Optional title..."
oninput={(event) => {
if (event?.currentTarget.value === '') {
if (enumLabels === undefined) {
enumLabels = {}
}
if (typeof enum_?.[i] === 'string') {
enum_ && delete enumLabels[enum_[i]]
}
}
}}
/>
{/if}
{#if allowKindChange}
<Button size="sm" on:click={() => enum_ && remove(enum_[i])}>-</Button>
{/if}
</div>
{#if allowKindChange}
<Button
size="sm"
on:click={() => enum_ && typeof enum_[i] === 'string' && remove(enum_[i])}
>-</Button
>
{/if}
</div>
{:else}
<div class="flex flex-row w-full gap-2 pt-2">
{JSON.stringify(enum_[i])} is not a string, remove it
</div>
{/if}
{/each}
{/if}
</div>