From a8823c3ed0ed3c0cd75abf27a5a1c3f2626d8941 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Tue, 9 May 2023 10:52:21 +0000 Subject: [PATCH] fix(filters/continue): cover multiple conditions --- .../src/apps/filter/actions/continue/index.ts | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/apps/filter/actions/continue/index.ts b/packages/backend/src/apps/filter/actions/continue/index.ts index 39f77afde0..1e264f720e 100644 --- a/packages/backend/src/apps/filter/actions/continue/index.ts +++ b/packages/backend/src/apps/filter/actions/continue/index.ts @@ -10,7 +10,7 @@ type TGroupItem = { type TGroup = Record<'and', TGroupItem[]>; const isEqual = (a: string, b: string) => a === b; -const isNotEqual = (a: string, b: string) => !isEqual(a, b) +const isNotEqual = (a: string, b: string) => !isEqual(a, b); const isGreaterThan = (a: string, b: string) => Number(a) > Number(b); const isLessThan = (a: string, b: string) => Number(a) < Number(b); const isGreaterThanOrEqual = (a: string, b: string) => Number(a) >= Number(b); @@ -18,6 +18,36 @@ const isLessThanOrEqual = (a: string, b: string) => Number(a) <= Number(b); const contains = (a: string, b: string) => a.includes(b); const doesNotContain = (a: string, b: string) => !contains(a, b); +const shouldContinue = (orGroups: TGroup[]) => { + let atLeastOneGroupMatches = false; + + for (const group of orGroups) { + let groupMatches = true; + + for (const condition of group.and) { + const conditionMatches = operate( + condition.operator, + condition.key, + condition.value + ); + + if (!conditionMatches) { + groupMatches = false; + + break; + } + } + + if (groupMatches) { + atLeastOneGroupMatches = true; + + break; + } + } + + return atLeastOneGroupMatches; +} + type TOperatorFunc = (a: string, b: string) => boolean; type TOperators = { @@ -66,7 +96,7 @@ export default defineAction({ return groups; }, []); - if (matchingGroups.length === 0) { + if (!shouldContinue(orGroups)) { $.execution.exit(); }