Skip to content

Commit

Permalink
SQL-211 refactor render clause
Browse files Browse the repository at this point in the history
  • Loading branch information
milt committed Dec 5, 2023
1 parent 5de04f2 commit 079076c
Showing 1 changed file with 95 additions and 49 deletions.
144 changes: 95 additions & 49 deletions src/com/yetanalytics/lrs_admin_ui/views/reactions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -313,54 +313,73 @@
parent-path
v]))}]])

(defn- render-clause
[mode
reaction-path
{and-clauses :and
or-clauses :or
not-clause :not
:as clause}]
(-> (cond
and-clauses
[:div.clause.boolean.and
[clause-label mode reaction-path :and]
(into [:div.boolean-body]
(map-indexed
(fn [idx clause]
[render-clause
mode
(into reaction-path [:and idx])
clause])
and-clauses))
(when (contains? #{:edit :new} mode)
[add-clause
(conj reaction-path :and)])]
or-clauses
[:div.clause.boolean.or
[clause-label mode reaction-path :or]
(into [:div.boolean-body]
(map-indexed
(fn [idx clause]
[render-clause
mode
(into reaction-path [:or idx])
clause])
or-clauses))
(when (contains? #{:edit :new} mode)
[add-clause
(conj reaction-path :or)])]
(find clause :not)
[:div.clause.boolean.not
[clause-label mode reaction-path :not]
[:div.boolean-body
(when not-clause
[render-clause mode (conj reaction-path :not) not-clause])]
(when (and (contains? #{:edit :new} mode)
(nil? not-clause))
[add-clause
(conj reaction-path :not)])]
:else
(let [{:keys [path op val ref]} clause]
(declare render-clause)

(defn- render-and
[mode reaction-path and-clauses]
[:div.clause.boolean.and
[clause-label mode reaction-path :and]
(into [:div.boolean-body]
(map-indexed
(fn [idx clause]
[render-clause
mode
(into reaction-path [:and idx])
clause])
and-clauses))
(when (contains? #{:edit :new} mode)
[:<>
[add-clause
(conj reaction-path :and)]
[delete-icon
:on-click
(fn []
(dispatch
[:reaction/delete-clause reaction-path]))]])])

(defn- render-or
[mode reaction-path or-clauses]
[:div.clause.boolean.or
[clause-label mode reaction-path :or]
(into [:div.boolean-body]
(map-indexed
(fn [idx clause]
[render-clause
mode
(into reaction-path [:or idx])
clause])
or-clauses))
(when (contains? #{:edit :new} mode)
[:<>
[add-clause
(conj reaction-path :or)]
[delete-icon
:on-click
(fn []
(dispatch
[:reaction/delete-clause reaction-path]))]])])

(defn- render-not
[mode reaction-path not-clause]
[:div.clause.boolean.not
[clause-label mode reaction-path :not]
[:div.boolean-body
(when not-clause
[render-clause mode (conj reaction-path :not) not-clause])]
(when (and (contains? #{:edit :new} mode)
(nil? not-clause))
[add-clause
(conj reaction-path :not)])
(when (contains? #{:edit :new} mode)
[delete-icon
:on-click
(fn []
(dispatch
[:reaction/delete-clause reaction-path]))])])

(defn- render-logic
[mode reaction-path clause]
(let [{:keys [path op val ref]} clause]
[:div.clause.op
[clause-label mode reaction-path :logic]
(cond-> [:dl.op-list
Expand Down Expand Up @@ -402,7 +421,34 @@
[render-ref
mode
(conj reaction-path :ref)
ref]]))]))
ref]]))
(when (contains? #{:edit :new} mode)
[delete-icon
:on-click
(fn []
(dispatch
[:reaction/delete-clause reaction-path]))])]))

(defn- render-clause
[mode
reaction-path
{and-clauses :and
or-clauses :or
not-clause :not
:as clause}]
(-> (cond
and-clauses
[render-and
mode reaction-path and-clauses]
or-clauses
[render-or
mode reaction-path or-clauses]
(find clause :not)
[render-not
mode reaction-path not-clause]
:else
[render-logic
mode reaction-path clause])
(cond->
(contains? #{:edit :new} mode)
(conj [delete-icon
Expand Down

0 comments on commit 079076c

Please sign in to comment.