2
0

🐛 (condition) Fix contains not working with lists

This commit is contained in:
Baptiste Arnaud
2023-03-02 11:16:01 +01:00
parent 58371879aa
commit 506fe003d1

View File

@ -32,16 +32,17 @@ export const executeCondition = (
const executeComparison = const executeComparison =
(variables: Variable[]) => (comparison: Comparison) => { (variables: Variable[]) => (comparison: Comparison) => {
if (!comparison?.variableId) return false if (!comparison?.variableId) return false
const inputValue = ( const inputValue =
variables.find((v) => v.id === comparison.variableId)?.value ?? '' variables.find((v) => v.id === comparison.variableId)?.value ?? ''
) const value = parseVariables(variables)(comparison.value)
.toString()
.trim()
const value = parseVariables(variables)(comparison.value).trim()
if (isNotDefined(value)) return false if (isNotDefined(value)) return false
switch (comparison.comparisonOperator) { switch (comparison.comparisonOperator) {
case ComparisonOperators.CONTAINS: { case ComparisonOperators.CONTAINS: {
return inputValue.toLowerCase().includes(value.toLowerCase()) const normalizeString = (value: string) => value.toLowerCase().trim()
const contains = (inputValue: string) =>
normalizeString(inputValue).includes(normalizeString(value))
if (typeof inputValue === 'string') return contains(inputValue)
return inputValue.some(contains)
} }
case ComparisonOperators.EQUAL: { case ComparisonOperators.EQUAL: {
return inputValue === value return inputValue === value
@ -50,9 +51,11 @@ const executeComparison =
return inputValue !== value return inputValue !== value
} }
case ComparisonOperators.GREATER: { case ComparisonOperators.GREATER: {
if (typeof inputValue !== 'string') return false
return parseFloat(inputValue) > parseFloat(value) return parseFloat(inputValue) > parseFloat(value)
} }
case ComparisonOperators.LESS: { case ComparisonOperators.LESS: {
if (typeof inputValue !== 'string') return false
return parseFloat(inputValue) < parseFloat(value) return parseFloat(inputValue) < parseFloat(value)
} }
case ComparisonOperators.IS_SET: { case ComparisonOperators.IS_SET: {