mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-20 16:02:19 +00:00
Fix UI crash with Dynamic Multiselect (#6660)
* Prevent crash when selecting dyn-multiselect * missing $derived and $state => reactivity issue when switching between DynSelect and DynMultiselect
This commit is contained in:
@@ -36,14 +36,16 @@
|
||||
|
||||
let { value = $bindable(), helperScript, format, otherArgs: otherArgs }: Props = $props()
|
||||
|
||||
const [inputType, entrypoint] = format.includes('-') ? format.split('-', 2) : [format, '']
|
||||
let [inputType, entrypoint] = $derived(format.includes('-') ? format.split('-', 2) : [format, ''])
|
||||
|
||||
const isMultiple = inputType === 'dynmultiselect'
|
||||
const isSelect = inputType === 'dynselect' || inputType === 'dynmultiselect'
|
||||
let isMultiple = $derived(inputType === 'dynmultiselect')
|
||||
let isSelect = $derived(inputType === 'dynselect' || inputType === 'dynmultiselect')
|
||||
|
||||
if (isMultiple && value === undefined) {
|
||||
value = []
|
||||
}
|
||||
$effect(() => {
|
||||
if (isMultiple && value === undefined) {
|
||||
value = []
|
||||
}
|
||||
})
|
||||
|
||||
let resultJobLoader: JobLoader | undefined = $state()
|
||||
let _items = usePromise(getItemsFromOptions, { clearValueOnRefresh: false })
|
||||
@@ -97,7 +99,7 @@
|
||||
|
||||
$effect(() => {
|
||||
if (_items.value && value !== undefined && isSelect) {
|
||||
if (isMultiple && Array.isArray(value)) {
|
||||
if (isMultiple && Array.isArray(value) && Array.isArray(_items.value)) {
|
||||
const availableValues = new Set(_items.value.map((x) => x.value))
|
||||
const filteredValue = value.filter((v) => availableValues.has(v))
|
||||
if (filteredValue.length !== value.length) {
|
||||
|
||||
@@ -372,6 +372,14 @@
|
||||
}
|
||||
|
||||
function updateDynCode(functionName: string, lang: ScriptLang = 'bun') {
|
||||
if (
|
||||
(lang == 'bun' && dynCode?.includes(`function ${functionName}`)) ||
|
||||
(lang == 'python3' && dynCode?.includes(`def ${functionName}`))
|
||||
) {
|
||||
// Don't add the function if it already exists
|
||||
return
|
||||
}
|
||||
|
||||
const generateFn = DynamicInput.getGenerateTemplateFn(lang)
|
||||
const code = generateFn(functionName)
|
||||
dynCode = dynCode ? dynCode.concat(code) : code
|
||||
@@ -701,6 +709,15 @@
|
||||
nullable: undefined,
|
||||
required: undefined
|
||||
}
|
||||
|
||||
if (
|
||||
isDynMultiselect &&
|
||||
args &&
|
||||
!Array.isArray(args?.[argName])
|
||||
) {
|
||||
args[argName] = []
|
||||
}
|
||||
|
||||
if (isS3) {
|
||||
schema.properties[argName] = {
|
||||
...emptyProperty,
|
||||
|
||||
Reference in New Issue
Block a user