mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-10 08:07:03 +00:00
fix: fix reorder of args in schema form
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
import LightweightArgInput from './LightweightArgInput.svelte'
|
||||
import type { ComponentCustomCSS } from './apps/types'
|
||||
import { allTrue, computeShow } from '$lib/utils'
|
||||
import { deepEqual } from 'fast-equals'
|
||||
|
||||
export let css: ComponentCustomCSS<'schemaformcomponent'> | undefined = undefined
|
||||
|
||||
@@ -24,8 +25,6 @@
|
||||
args = {}
|
||||
}
|
||||
|
||||
reorder()
|
||||
|
||||
export function invalidate(key: string, error: string) {
|
||||
inputCheck[key] = false
|
||||
errors[key] = error
|
||||
@@ -41,29 +40,39 @@
|
||||
errors = Object.fromEntries(Object.entries(errors).map((x) => [x[0], '']))
|
||||
}
|
||||
|
||||
let keys: string[] = Array.isArray(schema?.order)
|
||||
? schema?.order
|
||||
: Object.keys(schema?.properties ?? {})
|
||||
|
||||
$: schema && reorder()
|
||||
|
||||
function reorder() {
|
||||
console.log('reorder')
|
||||
if (schema?.order && Array.isArray(schema.order)) {
|
||||
const n = {}
|
||||
let lkeys = Object.keys(schema?.properties ?? {})
|
||||
if (!deepEqual(schema?.order, lkeys) || !deepEqual(keys, lkeys)) {
|
||||
console.debug('reorder')
|
||||
if (schema?.order && Array.isArray(schema.order)) {
|
||||
const n = {}
|
||||
|
||||
;(schema.order as string[]).forEach((x) => {
|
||||
if (schema.properties && schema.properties[x] != undefined) {
|
||||
n[x] = schema.properties[x]
|
||||
}
|
||||
})
|
||||
|
||||
Object.keys(schema.properties ?? {})
|
||||
.filter((x) => !schema.order?.includes(x))
|
||||
.forEach((x) => {
|
||||
n[x] = schema.properties[x]
|
||||
;(schema.order as string[]).forEach((x) => {
|
||||
if (schema.properties && schema.properties[x] != undefined) {
|
||||
n[x] = schema.properties[x]
|
||||
}
|
||||
})
|
||||
schema.properties = n
|
||||
|
||||
Object.keys(schema.properties ?? {})
|
||||
.filter((x) => !schema.order?.includes(x))
|
||||
.forEach((x) => {
|
||||
n[x] = schema.properties[x]
|
||||
})
|
||||
schema.properties = n
|
||||
}
|
||||
keys = Object.keys(schema.properties ?? {})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class={twMerge('w-full flex flex-col px-0.5 pb-2', largeGap ? 'gap-8' : 'gap-2')}>
|
||||
{#each Object.keys(schema.properties ?? {}) as argName (argName)}
|
||||
{#each keys as argName (argName)}
|
||||
{#if typeof args == 'object' && schema?.properties[argName] && args}
|
||||
<LightweightArgInput
|
||||
render={computeShow(argName, schema?.properties[argName].showExpr, args)}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import ToggleButton from './common/toggleButton-v2/ToggleButton.svelte'
|
||||
import { getResourceTypes } from './resourceTypesStore'
|
||||
import { Plus } from 'lucide-svelte'
|
||||
import { deepEqual } from 'fast-equals'
|
||||
|
||||
export let schema: Schema | any
|
||||
export let schemaSkippedValues: string[] = []
|
||||
@@ -55,7 +56,9 @@
|
||||
args = nargs
|
||||
}
|
||||
|
||||
let keys: string[] = []
|
||||
let keys: string[] = Array.isArray(schema?.order)
|
||||
? schema?.order
|
||||
: Object.keys(schema?.properties ?? {})
|
||||
|
||||
function removeExtraKey() {
|
||||
const nargs = {}
|
||||
@@ -71,16 +74,6 @@
|
||||
let itemPicker: ItemPicker | undefined = undefined
|
||||
let variableEditor: VariableEditor | undefined = undefined
|
||||
|
||||
$: {
|
||||
let lkeys = Object.keys(schema?.properties ?? {})
|
||||
if (schema?.properties && JSON.stringify(lkeys) != JSON.stringify(keys)) {
|
||||
keys = lkeys
|
||||
if (!noDelete) {
|
||||
removeExtraKey()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$: isValid = allTrue(inputCheck ?? {})
|
||||
|
||||
let resourceTypes: string[] | undefined = undefined
|
||||
@@ -93,24 +86,35 @@
|
||||
|
||||
$: schema && reorder()
|
||||
|
||||
function hasExtraKeys() {
|
||||
return Object.keys(args ?? {}).some((x) => !keys.includes(x))
|
||||
}
|
||||
function reorder() {
|
||||
if (schema?.order && Array.isArray(schema.order)) {
|
||||
const n = {}
|
||||
let lkeys = Object.keys(schema?.properties ?? {})
|
||||
if (!deepEqual(schema?.order, lkeys) || !deepEqual(keys, lkeys)) {
|
||||
console.debug('reorder')
|
||||
if (schema?.order && Array.isArray(schema.order)) {
|
||||
const n = {}
|
||||
|
||||
;(schema.order as string[]).forEach((x) => {
|
||||
if (schema.properties && schema.properties[x] != undefined) {
|
||||
n[x] = schema.properties[x]
|
||||
}
|
||||
})
|
||||
|
||||
Object.keys(schema.properties ?? {})
|
||||
.filter((x) => !schema.order?.includes(x))
|
||||
.forEach((x) => {
|
||||
n[x] = schema.properties[x]
|
||||
;(schema.order as string[]).forEach((x) => {
|
||||
if (schema.properties && schema.properties[x] != undefined) {
|
||||
n[x] = schema.properties[x]
|
||||
}
|
||||
})
|
||||
schema.properties = n
|
||||
|
||||
Object.keys(schema.properties ?? {})
|
||||
.filter((x) => !schema.order?.includes(x))
|
||||
.forEach((x) => {
|
||||
n[x] = schema.properties[x]
|
||||
})
|
||||
schema.properties = n
|
||||
}
|
||||
keys = Object.keys(schema.properties ?? {})
|
||||
}
|
||||
|
||||
if (!noDelete && hasExtraKeys()) {
|
||||
removeExtraKey()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -434,7 +434,7 @@
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
let error = e.body ?? e.message
|
||||
let error = e?.body ?? e?.message
|
||||
updateResult({ error })
|
||||
$errorByComponent[id] = { error }
|
||||
}
|
||||
@@ -593,7 +593,7 @@
|
||||
},
|
||||
error: (e) => {
|
||||
console.error(e)
|
||||
reject()
|
||||
reject(e)
|
||||
}
|
||||
}).catch(reject)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user