Skip to content

Commit

Permalink
SQL-211 allow clause type selection for any clause
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Dec 5, 2023
1 parent 1d9129b commit 5de04f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
18 changes: 13 additions & 5 deletions src/com/yetanalytics/lrs_admin_ui/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,19 +1284,27 @@
: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
or-clauses :or
: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
Expand Down
27 changes: 17 additions & 10 deletions src/com/yetanalytics/lrs_admin_ui/views/reactions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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])]
Expand All @@ -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
Expand Down

0 comments on commit 5de04f2

Please sign in to comment.