diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index ce64d7d231..bfc3c81cc0 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -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)} diff --git a/frontend/src/lib/components/ResourceForm.svelte b/frontend/src/lib/components/ResourceForm.svelte index c2404df0c0..78c71d00d9 100644 --- a/frontend/src/lib/components/ResourceForm.svelte +++ b/frontend/src/lib/components/ResourceForm.svelte @@ -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)} +