Skip to content

Commit

Permalink
馃悰 (condition) Improve contains/not contains on list input
Browse files Browse the repository at this point in the history
Closes #1430
  • Loading branch information
baptisteArno committed Apr 11, 2024
1 parent d194fbe commit cae7be4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/bot-engine/blocks/logic/condition/executeCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const executeComparison =
if (isNotDefined(comparison.comparisonOperator)) return false
switch (comparison.comparisonOperator) {
case ComparisonOperators.CONTAINS: {
if (Array.isArray(inputValue)) {
const equal = (a: string | null, b: string | null) => {
if (typeof a === 'string' && typeof b === 'string')
return a.normalize() === b.normalize()
return a !== b
}
return compare(equal, inputValue, value, 'some')
}
const contains = (a: string | null, b: string | null) => {
if (b === '' || !b || !a) return false
return a
Expand All @@ -43,6 +51,14 @@ const executeComparison =
return compare(contains, inputValue, value, 'some')
}
case ComparisonOperators.NOT_CONTAINS: {
if (Array.isArray(inputValue)) {
const notEqual = (a: string | null, b: string | null) => {
if (typeof a === 'string' && typeof b === 'string')
return a.normalize() !== b.normalize()
return a !== b
}
return compare(notEqual, inputValue, value, 'some')
}
const notContains = (a: string | null, b: string | null) => {
if (b === '' || !b || !a) return true
return !a
Expand Down

0 comments on commit cae7be4

Please sign in to comment.