mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-22 19:39:01 -05:00
fix: segment evaluation fix (#3043)
This commit is contained in:
@@ -680,20 +680,31 @@ export const evaluateSegment = async (
|
||||
return false;
|
||||
}
|
||||
|
||||
// We first evaluate all `and` conditions consecutively
|
||||
let intermediateResults: boolean[] = [];
|
||||
|
||||
// Given that the first filter in every group/sub-group always has a connector value of "null",
|
||||
// we initialize the finalResult with the result of the first filter.
|
||||
|
||||
let finalResult = resultPairs[0].result;
|
||||
let currentAndGroupResult = resultPairs[0].result;
|
||||
|
||||
for (let i = 1; i < resultPairs.length; i++) {
|
||||
const { result, connector } = resultPairs[i];
|
||||
|
||||
if (connector === "and") {
|
||||
finalResult = finalResult && result;
|
||||
currentAndGroupResult = currentAndGroupResult && result;
|
||||
} else if (connector === "or") {
|
||||
finalResult = finalResult || result;
|
||||
intermediateResults.push(currentAndGroupResult);
|
||||
currentAndGroupResult = result;
|
||||
}
|
||||
}
|
||||
// Push the final `and` group result
|
||||
intermediateResults.push(currentAndGroupResult);
|
||||
|
||||
// Now we can evaluate the `or` conditions
|
||||
let finalResult = intermediateResults[0];
|
||||
for (let i = 1; i < intermediateResults.length; i++) {
|
||||
finalResult = finalResult || intermediateResults[i];
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user