From 5de04f26411891cfec2c9b59652c434f5eadd55d Mon Sep 17 00:00:00 2001 From: Milton Reder Date: Tue, 5 Dec 2023 11:03:02 -0500 Subject: [PATCH] SQL-211 allow clause type selection for any clause --- .../yetanalytics/lrs_admin_ui/handlers.cljs | 18 +++++++++---- .../lrs_admin_ui/views/reactions.cljs | 27 ++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/com/yetanalytics/lrs_admin_ui/handlers.cljs b/src/com/yetanalytics/lrs_admin_ui/handlers.cljs index c51d83a5..b7eca72e 100644 --- a/src/com/yetanalytics/lrs_admin_ui/handlers.cljs +++ b/src/com/yetanalytics/lrs_admin_ui/handlers.cljs @@ -1284,9 +1284,9 @@ :path []}))))))) (re-frame/reg-event-db - :reaction/and-or-toggle + :reaction/set-clause-type global-interceptors - (fn [db [_ clause-path bool-key]] + (fn [db [_ clause-path clause-type]] ;; #{"and" "or" "not" "logic"} (let [full-path (into [::db/editing-reaction] clause-path) {and-clauses :and @@ -1294,9 +1294,17 @@ :as clause} (get-in db full-path)] (assoc-in db full-path (-> clause - (dissoc :and :or) - (assoc bool-key (or and-clauses - or-clauses))))))) + ;; preserve sort idx if there + (select-keys [:sort-idx]) + (merge + (case clause-type + "and" {:and (or or-clauses [])} + "or" {:or (or and-clauses [])} + "not" {:not nil} + "logic" {:path [] + :op "eq" + :val ""}))))))) + (re-frame/reg-event-db :reaction/set-condition-name global-interceptors diff --git a/src/com/yetanalytics/lrs_admin_ui/views/reactions.cljs b/src/com/yetanalytics/lrs_admin_ui/views/reactions.cljs index 35fdcb50..7f1c21d1 100644 --- a/src/com/yetanalytics/lrs_admin_ui/views/reactions.cljs +++ b/src/com/yetanalytics/lrs_admin_ui/views/reactions.cljs @@ -250,26 +250,32 @@ (conj ref-path :path) path]]]) -(defn- and-or-label +(defn- clause-label [mode reaction-path - bool-key] + type-key] [:div.boolean-label (if (contains? #{:edit :new} mode) [:select - {:value (name bool-key) + {:value (name type-key) :on-change (fn [e] - (dispatch [:reaction/and-or-toggle + (dispatch [:reaction/set-clause-type reaction-path - (keyword (fns/ps-event-val e))]))} + (fns/ps-event-val e)]))} [:option {:value "and"} "AND"] [:option {:value "or"} - "OR"]] - (case bool-key :and "AND" :or "OR"))]) + "OR"] + [:option + {:value "not"} + "NOT"] + [:option + {:value "logic"} + "Logic"]] + (case type-key :and "AND" :or "OR" :not "NOT" ""))]) (defn- delete-icon [& {:keys [on-click] @@ -317,7 +323,7 @@ (-> (cond and-clauses [:div.clause.boolean.and - [and-or-label mode reaction-path :and] + [clause-label mode reaction-path :and] (into [:div.boolean-body] (map-indexed (fn [idx clause] @@ -331,7 +337,7 @@ (conj reaction-path :and)])] or-clauses [:div.clause.boolean.or - [and-or-label mode reaction-path :or] + [clause-label mode reaction-path :or] (into [:div.boolean-body] (map-indexed (fn [idx clause] @@ -345,7 +351,7 @@ (conj reaction-path :or)])] (find clause :not) [:div.clause.boolean.not - [:div.boolean-label "NOT"] + [clause-label mode reaction-path :not] [:div.boolean-body (when not-clause [render-clause mode (conj reaction-path :not) not-clause])] @@ -356,6 +362,7 @@ :else (let [{:keys [path op val ref]} clause] [:div.clause.op + [clause-label mode reaction-path :logic] (cond-> [:dl.op-list [:dt "Path"] [:dd