SearchKit - Fix reloading a search with an OR group in the WHERE clause
authorColeman Watts <coleman@civicrm.org>
Sun, 11 Jul 2021 19:43:20 +0000 (15:43 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 11 Jul 2021 19:43:20 +0000 (15:43 -0400)
Fixes dev/report#71

ext/search_kit/ang/crmSearchAdmin/crmSearchClause.component.js

index f6409c30ee2601fe027ee4270e1b345c7a49309d..4d2c8072b63ecf0b91ec3eb5c230f6234b903db6 100644 (file)
@@ -34,6 +34,7 @@
         _.each(ctrl.clauses, updateOperators);
       };
 
+      // Return a list of operators allowed for the field in a given clause
       this.getOperators = function(clause) {
         var field = ctrl.getField(clause[0]);
         if (!field || !field.operators) {
         return ctrl.operators[opKey];
       };
 
+      // Ensures a clause is using an operator that is allowed for the field
       function updateOperators(clause) {
-        if (!ctrl.skip && (!clause[1] || !_.includes(_.pluck(ctrl.getOperators(clause), 'key'), clause[1]))) {
+        // Recurse into AND/OR/NOT groups
+        if (ctrl.conjunctions[clause[0]]) {
+          _.each(clause[1], updateOperators);
+        }
+        else if (!ctrl.skip && (!clause[1] || !_.includes(_.pluck(ctrl.getOperators(clause), 'key'), clause[1]))) {
           clause[1] = ctrl.getOperators(clause)[0].key;
           ctrl.changeClauseOperator(clause);
         }