Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQL-272] Refactor Reactions UI with re-route #96

Merged
merged 26 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
35cc206
Replace reaction-view with mode-specific components
kelvinqian00 Nov 25, 2024
ae5efed
Separate action button bars
kelvinqian00 Nov 25, 2024
82533df
Add sections
kelvinqian00 Nov 25, 2024
af11eae
Refactor ruleset-view
kelvinqian00 Nov 25, 2024
28770e6
Refactor render-conditions
kelvinqian00 Nov 25, 2024
ba405d2
Refactor render-or-edit-condition-name
kelvinqian00 Nov 25, 2024
4210958
Refactor render-clause
kelvinqian00 Nov 25, 2024
caa8b7c
Refactor path, op, val, and ref components
kelvinqian00 Nov 25, 2024
9c2a498
Refactor render-identity-paths
kelvinqian00 Nov 25, 2024
9969f5d
Refactor render-view-or-edit-template
kelvinqian00 Nov 25, 2024
57d26ea
Rename some components
kelvinqian00 Nov 25, 2024
fb87a7e
Refactor out reaction-ruleset-view
kelvinqian00 Nov 25, 2024
36a7215
Remove redundant ruleset-new components
kelvinqian00 Nov 25, 2024
7b3e827
Rename rest of render- components
kelvinqian00 Nov 25, 2024
e02bfca
Even more sectioning
kelvinqian00 Nov 25, 2024
b950816
Properly avoid calling local-display on nils
kelvinqian00 Nov 26, 2024
dc61539
Add new reactions routes + views
kelvinqian00 Nov 26, 2024
db68367
Use new reaction routes
kelvinqian00 Nov 26, 2024
2ac715c
Slight reformatting of route map
kelvinqian00 Nov 26, 2024
df262dd
Refactor cancel-edit into clear-edit
kelvinqian00 Nov 26, 2024
037ec2a
Only dispatch unset-focus when leaving the focus page
kelvinqian00 Nov 26, 2024
2dd5ff5
Delete back-to-list effect
kelvinqian00 Nov 26, 2024
3ad18d0
Delete reaction mode sub
kelvinqian00 Nov 26, 2024
c327279
Add edit-error? sub
kelvinqian00 Nov 26, 2024
626f5c4
Add some TODOs for edit saving
kelvinqian00 Nov 26, 2024
eff8d2b
Merge branch 'admin-jwt-renew-reroute-epic' into re-route-impl-reactions
kelvinqian00 Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 19 additions & 38 deletions src/com/yetanalytics/lrs_admin_ui/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,7 @@
rfns/focus->edit-form)]
{:db (-> db
(assoc ::db/editing-reaction reaction)
prep-edit-reaction-template)
;; unset focus in case we're looking at one
:fx [[:dispatch [:reaction/unset-focus]]]}
prep-edit-reaction-template)}
{:fx [[:dispatch [:notification/notify true
"Cannot edit, reaction not found!"]]]})))

Expand All @@ -1088,9 +1086,7 @@
"verb" {"id" "https://adlnet.gov/expapi/verbs/completed"}}}}]
{:db (-> db
(assoc ::db/editing-reaction reaction)
prep-edit-reaction-template)
;; unset focus in case we're looking at one
:fx [[:dispatch [:reaction/unset-focus]]]})))
prep-edit-reaction-template)})))

(re-frame/reg-event-fx
:reaction/upload-edit
Expand All @@ -1105,8 +1101,7 @@
(if (valid? ::rse/reaction reaction)
{:db (-> db
(assoc ::db/editing-reaction reaction)
prep-edit-reaction-template)
:fx [[:dispatch [:reaction/unset-focus]]]}
prep-edit-reaction-template)}
{:fx [[:dispatch [:notification/notify true
"Cannot upload invalid reaction"]]]}))
{:fx [[:dispatch [:notification/notify true
Expand All @@ -1121,9 +1116,7 @@
rfns/focus->edit-form)]
{:db (-> db
(assoc ::db/editing-reaction reaction)
prep-edit-reaction-template)
;; unset focus in case we're looking at one
:fx [[:dispatch [:reaction/unset-focus]]]}))))
prep-edit-reaction-template)}))))

(re-frame/reg-event-fx
:reaction/server-error
Expand Down Expand Up @@ -1160,21 +1153,24 @@
[:notification/notify true
"Cannot save invalid reaction."]]]}))))

(defn- cancel-edit
[db]
(dissoc db
::db/editing-reaction
::db/editing-reaction-template-json
::db/editing-reaction-template-errors))

(re-frame/reg-event-fx
:reaction/save-edit-success
global-interceptors
(fn [{:keys [db]} [_ {:keys [reactionId]}]]
{:db (-> db
cancel-edit
(assoc ::db/reaction-focus reactionId))
:fx [[:dispatch [:reaction/load-reactions]]]}))
(fn [_ [_ {:keys [reactionId]}]]
;; TODO: Only reload the reaction being updated, rather than all of them.
;; TODO: Display some sort of loading screen before reaction is updated
;; (for slow connection).
{:fx [[:dispatch [:reaction/load-reactions]]
[:dispatch [::re-route/navigate :reactions/focus {:id reactionId}]]]}))

