Persist trace expansions when changing tab

Fixes #105
This commit is contained in:
Daniel Compton 2017-12-19 21:01:07 +13:00
parent b378cb5f5a
commit 12b211657a
3 changed files with 23 additions and 9 deletions

View File

@ -198,6 +198,21 @@
(save-filter-items (get-in new-db [:traces :filter-items]))
new-db)))
(rf/reg-event-db
:traces/toggle-all-expansions
[(rf/path [:traces :expansions])]
(fn [trace-detail-expansions _]
(-> trace-detail-expansions
(assoc :overrides {})
(update :show-all? not))))
(rf/reg-event-db
:traces/toggle-trace
[(rf/path [:traces :expansions])]
(fn [expansions [_ id]]
(let [showing? (get-in expansions [:overrides id] (:show-all? expansions))]
(update-in expansions [:overrides id] #(if showing? false (not %))))))
;; App DB
(rf/reg-event-db

View File

@ -62,6 +62,11 @@
(fn [db _]
(get-in db [:traces :filter-items])))
(rf/reg-sub
:traces/expansions
(fn [db _]
(get-in db [:traces :expansions])))
(rf/reg-sub
:global/unloading?
(fn [db _]

View File

@ -32,9 +32,7 @@
operation)
#_#__ (js/console.log (devtools/header-api-call tags))]
(list [:tr {:key id
:on-click (fn [ev]
(swap! trace-detail-expansions update-in [:overrides id]
#(if show-row? false (not %))))
:on-click #(rf/dispatch [:traces/toggle-trace id])
:class (str/join " " ["trace--trace"
(case op-type
:sub/create "trace--sub-create"
@ -88,7 +86,7 @@
filter-type (r/atom :contains)
input-error (r/atom false)
categories (r/atom #{:event :sub/run :sub/create :sub/dispose})
trace-detail-expansions (r/atom {:show-all? false :overrides {}})]
trace-detail-expansions (rf/subscribe [:traces/expansions])]
(fn []
(let [toggle-category-fn (fn [category-keys]
(swap! categories #(if (set/superset? % category-keys)
@ -147,11 +145,7 @@
[:th {:style {:padding 0}}
[:button.text-button
{:style {:cursor "pointer"}
:on-click (fn [ev]
;; Always reset expansions
(swap! trace-detail-expansions assoc :overrides {})
;; Then toggle :show-all?
(swap! trace-detail-expansions update :show-all? not))}
:on-click #(rf/dispatch [:traces/toggle-all-expansions])}
(if (:show-all? @trace-detail-expansions) "-" "+")]]
[:th "operations"]
[:th