diff --git a/designer/client/conditions/SelectConditions.tsx b/designer/client/conditions/SelectConditions.tsx index 64a0abd871..27b896ce4f 100644 --- a/designer/client/conditions/SelectConditions.tsx +++ b/designer/client/conditions/SelectConditions.tsx @@ -81,13 +81,22 @@ class SelectConditions extends React.Component { const { data } = this.context; const fields: any = Object.values(this.fieldsForPath(path)); const { conditions = [] } = data; - var conditionsForPath: any[] = []; - + let conditionsForPath: any[] = []; const stringConditions = conditions.filter( (condition) => typeof condition.value === "string" ); + // nested conditions have their own data structure, so need to be considered separately + const nestedConditions = conditions.filter((condition) => + condition.value.conditions + .map((innerCondition) => innerCondition.hasOwnProperty("conditionName")) + .includes(true) + ); const objectConditions = conditions.filter( - (condition) => typeof condition.value !== "string" + (condition) => + typeof condition.value !== "string" && + !nestedConditions.find( + (nestedCondition) => nestedCondition.name === condition.name + ) ); fields.forEach((field) => { @@ -97,6 +106,11 @@ class SelectConditions extends React.Component { conditionsForPath ); this.handleConditions(objectConditions, field.name, conditionsForPath); + this.handleNestedConditions( + nestedConditions, + field.name, + conditionsForPath + ); }); return conditionsForPath; @@ -152,6 +166,33 @@ class SelectConditions extends React.Component { ); var a = ""; } + // loops through nested conditions, checking the referenced condition against the current field + handleNestedConditions( + nestedConditions: ConditionData[], + fieldName: string, + conditionsForPath: any[] + ) { + nestedConditions.forEach((condition) => { + condition.value.conditions.forEach((innerCondition) => { + if (innerCondition.hasOwnProperty("conditionName")) { + let nestedCondition = conditionsForPath.find( + (conditionForPath) => + conditionForPath.name === innerCondition.conditionName + ); + if (nestedCondition) { + conditionsForPath.push(condition); + } + } else { + this.checkAndAddCondition( + condition, + fieldName, + innerCondition.field.name, + conditionsForPath + ); + } + }); + }); + } checkAndAddCondition( conditionToAdd,