mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 16:20:25 +00:00
fix: show resource properties missing from the resource type schema (#12265)
* fix: show resource properties missing from the resource type schema The schema form only renders the type's properties, so a property removed from the resource type stayed in the stored value, invisible, and still reached scripts (a $var: in it fails the job once the variable is gone). The resource editor now lists such properties with an action to remove them, and the resource type editor warns when a save drops properties. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: render leftover resource properties as fields instead of an alert Each key the schema lacks gets its own untyped (JSON) field with a warning and a remove button, so its value can be read and edited in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: ignore validity of fields no longer in the schema form A field removed while invalid kept its false check, leaving the form invalid (and Save disabled) with nothing on screen to fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: flag leftover resource properties with a hover warning by the name The explanation moves from an always-visible description into a warning icon next to the field name (SchemaForm schemaFieldWarnings). The resource type editor's alert shrinks to one line without the property names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e6183f5e0f
commit
2a4724d482
@@ -12,7 +12,7 @@
|
||||
getSchemaFromProperties,
|
||||
type DynamicInput as DynamicInputTypes
|
||||
} from '$lib/utils'
|
||||
import { DollarSign, Plus, X, Check, Loader2, ExternalLink } from 'lucide-svelte'
|
||||
import { DollarSign, Plus, X, Check, Loader2, ExternalLink, AlertTriangle } from 'lucide-svelte'
|
||||
import { createEventDispatcher, onDestroy, onMount, tick, untrack } from 'svelte'
|
||||
import { fade } from 'svelte/transition'
|
||||
import { Alert, Button, SecondsInput } from './common'
|
||||
@@ -93,6 +93,8 @@
|
||||
disablePortal?: boolean
|
||||
showSchemaExplorer?: boolean
|
||||
simpleTooltip?: string | undefined
|
||||
/** Show `simpleTooltip` behind a warning icon rather than an info icon. */
|
||||
simpleTooltipWarning?: boolean
|
||||
customErrorMessage?: string | undefined
|
||||
onlyMaskPassword?: boolean
|
||||
nullable?: boolean
|
||||
@@ -165,6 +167,7 @@
|
||||
disablePortal = false,
|
||||
showSchemaExplorer = false,
|
||||
simpleTooltip = undefined,
|
||||
simpleTooltipWarning = false,
|
||||
customErrorMessage = undefined,
|
||||
onlyMaskPassword = false,
|
||||
nullable = false,
|
||||
@@ -671,6 +674,8 @@
|
||||
{contentEncoding}
|
||||
{format}
|
||||
{simpleTooltip}
|
||||
SimpleTooltipIcon={simpleTooltipWarning ? AlertTriangle : undefined}
|
||||
simpleTooltipIconClass={simpleTooltipWarning ? 'text-yellow-500' : undefined}
|
||||
{lightHeader}
|
||||
{displayType}
|
||||
labelClass={twMerge(lightHeaderFont ? '!font-normal text-primary' : '', css?.label?.class)}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
import { onDestroy, untrack } from 'svelte'
|
||||
import { setEditorUnparseable } from './pendingEditorFlush'
|
||||
import { emptyString, isOwner, urlize } from '$lib/utils'
|
||||
import { Alert, Skeleton } from './common'
|
||||
import { Alert, Button, Skeleton } from './common'
|
||||
import { Trash2 } from 'lucide-svelte'
|
||||
import Path from './Path.svelte'
|
||||
import LabelsInput from './LabelsInput.svelte'
|
||||
import { type UserExt } from '$lib/stores'
|
||||
@@ -123,6 +124,53 @@
|
||||
if (showReference) isValid = true
|
||||
})
|
||||
|
||||
// Keys the schema form cannot render (e.g. a property later removed from the resource type)
|
||||
// still ship with the value, and a `$var:` among them fails the job once the variable is gone.
|
||||
let orphanKeys = $derived.by(() => {
|
||||
const props = resourceSchema?.properties
|
||||
if (
|
||||
!props ||
|
||||
showReference ||
|
||||
rawMode ||
|
||||
loadingSchema ||
|
||||
resourceTypeInfo?.is_fileset ||
|
||||
resourceTypeInfo?.format_extension ||
|
||||
!args ||
|
||||
typeof args !== 'object' ||
|
||||
Array.isArray(args)
|
||||
) {
|
||||
return []
|
||||
}
|
||||
return Object.keys(args).filter((k) => !(k in props))
|
||||
})
|
||||
|
||||
// Rendered untyped, which the form shows as a JSON input, so any stored value fits.
|
||||
let formSchema = $derived(
|
||||
orphanKeys.length > 0 && resourceSchema
|
||||
? {
|
||||
...resourceSchema,
|
||||
properties: {
|
||||
...resourceSchema.properties,
|
||||
...Object.fromEntries(orphanKeys.map((k) => [k, {}]))
|
||||
}
|
||||
}
|
||||
: resourceSchema
|
||||
)
|
||||
|
||||
let orphanWarnings = $derived(
|
||||
Object.fromEntries(
|
||||
orphanKeys.map((k) => [
|
||||
k,
|
||||
'Not in the resource type schema, but still passed to scripts using this resource. Remove it if it is no longer used.'
|
||||
])
|
||||
)
|
||||
)
|
||||
|
||||
function removeOrphanKey(key: string) {
|
||||
const { [key]: _, ...rest } = args
|
||||
args = rest
|
||||
}
|
||||
|
||||
// This field is a bare SimpleEditor parsed here, so it never passes through JsonEditor —
|
||||
// it has to register itself, or a caller persisting what is on screen would save the
|
||||
// last value that parsed and leave without the text in front of the user.
|
||||
@@ -357,11 +405,25 @@
|
||||
noDelete
|
||||
disabled={!can_write}
|
||||
compact
|
||||
schema={resourceSchema}
|
||||
schema={formSchema}
|
||||
bind:args
|
||||
bind:isValid
|
||||
schemaFieldWarnings={orphanWarnings}
|
||||
{workspace}
|
||||
/>
|
||||
>
|
||||
{#snippet actions({ item })}
|
||||
{#if can_write && orphanKeys.includes(item.value)}
|
||||
<Button
|
||||
variant="subtle"
|
||||
unifiedSize="sm"
|
||||
iconOnly
|
||||
startIcon={{ icon: Trash2 }}
|
||||
title="Remove from this resource"
|
||||
onclick={() => removeOrphanKey(item.value)}
|
||||
/>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</SchemaForm>
|
||||
{/if}
|
||||
{:else if !can_write}
|
||||
<input type="text" disabled value={rawCode} />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
const bubble = createBubbler()
|
||||
import type { Schema } from '$lib/common'
|
||||
import { allTrue, type DynamicInput } from '$lib/utils'
|
||||
import { type DynamicInput } from '$lib/utils'
|
||||
import { computeShow, quickjsSettled } from '$lib/utils/quickjsEval.svelte'
|
||||
import { Button } from './common'
|
||||
import type ItemPicker from './ItemPicker.svelte'
|
||||
@@ -32,6 +32,8 @@
|
||||
schema: Schema | any
|
||||
hiddenArgs?: string[]
|
||||
schemaFieldTooltip?: Record<string, string>
|
||||
/** Per-field warning, shown on hover of a warning icon next to the field name. */
|
||||
schemaFieldWarnings?: Record<string, string>
|
||||
args?: Record<string, any>
|
||||
disabledArgs?: string[]
|
||||
disabled?: boolean
|
||||
@@ -84,6 +86,7 @@
|
||||
schema = $bindable(),
|
||||
hiddenArgs = [],
|
||||
schemaFieldTooltip = {},
|
||||
schemaFieldWarnings = {},
|
||||
args = $bindable(undefined),
|
||||
disabledArgs = [],
|
||||
disabled = false,
|
||||
@@ -278,7 +281,8 @@
|
||||
untrack(() => handleHiddenFields(schema, args ?? {}))
|
||||
})
|
||||
$effect.pre(() => {
|
||||
isValid = allTrue(inputCheck ?? {})
|
||||
// A field that left the schema keeps its last check here; it must not block validity.
|
||||
isValid = keys.every((k) => !(k in inputCheck) || !!inputCheck[k])
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -436,7 +440,8 @@
|
||||
password={linkedSecrets.includes(argName)}
|
||||
extra={prop}
|
||||
{showSchemaExplorer}
|
||||
simpleTooltip={schemaFieldTooltip[argName]}
|
||||
simpleTooltip={schemaFieldWarnings[argName] ?? schemaFieldTooltip[argName]}
|
||||
simpleTooltipWarning={argName in schemaFieldWarnings}
|
||||
{onlyMaskPassword}
|
||||
nullable={prop?.nullable}
|
||||
title={prop?.title}
|
||||
|
||||
@@ -150,6 +150,10 @@
|
||||
formatExtension: undefined as string | undefined,
|
||||
isFileset: false
|
||||
})
|
||||
let editResourceTypeOriginalKeys: string[] = $state([])
|
||||
let editResourceTypeRemovesKeys = $derived(
|
||||
editResourceTypeOriginalKeys.some((k) => !(k in (editResourceType.schema?.properties ?? {})))
|
||||
)
|
||||
let resourceEditor: ResourceEditorDrawer | undefined = $state(undefined)
|
||||
|
||||
/** An `ai_agent` gets the agent editor rather than the generic resource form, which would
|
||||
@@ -510,6 +514,7 @@
|
||||
formatExtension: rt.format_extension,
|
||||
isFileset: rt.is_fileset ?? false
|
||||
}
|
||||
editResourceTypeOriginalKeys = Object.keys((rt.schema as any)?.properties ?? {})
|
||||
editResourceTypeDrawer?.openDrawer?.()
|
||||
}
|
||||
|
||||
@@ -965,6 +970,14 @@
|
||||
</Alert>
|
||||
{:else}
|
||||
<div class="mb-1 font-semibold text-emphasis text-xs">Schema</div>
|
||||
{#if editResourceTypeRemovesKeys}
|
||||
<Alert
|
||||
type="warning"
|
||||
size="xs"
|
||||
class="mb-2"
|
||||
title="Existing resources keep removed properties and still pass them to scripts"
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col gap-2">
|
||||
<!-- Dynamic, like the one below: the schema editor reaches monaco. -->
|
||||
{#await import('$lib/components/schema/EditableSchemaWrapper.svelte') then EditableSchemaWrapper}
|
||||
|
||||
Reference in New Issue
Block a user