From 2ce5a3a603746c65b8d3bf368e4a56d99fa4bdcd Mon Sep 17 00:00:00 2001 From: hugocasa Date: Tue, 3 Nov 2026 17:18:57 +0100 Subject: [PATCH] fix: keep a resource whose whole value is a variable reference (#12171) * fix: keep a resource whose whole value is a variable reference Co-Authored-By: Claude Opus 5.5 * fix: open a referenced resource in the form's workspace Co-Authored-By: Claude Opus 5.5 * fix: say the variable's content is parsed as JSON in the menu Co-Authored-By: Claude Opus 5.5 * fix: keep the JSON editor while a reference is typed into it Co-Authored-By: Claude Opus 5.5 * fix: show the reference as text and reload the picker after creating a variable Co-Authored-By: Claude Opus 5.5 * refactor: pick the whole-value variable with the shared variable picker Co-Authored-By: Claude Opus 5.5 * fix: pick another variable from the reference's own button only Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../src/lib/components/ApiConnectForm.svelte | 220 +++++++++++------- .../src/lib/components/ResourceForm.svelte | 189 +++++++++------ .../components/ResourceValueReference.svelte | 110 +++++++++ 3 files changed, 361 insertions(+), 158 deletions(-) create mode 100644 frontend/src/lib/components/ResourceValueReference.svelte diff --git a/frontend/src/lib/components/ApiConnectForm.svelte b/frontend/src/lib/components/ApiConnectForm.svelte index 37342912c7..5771e73910 100644 --- a/frontend/src/lib/components/ApiConnectForm.svelte +++ b/frontend/src/lib/components/ApiConnectForm.svelte @@ -20,6 +20,12 @@ import SyncResourceTypes from './SyncResourceTypes.svelte' import { parsePostgresConnectionString } from '$lib/utils/postgresConnectionString' import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' + import DropdownV2 from './DropdownV2.svelte' + import ResourceValueReference, { + canReferenceWholeValue, + resourceValueMenuItems, + resourceValueReference + } from './ResourceValueReference.svelte' const operatingWorkspace = useOperatingWorkspace() @@ -72,6 +78,7 @@ if (!resourceTypeInfo) return rawCode = '{}' viewJsonSchema = false + referencePinned = false try { schema = resourceTypeInfo.schema as any // A resource type may declare no properties at all — `dbt_profile` is a @@ -111,6 +118,23 @@ } } + let reference = $derived(resourceValueReference(args)) + // Pinned only by the picker: text typed into the JSON editor that parses to a reference keeps + // that editor, while any other form would replace the string with its own fields. + let referencePinned = $state(false) + let showReference = $derived( + !!reference && (referencePinned || !(notFound || viewJsonSchema || !schema?.properties)) + ) + let valueReference: ResourceValueReference | undefined = $state(undefined) + + function setWholeValue(v: Record | string) { + referencePinned = typeof v === 'string' + // The "As JSON" toggle holds its own state and remounts unchecked with the form. + viewJsonSchema = false + rawCode = JSON.stringify(v, null, 2) + args = v + } + let connectionString = $state('') let validConnectionString = $state(true) function parseConnectionString(close: (_: any) => void) { @@ -171,101 +195,113 @@ {#if !notFound}
- switchTab(e.detail)} - options={{ - right: 'As JSON' - }} - class="as-json-toggle" - /> - - - {#if aiProvider} - m.provider === aiProvider)?.model} + {#if showReference || canReferenceWholeValue(resourceTypeInfo)} + + resourceValueMenuItems(showReference ? reference : undefined, { + pickVariable: () => valueReference?.pickVariable(), + editFields: () => setWholeValue({}) + })} /> {/if} - {#if resourceType == 'postgresql'} - switchTab(e.detail)} + options={{ + right: 'As JSON' }} - > - {#snippet trigger()} - - {/snippet} - {#snippet content({ close })} -
-
-
- - + class="as-json-toggle" + /> + + + {#if aiProvider} + m.provider === aiProvider)?.model} + /> + {/if} + {#if resourceType == 'postgresql'} + + {#snippet trigger()} + + {/snippet} + {#snippet content({ close })} +
+
+
+ + +
+ {#if !validConnectionString} +

Could not parse connection string

+ {/if}
- {#if !validConnectionString} -

Could not parse connection string

- {/if}
-
- {/snippet} - - {/if} - {#if resourceType == 'postgresql' && supabaseWizard} - - {#await import('./workspaceSettings/SupabaseResourceConnect.svelte')} - - {:then Module} - - {/await} - {/if} - { - args = newArgs - rawCode = JSON.stringify(args, null, 2) - rawCodeEditor?.setCode(rawCode) - }} - onDescriptionUpdate={(newDescription) => (description = newDescription)} - /> - - { - args = newArgs - rawCode = JSON.stringify(args, null, 2) - rawCodeEditor?.setCode(rawCode) - }} - /> + { + args = newArgs + rawCode = JSON.stringify(args, null, 2) + rawCodeEditor?.setCode(rawCode) + }} + /> + {/if}
{#if resourceType?.includes('bedrock') && !isCloudHosted()} @@ -277,7 +313,13 @@ > {/if} -{#if notFound || viewJsonSchema || !schema?.properties} + +{#if showReference}{:else if notFound || viewJsonSchema || !schema?.properties} {#if !emptyString(error)}{error}{:else}
{/if} diff --git a/frontend/src/lib/components/ResourceForm.svelte b/frontend/src/lib/components/ResourceForm.svelte index 0a6e3edfc5..c2404df0c0 100644 --- a/frontend/src/lib/components/ResourceForm.svelte +++ b/frontend/src/lib/components/ResourceForm.svelte @@ -2,7 +2,7 @@ import ResourceDescriptionField from './ResourceDescriptionField.svelte' import type { Schema } from '$lib/common' import type { Resource, ResourceType } from '$lib/gen' - import { onDestroy } from 'svelte' + import { onDestroy, untrack } from 'svelte' import { setEditorUnparseable } from './pendingEditorFlush' import { emptyString, isOwner, urlize } from '$lib/utils' import { Alert, Skeleton } from './common' @@ -26,6 +26,12 @@ import Label from './Label.svelte' import ResourcePathHint from './ResourcePathHint.svelte' import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' + import DropdownV2 from './DropdownV2.svelte' + import ResourceValueReference, { + canReferenceWholeValue, + resourceValueMenuItems, + resourceValueReference + } from './ResourceValueReference.svelte' const operatingWorkspace = useOperatingWorkspace() @@ -93,6 +99,30 @@ let rawCode: string | undefined = $state(undefined) let textFileContent: string = $state('') + let reference = $derived(resourceValueReference(args)) + let rawMode = $derived( + viewJsonSchema || + (!resourceTypeInfo?.is_fileset && !(resourceSchema && resourceSchema.properties)) + ) + // Pinned when the value arrives as a reference (loaded or picked), not when the JSON editor's + // text parses to one: that editor stays mounted while it is being typed into. Any other form + // would replace the string with its own fields, so it never renders over a reference. + let referencePinned = $state(untrack(() => !!resourceValueReference(args))) + let showReference = $derived(!!reference && (referencePinned || !rawMode)) + let valueReference: ResourceValueReference | undefined = $state(undefined) + + function setWholeValue(v: Record | string) { + args = v as Record + referencePinned = typeof v === 'string' + jsonError = '' + // Reseeded from the new value by the effect below once the raw editor is the input again. + rawCode = undefined + } + + $effect(() => { + if (showReference) isValid = true + }) + // 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. @@ -115,11 +145,7 @@ // The raw JSON editor is the active input whenever the "As JSON" toggle is on, // or no schema-based form can be rendered (e.g. the resource type is missing // from the workspace). In both cases rawCode must be seeded from args. - let usesRawEditor = $derived( - !loadingSchema && - (viewJsonSchema || - (!resourceTypeInfo?.is_fileset && !(resourceSchema && resourceSchema.properties))) - ) + let usesRawEditor = $derived(!loadingSchema && !showReference && rawMode) $effect(() => { if (rawCode !== undefined) parseJson() @@ -142,7 +168,13 @@ // Seed the JSON editor when the resource type schema is missing // (restores the old ResourceEditor's catch-block behavior) $effect(() => { - if (resource_type && !loadingSchema && !resourceSchema && rawCode === undefined) { + if ( + resource_type && + !loadingSchema && + !resourceSchema && + !showReference && + rawCode === undefined + ) { rawCode = JSON.stringify(args, null, 2) } }) @@ -200,79 +232,98 @@
- { - if (e.detail) { - rawCode = JSON.stringify(args, null, 2) - } else if (resourceTypeInfo?.format_extension && !resourceTypeInfo?.is_fileset) { - textFileContent = args?.content ?? '' - } - }} - options={{ - right: 'As JSON' - }} - /> - - {#if resourceToEdit?.resource_type === 'nats' || resourceToEdit?.resource_type === 'kafka'} - - {:else} - + resourceValueMenuItems(showReference ? reference : undefined, { + pickVariable: () => valueReference?.pickVariable(), + editFields: () => setWholeValue({}) + })} /> {/if} - {#if aiProvider} - m.provider === aiProvider)?.model} - /> - {/if} - {#if resource_type === 'git_repository' && ws && (actingUser?.is_admin || actingUser?.is_super_admin)} - { - args = newArgs - // The raw editor is also what a workspace missing the resource type - // gets, and it holds its own copy of the value: without this the - // picker fills in a URL nothing on screen ever shows. - if (viewJsonSchema || !resourceSchema) { + {#if !showReference} + { + if (e.detail) { rawCode = JSON.stringify(args, null, 2) + } else if (resourceTypeInfo?.format_extension && !resourceTypeInfo?.is_fileset) { + textFileContent = args?.content ?? '' } }} - onDescriptionUpdate={(newDescription) => (description = newDescription)} - /> - { - args = newArgs - // The raw editor is also what a workspace missing the resource type - // gets, and it holds its own copy of the value: without this the - // picker fills in a URL nothing on screen ever shows. - if (viewJsonSchema || !resourceSchema) { - rawCode = JSON.stringify(args, null, 2) - } + options={{ + right: 'As JSON' }} /> + + {#if resourceToEdit?.resource_type === 'nats' || resourceToEdit?.resource_type === 'kafka'} + + {:else} + + {/if} + {#if aiProvider} + m.provider === aiProvider)?.model} + /> + {/if} + {#if resource_type === 'git_repository' && ws && (actingUser?.is_admin || actingUser?.is_super_admin)} + { + args = newArgs + // The raw editor is also what a workspace missing the resource type + // gets, and it holds its own copy of the value: without this the + // picker fills in a URL nothing on screen ever shows. + if (viewJsonSchema || !resourceSchema) { + rawCode = JSON.stringify(args, null, 2) + } + }} + onDescriptionUpdate={(newDescription) => (description = newDescription)} + /> + { + args = newArgs + // The raw editor is also what a workspace missing the resource type + // gets, and it holds its own copy of the value: without this the + // picker fills in a URL nothing on screen ever shows. + if (viewJsonSchema || !resourceSchema) { + rawCode = JSON.stringify(args, null, 2) + } + }} + /> + {/if} {/if}
- {#if loadingSchema} + + {#if showReference}{:else if loadingSchema} {:else if !viewJsonSchema && resourceTypeInfo?.is_fileset}
diff --git a/frontend/src/lib/components/ResourceValueReference.svelte b/frontend/src/lib/components/ResourceValueReference.svelte new file mode 100644 index 0000000000..198f0cad99 --- /dev/null +++ b/frontend/src/lib/components/ResourceValueReference.svelte @@ -0,0 +1,110 @@ + + + + +{#if reference} +
+
+ {reference} + {#if !disabled} +
+
+ {#if referencedResource} + Linked to resource {referencedResource} + {:else} + Linked to variable . + {reference.startsWith('$jsonvar:') + ? 'Its content is parsed as JSON and used as the whole value.' + : 'Its content is used as the whole value.'} + {/if} +
+
+{/if} + + onPick('$jsonvar:' + path)} +/>