(re-frame/reg-event-db
:reaction/clear-edit
global-interceptors
(fn [db _]
(dissoc db
::db/editing-reaction
::db/editing-reaction-template-json
::db/editing-reaction-template-errors)))

;; TODO: :reaction/save-edit-fail

Expand Down Expand Up @@ -1214,24 +1210,9 @@
global-interceptors
(fn [_ _]
{:fx [[:dispatch [:reaction/load-reactions]]
[:dispatch [:reaction/back-to-list]]
[:dispatch [:notification/notify false
"Reaction Deleted"]]]}))

(re-frame/reg-event-db
:reaction/cancel-edit
global-interceptors
(fn [db _]
(cancel-edit db)))

(re-frame/reg-event-fx
:reaction/back-to-list
global-interceptors
(fn [_ _]
;; TODO: Whatever new needs to clear
{:fx [[:dispatch [:reaction/unset-focus]]
[:dispatch [:reaction/cancel-edit]]]}))

(re-frame/reg-event-db
:reaction/edit-title
global-interceptors
Expand Down
64 changes: 44 additions & 20 deletions src/com/yetanalytics/lrs_admin_ui/routes.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
[com.yetanalytics.lrs-admin-ui.views.credentials :refer [credentials]]
[com.yetanalytics.lrs-admin-ui.views.data-management :refer [data-management]]
[com.yetanalytics.lrs-admin-ui.views.not-found :refer [not-found]]
[com.yetanalytics.lrs-admin-ui.views.reactions :refer [reactions]]
[com.yetanalytics.lrs-admin-ui.views.status :refer [status]]
[com.yetanalytics.lrs-admin-ui.views.update-password :refer [update-password]]))
[com.yetanalytics.lrs-admin-ui.views.update-password :refer [update-password]]
[com.yetanalytics.lrs-admin-ui.views.reactions :refer [reactions-list
reaction-focus
reaction-edit
reaction-new]]))

(defn routes [{:keys [proxy-path
enable-admin-delete-actor
Expand All @@ -30,15 +33,13 @@
["/accounts"
{:name :accounts
:view accounts
:controllers [{:start
(fn [_]
(dispatch [:accounts/load-accounts]))}]}]
:controllers [{:start (fn [_]
(dispatch [:accounts/load-accounts]))}]}]
["/accounts/password"
{:name :update-password
:view update-password
:controllers [{:stop
(fn [_]
(dispatch [:update-password/clear]))}]}]
:controllers [{:stop (fn [_]
(dispatch [:update-password/clear]))}]}]
["/browser"
{:name :browser
:view browser}]
Expand All @@ -53,16 +54,39 @@
(conj ["/status"
{:name :status
:view status
:controllers [{:start
(fn [_]
(dispatch [:status/get-all-data]))}]}])
;; TODO: Add `/reactions/new`, `/reactions/view`, and `/reactions/edit`
;; routes for their respective pages.
:controllers [{:start (fn [_]
(dispatch [:status/get-all-data]))}]}])
enable-reactions
(conj ["/reactions"
{:name :reactions
:view reactions
:controllers [{:start
(fn [_]
(dispatch [:reaction/back-to-list])
(dispatch [:reaction/load-reactions]))}]}])))
(conj
["/reactions"
{:name :reactions
:view reactions-list
:controllers [{:start (fn [_]
(dispatch [:reaction/load-reactions]))}]}]
["/reactions/new"
{:name :reactions/new
:view reaction-new
:controllers [{:start (fn [_]
(dispatch [:reaction/new]))
:stop (fn [_]
(dispatch [:reaction/clear-edit]))}]}]
["/reactions/:id/view"
{:name :reactions/focus
:view reaction-focus
:parameters {:path [:id]}
:controllers [{:identity (fn [params]
(get-in params [:path-params :id]))
:start (fn [id]
(dispatch [:reaction/set-focus id]))
:stop (fn [_]
(dispatch [:reaction/unset-focus]))}]}]
["/reactions/:id/edit"
{:name :reactions/edit
:view reaction-edit
:parameters {:path [:id]}
:controllers [{:identity (fn [params]
(get-in params [:path-params :id]))
:start (fn [id]
(dispatch [:reaction/edit id]))
:stop (fn [_]
(dispatch [:reaction/clear-edit]))}]}])))
22 changes: 8 additions & 14 deletions src/com/yetanalytics/lrs_admin_ui/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,6 @@

;; Reactions

;; Are we viewing the list, an individual activiy, editing or creating?
(reg-sub
:reaction/mode
:<- [:reaction/editing]
:<- [:reaction/focus-id]
(fn [[editing
focus]]
(cond
editing (if (:id editing)
:edit
:new)
focus :focus
:else :list)))

(reg-sub
:reaction/enabled?
(fn [db _]
Expand Down Expand Up @@ -516,6 +502,14 @@
(fn [emap [_ in-path]]
(get emap in-path)))

(reg-sub
:reaction/edit-error?
:<- [:reaction/edit-spec-errors]
:<- [:reaction/edit-template-errors]
(fn [[spec-errors template-errors] _]
(boolean (or (some? spec-errors)
(seq template-errors)))))

;; Dialog

(reg-sub
Expand Down
Loading
Loading