fix: use $var: syntax for empty string template fields (#6603)

* fix: use $var: syntax for empty string template fields (#6570)

Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>

* refactor: extract regex patterns to shared functions

Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>

---------

Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
This commit is contained in:
Ramtin Mesgari
2025-09-13 09:50:41 +00:00
committed by GitHub
co-authored by Ruben Fiszel
parent eb7cbd29bf
commit 0a7d762010
@@ -87,6 +87,11 @@
let argInput: ArgInput | undefined = $state(undefined)
let focusedPrev = false
const variableMatch = (value: string): RegExpMatchArray | null =>
value.match(/^variable\('([^']+)'\)$/)
const resourceMatch = (value: string): RegExpMatchArray | null =>
value.match(/^resource\('([^']+)'\)$/)
const dispatch = createEventDispatcher()
$effect(() => {
@@ -233,18 +238,18 @@
function connectProperty(rawValue: string) {
// Extract path from variable('x') or resource('x') format
const varMatch = rawValue.match(/^variable\('([^']+)'\)$/)
const resourceMatch = rawValue.match(/^resource\('([^']+)'\)$/)
const varMatch = variableMatch(rawValue)
const resMatch = resourceMatch(rawValue)
if (varMatch) {
arg.type = 'static'
propertyType = 'static'
arg.value = '$var:' + varMatch[1]
monacoTemplate?.setCode(arg.value)
} else if (resourceMatch) {
} else if (resMatch) {
arg.type = 'static'
propertyType = 'static'
arg.value = '$res:' + resourceMatch[1]
arg.value = '$res:' + resMatch[1]
monacoTemplate?.setCode(arg.value)
} else {
arg.expr = getDefaultExpr(undefined, previousModuleId, rawValue)
@@ -258,12 +263,20 @@
focused = true
if (isStaticTemplate(inputCat)) {
focusProp?.(argName, 'append', (path) => {
const toAppend = `\$\{${path}}`
arg.value = `${arg.value ?? ''}${toAppend}`
monacoTemplate?.setCode(arg.value)
setPropertyType(arg.value)
argInput?.focus()
return false
// Empty field + variable = use $var:/$res: syntax instead of ${...}
const isEmpty = !arg.value || arg.value.trim() === ''
if (isEmpty && variableMatch(path)) {
connectProperty(path)
return true
} else {
const toAppend = `\$\{${path}}`
arg.value = `${arg.value ?? ''}${toAppend}`
monacoTemplate?.setCode(arg.value)
setPropertyType(arg.value)
argInput?.focus()
return false
}
})
} else {
focusProp?.(argName, 'insert', (path) => {