mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
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 <noreply@anthropic.com> * fix: open a referenced resource in the form's workspace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: say the variable's content is parsed as JSON in the menu Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the JSON editor while a reference is typed into it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: show the reference as text and reload the picker after creating a variable Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: pick the whole-value variable with the shared variable picker Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: pick another variable from the reference's own button only 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
201d8f6967
commit
2ce5a3a603
@@ -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, any> | 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}
|
||||
<div class="w-full flex gap-2 flex-row-reverse items-center">
|
||||
<Toggle
|
||||
on:change={(e) => switchTab(e.detail)}
|
||||
options={{
|
||||
right: 'As JSON'
|
||||
}}
|
||||
class="as-json-toggle"
|
||||
/>
|
||||
<ResourceGen
|
||||
bind:args
|
||||
{resourceType}
|
||||
resourceSchema={notFound ? undefined : schema}
|
||||
isFileset={resourceTypeInfo?.is_fileset ?? false}
|
||||
/>
|
||||
<TestConnection {resourceType} {args} />
|
||||
{#if aiProvider}
|
||||
<TestAiKey
|
||||
{aiProvider}
|
||||
workspace={workspace ?? $operatingWorkspace}
|
||||
resourceValue={args}
|
||||
model={$copilotInfo.aiModels.find((m) => m.provider === aiProvider)?.model}
|
||||
{#if showReference || canReferenceWholeValue(resourceTypeInfo)}
|
||||
<DropdownV2
|
||||
placement="bottom-end"
|
||||
items={() =>
|
||||
resourceValueMenuItems(showReference ? reference : undefined, {
|
||||
pickVariable: () => valueReference?.pickVariable(),
|
||||
editFields: () => setWholeValue({})
|
||||
})}
|
||||
/>
|
||||
{/if}
|
||||
{#if resourceType == 'postgresql'}
|
||||
<Popover
|
||||
floatingConfig={{
|
||||
placement: 'bottom'
|
||||
{#if !showReference}
|
||||
<Toggle
|
||||
on:change={(e) => switchTab(e.detail)}
|
||||
options={{
|
||||
right: 'As JSON'
|
||||
}}
|
||||
>
|
||||
{#snippet trigger()}
|
||||
<Button spacingSize="sm" size="xs" unifiedSize="md" variant="default" nonCaptureEvent>
|
||||
From connection string
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#snippet content({ close })}
|
||||
<div class="block text-primary p-4">
|
||||
<div class="w-[550px] flex flex-col items-start gap-1">
|
||||
<div class="flex flex-row gap-1 w-full">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={connectionString}
|
||||
placeholder="postgres://user:password@host:5432/dbname?sslmode=disable"
|
||||
/>
|
||||
<Button
|
||||
size="xs"
|
||||
color="blue"
|
||||
buttonType="button"
|
||||
on:click={() => {
|
||||
parseConnectionString(close)
|
||||
}}
|
||||
disabled={connectionString.length <= 0}
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
class="as-json-toggle"
|
||||
/>
|
||||
<ResourceGen
|
||||
bind:args
|
||||
{resourceType}
|
||||
resourceSchema={notFound ? undefined : schema}
|
||||
isFileset={resourceTypeInfo?.is_fileset ?? false}
|
||||
/>
|
||||
<TestConnection {resourceType} {args} />
|
||||
{#if aiProvider}
|
||||
<TestAiKey
|
||||
{aiProvider}
|
||||
workspace={workspace ?? $operatingWorkspace}
|
||||
resourceValue={args}
|
||||
model={$copilotInfo.aiModels.find((m) => m.provider === aiProvider)?.model}
|
||||
/>
|
||||
{/if}
|
||||
{#if resourceType == 'postgresql'}
|
||||
<Popover
|
||||
floatingConfig={{
|
||||
placement: 'bottom'
|
||||
}}
|
||||
>
|
||||
{#snippet trigger()}
|
||||
<Button spacingSize="sm" size="xs" unifiedSize="md" variant="default" nonCaptureEvent>
|
||||
From connection string
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#snippet content({ close })}
|
||||
<div class="block text-primary p-4">
|
||||
<div class="w-[550px] flex flex-col items-start gap-1">
|
||||
<div class="flex flex-row gap-1 w-full">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={connectionString}
|
||||
placeholder="postgres://user:password@host:5432/dbname?sslmode=disable"
|
||||
/>
|
||||
<Button
|
||||
size="xs"
|
||||
color="blue"
|
||||
buttonType="button"
|
||||
on:click={() => {
|
||||
parseConnectionString(close)
|
||||
}}
|
||||
disabled={connectionString.length <= 0}
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
</div>
|
||||
{#if !validConnectionString}
|
||||
<p class="text-red-500 text-xs">Could not parse connection string</p>
|
||||
{/if}
|
||||
</div>
|
||||
{#if !validConnectionString}
|
||||
<p class="text-red-500 text-xs">Could not parse connection string</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Popover>
|
||||
{/if}
|
||||
{#if resourceType == 'postgresql' && supabaseWizard}
|
||||
<!-- Imported here rather than at the top so the wizard's Supabase graph stays out of
|
||||
{/snippet}
|
||||
</Popover>
|
||||
{/if}
|
||||
{#if resourceType == 'postgresql' && supabaseWizard}
|
||||
<!-- Imported here rather than at the top so the wizard's Supabase graph stays out of
|
||||
this form's chunk, which loads on the resources page and in every resource drawer. -->
|
||||
{#await import('./workspaceSettings/SupabaseResourceConnect.svelte')}
|
||||
<Loader2 class="animate-spin" />
|
||||
{:then Module}
|
||||
<Module.default onPicked={applySupabasePick} />
|
||||
{/await}
|
||||
{/if}
|
||||
<GitHubAppIntegration
|
||||
{resourceType}
|
||||
{args}
|
||||
{description}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
args = newArgs
|
||||
rawCode = JSON.stringify(args, null, 2)
|
||||
rawCodeEditor?.setCode(rawCode)
|
||||
}}
|
||||
onDescriptionUpdate={(newDescription) => (description = newDescription)}
|
||||
/>
|
||||
<!-- Last in a `flex-row-reverse` row, so it lands beside the GitHub App
|
||||
{#await import('./workspaceSettings/SupabaseResourceConnect.svelte')}
|
||||
<Loader2 class="animate-spin" />
|
||||
{:then Module}
|
||||
<Module.default onPicked={applySupabasePick} />
|
||||
{/await}
|
||||
{/if}
|
||||
<GitHubAppIntegration
|
||||
{resourceType}
|
||||
{args}
|
||||
{description}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
args = newArgs
|
||||
rawCode = JSON.stringify(args, null, 2)
|
||||
rawCodeEditor?.setCode(rawCode)
|
||||
}}
|
||||
onDescriptionUpdate={(newDescription) => (description = newDescription)}
|
||||
/>
|
||||
<!-- Last in a `flex-row-reverse` row, so it lands beside the GitHub App
|
||||
button without splitting it from its own refresh control. -->
|
||||
<GitLabIntegration
|
||||
{resourceType}
|
||||
{args}
|
||||
{workspace}
|
||||
{onCredentialStored}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
args = newArgs
|
||||
rawCode = JSON.stringify(args, null, 2)
|
||||
rawCodeEditor?.setCode(rawCode)
|
||||
}}
|
||||
/>
|
||||
<GitLabIntegration
|
||||
{resourceType}
|
||||
{args}
|
||||
{workspace}
|
||||
{onCredentialStored}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
args = newArgs
|
||||
rawCode = JSON.stringify(args, null, 2)
|
||||
rawCodeEditor?.setCode(rawCode)
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{#if resourceType?.includes('bedrock') && !isCloudHosted()}
|
||||
<BedrockCredentialsCheck />
|
||||
@@ -277,7 +313,13 @@
|
||||
>
|
||||
<SyncResourceTypes {resourceType} {onSynced} />
|
||||
{/if}
|
||||
{#if notFound || viewJsonSchema || !schema?.properties}
|
||||
<ResourceValueReference
|
||||
bind:this={valueReference}
|
||||
reference={showReference ? reference : undefined}
|
||||
workspace={workspace ?? $operatingWorkspace}
|
||||
onPick={setWholeValue}
|
||||
/>
|
||||
{#if showReference}{:else if notFound || viewJsonSchema || !schema?.properties}
|
||||
{#if !emptyString(error)}<span class="text-red-400 text-xs mb-1 flex flex-row-reverse"
|
||||
>{error}</span
|
||||
>{:else}<div class="py-2"></div>{/if}
|
||||
|
||||
@@ -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, any> | string) {
|
||||
args = v as Record<string, any>
|
||||
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 @@
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="w-full flex gap-4 flex-row-reverse items-center">
|
||||
<Toggle
|
||||
bind:checked={viewJsonSchema}
|
||||
on:change={(e) => {
|
||||
if (e.detail) {
|
||||
rawCode = JSON.stringify(args, null, 2)
|
||||
} else if (resourceTypeInfo?.format_extension && !resourceTypeInfo?.is_fileset) {
|
||||
textFileContent = args?.content ?? ''
|
||||
}
|
||||
}}
|
||||
options={{
|
||||
right: 'As JSON'
|
||||
}}
|
||||
/>
|
||||
<ResourceGen
|
||||
bind:args
|
||||
resourceType={resource_type}
|
||||
resourceName={path}
|
||||
resourceDescription={description}
|
||||
{resourceSchema}
|
||||
/>
|
||||
{#if resourceToEdit?.resource_type === 'nats' || resourceToEdit?.resource_type === 'kafka'}
|
||||
<TestTriggerConnection kind={resourceToEdit?.resource_type} args={{ connection: args }} />
|
||||
{:else}
|
||||
<TestConnection
|
||||
resourceType={resourceToEdit?.resource_type}
|
||||
{args}
|
||||
workspaceOverride={workspace}
|
||||
{#if can_write && (showReference || canReferenceWholeValue(resourceTypeInfo))}
|
||||
<DropdownV2
|
||||
placement="bottom-end"
|
||||
items={() =>
|
||||
resourceValueMenuItems(showReference ? reference : undefined, {
|
||||
pickVariable: () => valueReference?.pickVariable(),
|
||||
editFields: () => setWholeValue({})
|
||||
})}
|
||||
/>
|
||||
{/if}
|
||||
{#if aiProvider}
|
||||
<TestAiKey
|
||||
{aiProvider}
|
||||
workspace={ws}
|
||||
resourceValue={args}
|
||||
model={$copilotInfo.aiModels.find((m) => m.provider === aiProvider)?.model}
|
||||
/>
|
||||
{/if}
|
||||
{#if resource_type === 'git_repository' && ws && (actingUser?.is_admin || actingUser?.is_super_admin)}
|
||||
<GitHubAppIntegration
|
||||
resourceType={resource_type}
|
||||
{args}
|
||||
{description}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
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}
|
||||
<Toggle
|
||||
bind:checked={viewJsonSchema}
|
||||
on:change={(e) => {
|
||||
if (e.detail) {
|
||||
rawCode = JSON.stringify(args, null, 2)
|
||||
} else if (resourceTypeInfo?.format_extension && !resourceTypeInfo?.is_fileset) {
|
||||
textFileContent = args?.content ?? ''
|
||||
}
|
||||
}}
|
||||
onDescriptionUpdate={(newDescription) => (description = newDescription)}
|
||||
/>
|
||||
<GitLabIntegration
|
||||
resourceType={resource_type}
|
||||
{args}
|
||||
workspace={ws}
|
||||
{onCredentialStored}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
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'
|
||||
}}
|
||||
/>
|
||||
<ResourceGen
|
||||
bind:args
|
||||
resourceType={resource_type}
|
||||
resourceName={path}
|
||||
resourceDescription={description}
|
||||
{resourceSchema}
|
||||
/>
|
||||
{#if resourceToEdit?.resource_type === 'nats' || resourceToEdit?.resource_type === 'kafka'}
|
||||
<TestTriggerConnection kind={resourceToEdit?.resource_type} args={{ connection: args }} />
|
||||
{:else}
|
||||
<TestConnection
|
||||
resourceType={resourceToEdit?.resource_type}
|
||||
{args}
|
||||
workspaceOverride={workspace}
|
||||
/>
|
||||
{/if}
|
||||
{#if aiProvider}
|
||||
<TestAiKey
|
||||
{aiProvider}
|
||||
workspace={ws}
|
||||
resourceValue={args}
|
||||
model={$copilotInfo.aiModels.find((m) => m.provider === aiProvider)?.model}
|
||||
/>
|
||||
{/if}
|
||||
{#if resource_type === 'git_repository' && ws && (actingUser?.is_admin || actingUser?.is_super_admin)}
|
||||
<GitHubAppIntegration
|
||||
resourceType={resource_type}
|
||||
{args}
|
||||
{description}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
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)}
|
||||
/>
|
||||
<GitLabIntegration
|
||||
resourceType={resource_type}
|
||||
{args}
|
||||
workspace={ws}
|
||||
{onCredentialStored}
|
||||
onArgsUpdate={(newArgs) => {
|
||||
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}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{#if loadingSchema}
|
||||
<ResourceValueReference
|
||||
bind:this={valueReference}
|
||||
reference={showReference ? reference : undefined}
|
||||
disabled={!can_write}
|
||||
workspace={ws}
|
||||
onPick={setWholeValue}
|
||||
/>
|
||||
{#if showReference}{:else if loadingSchema}
|
||||
<Skeleton layout={[[4]]} />
|
||||
{:else if !viewJsonSchema && resourceTypeInfo?.is_fileset}
|
||||
<div class="mt-1 flex items-center gap-2">
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
<script module lang="ts">
|
||||
import type { Item } from '$lib/utils'
|
||||
import type { ResourceType } from '$lib/gen'
|
||||
|
||||
/** The whole value of a resource can be a single `$jsonvar:`/`$var:`/`$res:` string, resolved
|
||||
* at runtime. No form may render over it: a schema form replaces it with empty fields. */
|
||||
export function resourceValueReference(value: unknown): string | undefined {
|
||||
return typeof value === 'string' &&
|
||||
['$jsonvar:', '$var:', '$res:'].some((p) => value.startsWith(p))
|
||||
? value
|
||||
: undefined
|
||||
}
|
||||
|
||||
/** A file-type resource is `{ content }` and a fileset a map of files: neither is a JSON
|
||||
* document a variable could hold whole. */
|
||||
export function canReferenceWholeValue(resourceTypeInfo: ResourceType | undefined): boolean {
|
||||
return !resourceTypeInfo?.format_extension && !resourceTypeInfo?.is_fileset
|
||||
}
|
||||
|
||||
export function resourceValueMenuItems(
|
||||
reference: string | undefined,
|
||||
actions: { pickVariable: () => void; editFields: () => void }
|
||||
): Item[] {
|
||||
return reference
|
||||
? [{ displayName: 'Edit fields instead', action: actions.editFields }]
|
||||
: [
|
||||
{
|
||||
displayName: 'Whole value from a variable',
|
||||
description: "The variable's content is parsed as JSON",
|
||||
action: actions.pickVariable
|
||||
}
|
||||
]
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { DollarSign } from 'lucide-svelte'
|
||||
import { Button } from './common'
|
||||
import type VariableEditor from './VariableEditor.svelte'
|
||||
import VariablePicker from './VariablePicker.svelte'
|
||||
|
||||
interface Props {
|
||||
/** The reference to show, `undefined` when the value is not one: the picker still mounts. */
|
||||
reference: string | undefined
|
||||
disabled?: boolean
|
||||
workspace: string | undefined
|
||||
onPick: (reference: string) => void
|
||||
}
|
||||
|
||||
let { reference, disabled = false, workspace, onPick }: Props = $props()
|
||||
|
||||
let picker: VariablePicker | undefined = $state(undefined)
|
||||
let variableEditor: VariableEditor | undefined = $state(undefined)
|
||||
|
||||
let referencedResource = $derived(reference?.startsWith('$res:') ? reference.slice(5) : undefined)
|
||||
let referencedVariable = $derived(
|
||||
reference && !referencedResource ? reference.slice(reference.indexOf(':') + 1) : undefined
|
||||
)
|
||||
|
||||
export function pickVariable() {
|
||||
picker?.openDrawer()
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if reference}
|
||||
<div class="flex flex-col gap-1 w-full">
|
||||
<div class="flex items-center gap-2 h-8 pl-2 pr-0.5 rounded-md bg-surface-secondary">
|
||||
<span class="grow truncate text-xs font-mono text-emphasis">{reference}</span>
|
||||
{#if !disabled}
|
||||
<Button
|
||||
iconOnly
|
||||
startIcon={{ icon: DollarSign }}
|
||||
unifiedSize="sm"
|
||||
onClick={pickVariable}
|
||||
variant="default"
|
||||
btnClasses="bg-surface-tertiary"
|
||||
title="Pick another variable"
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="text-2xs text-hint">
|
||||
{#if referencedResource}
|
||||
Linked to resource <a
|
||||
target="_blank"
|
||||
href="/resources{workspace
|
||||
? `?workspace=${workspace}`
|
||||
: ''}#/resource/{referencedResource}"
|
||||
class="text-accent underline">{referencedResource}</a
|
||||
>
|
||||
{:else}
|
||||
Linked to variable <button
|
||||
class="text-accent underline font-normal"
|
||||
onclick={() => variableEditor?.editVariable?.(referencedVariable ?? '')}
|
||||
>{referencedVariable}</button
|
||||
>.
|
||||
{reference.startsWith('$jsonvar:')
|
||||
? 'Its content is parsed as JSON and used as the whole value.'
|
||||
: 'Its content is used as the whole value.'}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<VariablePicker
|
||||
bind:this={picker}
|
||||
bind:variableEditor
|
||||
{workspace}
|
||||
tooltip="The variable must hold the whole value as JSON. It is parsed when the resource is used."
|
||||
onPick={(path) => onPick('$jsonvar:' + path)}
|
||||
/>
|
||||
Reference in New Issue
Block a user