mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 00:01:49 +00:00
fix handle default values
This commit is contained in:
@@ -235,6 +235,8 @@
|
||||
|
||||
let rawValue: string | undefined = $state(undefined)
|
||||
|
||||
let lastValue: any = null
|
||||
|
||||
function computeDefaultValue(inputCat?: string, defaultValue?: any, nnullable?: boolean) {
|
||||
let nvalue: any = null
|
||||
if (label == 'toString' && typeof value == 'function') {
|
||||
@@ -257,16 +259,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (nnullable && type === 'string' && value === '' && nvalue != null) {
|
||||
if (nnullable && type === 'string' && value === '' && nvalue == null) {
|
||||
value = null
|
||||
} else if (nvalue != null && !deepEqual(nvalue, value)) {
|
||||
console.log('set value 2', label, nvalue, value)
|
||||
value = nvalue
|
||||
lastValue = value
|
||||
}
|
||||
}
|
||||
|
||||
let lastValue: any = $state(undefined)
|
||||
|
||||
// By setting isListJson to true, we can render inputs even if the value is not an array of the correct type
|
||||
// This avoids the issue of the input being rendered as a string with value: [object Object], or as a number with value: NaN
|
||||
function checkArrayValueType() {
|
||||
@@ -353,7 +353,6 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
computeDefaultValue()
|
||||
evalValueToRaw()
|
||||
})
|
||||
|
||||
@@ -457,7 +456,8 @@
|
||||
$effect(() => {
|
||||
oneOf && value && untrack(() => onOneOfChange())
|
||||
})
|
||||
$effect(() => {
|
||||
|
||||
$effect.pre(() => {
|
||||
value
|
||||
let args = [inputCat, defaultValue, nullable]
|
||||
|
||||
@@ -466,7 +466,7 @@
|
||||
computeDefaultValue(...args)
|
||||
})
|
||||
})
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
!isListJson &&
|
||||
inputCat === 'list' &&
|
||||
value != lastValue &&
|
||||
@@ -474,10 +474,10 @@
|
||||
!hasIsListJsonChanged &&
|
||||
untrack(() => checkArrayValueType())
|
||||
})
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
defaultValue != undefined && untrack(() => handleDefaultValueChange())
|
||||
})
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
;(inputCat &&
|
||||
(isObjectCat(inputCat) || isRawStringEditor(inputCat)) &&
|
||||
!oneOf &&
|
||||
|
||||
@@ -337,7 +337,6 @@
|
||||
bind:schema={
|
||||
() => (previewSchema ? previewSchema : schema),
|
||||
(newSchema) => {
|
||||
console.log('schemaChange set', $state.snapshot(newSchema))
|
||||
schema = newSchema
|
||||
tick().then(() => dispatch('change', schema))
|
||||
}
|
||||
|
||||
@@ -114,12 +114,6 @@
|
||||
actions
|
||||
}: Props = $props()
|
||||
|
||||
$effect.pre(() => {
|
||||
if (args == undefined) {
|
||||
args = {}
|
||||
}
|
||||
})
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
let inputCheck: { [id: string]: boolean } = $state({})
|
||||
@@ -222,27 +216,32 @@
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
if (args == undefined || typeof args !== 'object') {
|
||||
args = {}
|
||||
}
|
||||
})
|
||||
$effect(() => {
|
||||
const newKeys = Array.isArray(schema?.order)
|
||||
? schema?.order
|
||||
: Object.keys(schema?.properties ?? {})
|
||||
$effect.pre(() => {
|
||||
const newKeys = [
|
||||
...new Set(
|
||||
(Array.isArray(schema?.order)
|
||||
? schema?.order
|
||||
: Object.keys(schema?.properties ?? {})) as string[]
|
||||
)
|
||||
]
|
||||
|
||||
if (!deepEqual(keys, newKeys)) {
|
||||
keys = newKeys
|
||||
}
|
||||
})
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
schema && (untrack(() => reorder()), (hidden = {}))
|
||||
})
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
;[schema, args]
|
||||
untrack(() => handleHiddenFields(schema, args ?? {}))
|
||||
})
|
||||
$effect(() => {
|
||||
$effect.pre(() => {
|
||||
isValid = allTrue(inputCheck ?? {})
|
||||
})
|
||||
const actions_render = $derived(actions)
|
||||
|
||||
@@ -61,14 +61,16 @@
|
||||
let schemaString: string = $state(JSON.stringify(schema, null, '\t'))
|
||||
let editor: SimpleEditor | undefined = $state(undefined)
|
||||
let error: string | undefined = $state(undefined)
|
||||
let items = $derived(
|
||||
((schema?.order ?? Object.keys(schema?.properties ?? {}))?.map((item, index) => {
|
||||
return { value: item, id: item }
|
||||
}) ?? []) as Array<{
|
||||
value: string
|
||||
id: string
|
||||
}>
|
||||
)
|
||||
let items = $derived([
|
||||
...new Set(
|
||||
(schema?.order ?? Object.keys(schema?.properties ?? {}))?.map((item, index) => {
|
||||
return { value: item, id: item }
|
||||
}) ?? []
|
||||
)
|
||||
]) as Array<{
|
||||
value: string
|
||||
id: string
|
||||
}>
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col items-end mb-2 w-full">
|
||||
@@ -163,7 +165,7 @@
|
||||
<Label label="Nested properties">
|
||||
<EditableSchemaDrawer
|
||||
on:change={() => {
|
||||
schema = schema
|
||||
schema = $state.snapshot(schema)
|
||||
dispatch('change', schema)
|
||||
}}
|
||||
bind:schema={schema.properties[item.value]}
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<!-- {JSON.stringify(items)} -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
|
||||
<SchemaForm
|
||||
{nestedClasses}
|
||||
{hiddenArgs}
|
||||
|
||||
Reference in New Issue
Block a user