Fix indexing through match ids
This commit is contained in:
parent
08716872f4
commit
0f3ec5daa1
|
@ -5,7 +5,7 @@
|
|||
(defn init-db []
|
||||
(let [panel-width% (localstorage/get "panel-width-ratio" 0.35)
|
||||
show-panel? (localstorage/get "show-panel" false)
|
||||
selected-tab (localstorage/get "selected-tab" :event)
|
||||
selected-tab (localstorage/get "selected-tab" :app-db)
|
||||
filter-items (localstorage/get "filter-items" [])
|
||||
app-db-paths (into (sorted-map) (localstorage/get "app-db-paths" {}))
|
||||
json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{})
|
||||
|
|
|
@ -122,7 +122,8 @@
|
|||
(fn [db _]
|
||||
(-> db
|
||||
(assoc-in [:settings :paused?] false)
|
||||
(assoc-in [:epochs :current-epoch-index] nil))))
|
||||
(assoc-in [:epochs :current-epoch-index] nil)
|
||||
(assoc-in [:epochs :current-epoch-id] nil))))
|
||||
|
||||
(rf/reg-event-db
|
||||
:settings/set-number-of-retained-epochs
|
||||
|
@ -228,7 +229,7 @@
|
|||
;; if existing, remove prior filter for :slower-than
|
||||
;; TODO: rework how time filters are used.
|
||||
(let [filter-items (if (and (= :slower-than filter-type)
|
||||
(some #(= filter-type (:filter-type %)) filter-items))
|
||||
(some #(= filter-type (:filter-type %)) filter-items))
|
||||
(remove #(= :slower-than (:filter-type %)) filter-items)
|
||||
filter-items)]
|
||||
;; add new filter
|
||||
|
@ -373,29 +374,29 @@
|
|||
paths))
|
||||
|
||||
#_(rf/reg-event-db
|
||||
:app-db/remove-path
|
||||
(fn [db [_ path]]
|
||||
(let [new-db (update-in db [:app-db :paths] #(remove (fn [p] (= p path)) %))]
|
||||
(localstorage/save! "app-db-paths" (get-in new-db [:app-db :paths]))
|
||||
;; TODO: remove from json-ml expansions too.
|
||||
new-db)))
|
||||
:app-db/remove-path
|
||||
(fn [db [_ path]]
|
||||
(let [new-db (update-in db [:app-db :paths] #(remove (fn [p] (= p path)) %))]
|
||||
(localstorage/save! "app-db-paths" (get-in new-db [:app-db :paths]))
|
||||
;; TODO: remove from json-ml expansions too.
|
||||
new-db)))
|
||||
|
||||
#_(rf/reg-event-db
|
||||
:app-db/add-path
|
||||
(fn [db _]
|
||||
(let [search-string (get-in db [:app-db :search-string])
|
||||
path (try
|
||||
(when-not (str/blank? search-string)
|
||||
(cljs.reader/read-string (str "[" search-string "]")))
|
||||
(catch :default e
|
||||
nil))]
|
||||
(if (some? path)
|
||||
(do (localstorage/save! "app-db-paths" (cons path (get-in db [:app-db :paths])))
|
||||
(rf/dispatch [:app-db/toggle-expansion [path]])
|
||||
(-> db
|
||||
(update-in [:app-db :paths] #(cons path %))
|
||||
(assoc-in [:app-db :search-string] "")))
|
||||
db))))
|
||||
:app-db/add-path
|
||||
(fn [db _]
|
||||
(let [search-string (get-in db [:app-db :search-string])
|
||||
path (try
|
||||
(when-not (str/blank? search-string)
|
||||
(cljs.reader/read-string (str "[" search-string "]")))
|
||||
(catch :default e
|
||||
nil))]
|
||||
(if (some? path)
|
||||
(do (localstorage/save! "app-db-paths" (cons path (get-in db [:app-db :paths])))
|
||||
(rf/dispatch [:app-db/toggle-expansion [path]])
|
||||
(-> db
|
||||
(update-in [:app-db :paths] #(cons path %))
|
||||
(assoc-in [:app-db :search-string] "")))
|
||||
db))))
|
||||
|
||||
(rf/reg-event-db
|
||||
:app-db/search-string
|
||||
|
@ -433,25 +434,45 @@
|
|||
|
||||
;;;
|
||||
|
||||
(defn first-match-id
|
||||
[m]
|
||||
(-> m first :id))
|
||||
|
||||
(rf/reg-event-db
|
||||
:epochs/update-epochs
|
||||
[(rf/path [:epochs :matches])]
|
||||
(fn [matches [_ rt]]
|
||||
(:matches rt)))
|
||||
[(rf/path [:epochs])]
|
||||
(fn [epochs [_ rt]]
|
||||
(let [matches (:matches rt)]
|
||||
(assoc epochs
|
||||
:matches matches
|
||||
:matches-by-id (into {} (map (juxt first-match-id identity)) matches)
|
||||
:match-ids (mapv first-match-id matches)))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:epochs/previous-epoch
|
||||
[(rf/path [:epochs :current-epoch-index])]
|
||||
(fn [ctx _]
|
||||
{:db ((fnil dec 0) (:db ctx))
|
||||
:dispatch [:settings/pause]}))
|
||||
[(rf/path [:epochs])]
|
||||
(fn [{:keys [db]} _]
|
||||
(if-some [current-id (:current-epoch-id db)]
|
||||
(let [match-ids (:match-ids db)
|
||||
match-array-index (utils/find-index-in-vec (fn [x] (= current-id x)) match-ids)
|
||||
new-id (nth match-ids (dec match-array-index))]
|
||||
{:db (assoc db :current-epoch-id new-id)
|
||||
:dispatch [:settings/pause]})
|
||||
{:db (assoc db :current-epoch-id (nth (:match-ids db) (- (count (:match-ids db)) 2)))
|
||||
:dispatch [:settings/pause]})))
|
||||
|
||||
(rf/reg-event-fx
|
||||
:epochs/next-epoch
|
||||
[(rf/path [:epochs :current-epoch-index])]
|
||||
(fn [ctx _]
|
||||
{:db ((fnil inc 0) (:db ctx))
|
||||
:dispatch [:settings/pause]}))
|
||||
[(rf/path [:epochs])]
|
||||
(fn [{:keys [db]} _]
|
||||
(if-some [current-id (:current-epoch-id db)]
|
||||
(let [match-ids (:match-ids db)
|
||||
match-array-index (utils/find-index-in-vec (fn [x] (= current-id x)) match-ids)
|
||||
new-id (nth match-ids (inc match-array-index))]
|
||||
{:db (assoc db :current-epoch-id new-id)
|
||||
:dispatch [:settings/pause]})
|
||||
{:db (assoc db :current-epoch-id (last (:match-ids db)))
|
||||
:dispatch [:settings/pause]})))
|
||||
|
||||
(rf/reg-event-db
|
||||
:traces/update-traces
|
||||
|
|
|
@ -176,10 +176,13 @@
|
|||
(rf/reg-sub
|
||||
:epochs/current-match
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs _]
|
||||
(let [matches (:matches epochs)
|
||||
current-index (:current-epoch-index epochs)
|
||||
match (nth matches (+ (count matches) (or current-index 0)) (last matches))]
|
||||
:<- [:epochs/match-ids]
|
||||
(fn [[epochs match-ids] _]
|
||||
(let [current-id (:current-epoch-id epochs)
|
||||
match (cond
|
||||
(nil? current-id) (last (:matches epochs))
|
||||
(< current-id (first match-ids)) (first (:matches epochs))
|
||||
:else (get (:matches-by-id epochs) current-id))]
|
||||
match)))
|
||||
|
||||
(rf/reg-sub
|
||||
|
@ -207,11 +210,16 @@
|
|||
(:current-epoch-index epochs)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/event-position
|
||||
:<- [:epochs/current-event-index]
|
||||
:<- [:epochs/number-of-matches]
|
||||
(fn [[current total]]
|
||||
(str current " of " total)))
|
||||
:epochs/current-epoch-id
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs _]
|
||||
(:current-epoch-id epochs)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/match-ids
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs]
|
||||
(:match-ids epochs)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/beginning-trace-id
|
||||
|
@ -227,18 +235,21 @@
|
|||
|
||||
(rf/reg-sub
|
||||
:epochs/older-epochs-available?
|
||||
:<- [:epochs/current-event-index]
|
||||
:<- [:epochs/number-of-matches]
|
||||
(fn [[current total]]
|
||||
(pos? (+ current total -1))))
|
||||
:<- [:epochs/current-epoch-id]
|
||||
:<- [:epochs/match-ids]
|
||||
(fn [[current ids]]
|
||||
(and (pos? (count ids))
|
||||
(or (nil? current)
|
||||
(> current (nth ids 0))))))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/newer-epochs-available?
|
||||
:<- [:epochs/current-event-index]
|
||||
:<- [:epochs/number-of-matches]
|
||||
(fn [[current total]]
|
||||
(and (not (zero? current))
|
||||
(some? current))))
|
||||
:<- [:epochs/current-epoch-id]
|
||||
:<- [:epochs/match-ids]
|
||||
(fn [[current ids]]
|
||||
(and (pos? (count ids))
|
||||
(some? current)
|
||||
(< current (utils/last-in-vec ids)))))
|
||||
|
||||
;;
|
||||
|
||||
|
@ -378,9 +389,6 @@
|
|||
(frequencies (map :id raw)))
|
||||
|
||||
output (map (fn [sub] (assoc sub :run-times (get run-multiple? (:id sub)))) raw)]
|
||||
(js/console.log "Output" output)
|
||||
(js/console.log "Traces" traces)
|
||||
(js/console.log "rerun" re-run)
|
||||
(sort-by identity subscription-comparator output))))
|
||||
|
||||
(rf/reg-sub
|
||||
|
|
|
@ -13,11 +13,15 @@
|
|||
[rc/label :label (str "Ending " (prn-str @(rf/subscribe [:epochs/ending-trace-id])))]
|
||||
|
||||
[rc/label :label "Epochs"]
|
||||
(for [match (:matches @(rf/subscribe [:epochs/epoch-root]))]
|
||||
^{:key (:id (first match))}
|
||||
[rc/v-box
|
||||
:style {:border "1px solid black"}
|
||||
:children (doall (map (fn [event] [rc/label :label (prn-str event)]) (metam/summarise-match match)))
|
||||
])
|
||||
(let [current-match @(rf/subscribe [:epochs/current-match])]
|
||||
(for [match (:matches @(rf/subscribe [:epochs/epoch-root]))]
|
||||
^{:key (:id (first match))}
|
||||
[rc/v-box
|
||||
:style {:border "1px solid black"
|
||||
:font-weight (if (= current-match match)
|
||||
"bold"
|
||||
"normal")}
|
||||
:children (doall (map (fn [event] [rc/label :label (prn-str event)]) (metam/summarise-match match)))
|
||||
]))
|
||||
]]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue