From 506fe003d1c25b3f9b4b0ec4443db4aff7efb668 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 2 Mar 2023 11:16:01 +0100 Subject: [PATCH] :bug: (condition) Fix contains not working with lists --- .../logic/condition/api/utils/executeCondition.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts b/apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts index 902b2a711..49a4b8e01 100644 --- a/apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts +++ b/apps/viewer/src/features/blocks/logic/condition/api/utils/executeCondition.ts @@ -32,16 +32,17 @@ export const executeCondition = ( const executeComparison = (variables: Variable[]) => (comparison: Comparison) => { if (!comparison?.variableId) return false - const inputValue = ( + const inputValue = variables.find((v) => v.id === comparison.variableId)?.value ?? '' - ) - .toString() - .trim() - const value = parseVariables(variables)(comparison.value).trim() + const value = parseVariables(variables)(comparison.value) if (isNotDefined(value)) return false switch (comparison.comparisonOperator) { 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: { return inputValue === value @@ -50,9 +51,11 @@ const executeComparison = return inputValue !== value } case ComparisonOperators.GREATER: { + if (typeof inputValue !== 'string') return false return parseFloat(inputValue) > parseFloat(value) } case ComparisonOperators.LESS: { + if (typeof inputValue !== 'string') return false return parseFloat(inputValue) < parseFloat(value) } case ComparisonOperators.IS_SET: {