2
0

(buttons) Allow dynamic buttons from variable

Closes #237
This commit is contained in:
Baptiste Arnaud
2023-02-23 14:44:37 +01:00
parent 84628109d0
commit 2ff6991ca7
28 changed files with 290 additions and 116 deletions

View File

@ -29,7 +29,9 @@ const executeComparison =
if (!comparison?.variableId) return false
const inputValue = (
variables.find((v) => v.id === comparison.variableId)?.value ?? ''
).trim()
)
.toString()
.trim()
const value = parseVariables(variables)(comparison.value).trim()
if (isNotDefined(value) || !comparison.comparisonOperator) return false
return matchComparison(inputValue, comparison.comparisonOperator, value)

View File

@ -25,7 +25,10 @@ export const parseVariables =
if (!variable) return ''
if (options.fieldToParse === 'id') return variable.id
const { value } = variable
if (options.escapeForJson) return jsonParse(value)
if (options.escapeForJson)
return typeof value === 'string'
? jsonParse(value)
: jsonParse(JSON.stringify(value))
const parsedValue = safeStringify(value)
if (!parsedValue) return ''
return parsedValue
@ -45,9 +48,10 @@ export const safeStringify = (val: unknown): string | null => {
export const parseCorrectValueType = (
value: Variable['value']
): string | boolean | number | null | undefined => {
): string | string[] | boolean | number | null | undefined => {
if (value === null) return null
if (value === undefined) return undefined
if (Array.isArray(value)) return value
if (typeof value === 'number') return value
if (value === 'true') return true
if (value === 'false') return false