🐛 Fix parseVariables when preceding with a dollar sign
This commit is contained in:
@@ -179,6 +179,7 @@ export const VariableSearchInput = ({
|
|||||||
onFocus={onOpen}
|
onFocus={onOpen}
|
||||||
onKeyDown={handleKeyUp}
|
onKeyDown={handleKeyUp}
|
||||||
placeholder={inputProps.placeholder ?? 'Select a variable'}
|
placeholder={inputProps.placeholder ?? 'Select a variable'}
|
||||||
|
autoComplete="off"
|
||||||
{...inputProps}
|
{...inputProps}
|
||||||
/>
|
/>
|
||||||
</PopoverAnchor>
|
</PopoverAnchor>
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ export const parseVariables =
|
|||||||
(text: string | undefined): string => {
|
(text: string | undefined): string => {
|
||||||
if (!text || text === '') return ''
|
if (!text || text === '') return ''
|
||||||
// Capture {{variable}} and ${{{variable}}} (variables in template litterals)
|
// Capture {{variable}} and ${{{variable}}} (variables in template litterals)
|
||||||
const pattern = /\{\{([^{}]+)\}\}|\$\{\{([^{}]+)\}\}/g
|
const pattern = /\{\{([^{}]+)\}\}|(\$)\{\{([^{}]+)\}\}/g
|
||||||
return text.replace(
|
return text.replace(
|
||||||
pattern,
|
pattern,
|
||||||
(_, nameInCurlyBraces, nameInTemplateLitteral) => {
|
(_full, nameInCurlyBraces, _dollarSign, nameInTemplateLitteral) => {
|
||||||
|
const dollarSign = _dollarSign ?? ''
|
||||||
const matchedVarName = nameInCurlyBraces ?? nameInTemplateLitteral
|
const matchedVarName = nameInCurlyBraces ?? nameInTemplateLitteral
|
||||||
const variable = variables.find((variable) => {
|
const variable = variables.find((variable) => {
|
||||||
return (
|
return (
|
||||||
@@ -33,19 +34,22 @@ export const parseVariables =
|
|||||||
(options.fieldToParse === 'id' || isDefined(variable.value))
|
(options.fieldToParse === 'id' || isDefined(variable.value))
|
||||||
)
|
)
|
||||||
}) as VariableWithValue | undefined
|
}) as VariableWithValue | undefined
|
||||||
if (!variable) return ''
|
if (!variable) return dollarSign + ''
|
||||||
if (options.fieldToParse === 'id') return variable.id
|
if (options.fieldToParse === 'id') return dollarSign + variable.id
|
||||||
const { value } = variable
|
const { value } = variable
|
||||||
if (options.escapeForJson)
|
if (options.escapeForJson)
|
||||||
return jsonParse(
|
return (
|
||||||
typeof value !== 'string' ? JSON.stringify(value) : value
|
dollarSign +
|
||||||
|
jsonParse(typeof value !== 'string' ? JSON.stringify(value) : value)
|
||||||
)
|
)
|
||||||
const parsedValue = safeStringify(
|
const parsedValue =
|
||||||
|
dollarSign +
|
||||||
|
safeStringify(
|
||||||
options.takeLatestIfList && Array.isArray(value)
|
options.takeLatestIfList && Array.isArray(value)
|
||||||
? value[value.length - 1]
|
? value[value.length - 1]
|
||||||
: value
|
: value
|
||||||
)
|
)
|
||||||
if (!parsedValue) return ''
|
if (!parsedValue) return dollarSign + ''
|
||||||
return parsedValue
|
return parsedValue
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user