Add setting to ignore events/epochs

This commit is contained in:
Daniel Compton 2018-01-26 17:48:19 +13:00
parent db14e69f17
commit 022a070fb8
6 changed files with 71 additions and 26 deletions

View File

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. This change
* Setting to control how many epochs are retained * Setting to control how many epochs are retained
* Setting to reset all epochs * Setting to reset all epochs
* Setting to ignore epochs
### Changed ### Changed

View File

@ -11,6 +11,7 @@
json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{}) json-ml-paths (localstorage/get "app-db-json-ml-expansions" #{})
external-window? (localstorage/get "external-window?" false) external-window? (localstorage/get "external-window?" false)
using-trace? (localstorage/get "using-trace?" true) using-trace? (localstorage/get "using-trace?" true)
ignored-events (localstorage/get "ignored-events" {})
num-epochs (localstorage/get "retained-epochs" 5) num-epochs (localstorage/get "retained-epochs" 5)
categories (localstorage/get "categories" #{:event :sub/run :sub/create :sub/dispose})] categories (localstorage/get "categories" #{:event :sub/run :sub/create :sub/dispose})]
(when using-trace? (when using-trace?
@ -18,6 +19,7 @@
(rf/dispatch [:settings/panel-width% panel-width%]) (rf/dispatch [:settings/panel-width% panel-width%])
(rf/dispatch [:settings/show-panel? show-panel?]) (rf/dispatch [:settings/show-panel? show-panel?])
(rf/dispatch [:settings/selected-tab selected-tab]) (rf/dispatch [:settings/selected-tab selected-tab])
(rf/dispatch [:settings/set-ignored-events ignored-events])
(rf/dispatch [:settings/set-number-of-retained-epochs num-epochs]) (rf/dispatch [:settings/set-number-of-retained-epochs num-epochs])
(when external-window? (when external-window?
(rf/dispatch [:global/launch-external])) (rf/dispatch [:global/launch-external]))

View File

@ -19,6 +19,7 @@
(defonce traces (r/atom [])) (defonce traces (r/atom []))
(defonce total-traces (r/atom 0)) (defonce total-traces (r/atom 0))
(defonce number-of-epochs-to-retain (atom default-number-of-epochs-to-retain)) (defonce number-of-epochs-to-retain (atom default-number-of-epochs-to-retain))
(defonce events-to-ignore (atom #{}))
(defn log-trace? [trace] (defn log-trace? [trace]
(let [render-operation? (or (= (:op-type trace) :render) (let [render-operation? (or (= (:op-type trace) :render)
@ -46,12 +47,15 @@
(do (reset! total-traces 0) (do (reset! total-traces 0)
(into [] new2)))) (into [] new2))))
new)))) new))))
;; TODO: there is a bit of double handling here, that will be cleaned up ;; TODO: there is a bit of double handling here with retaining the last n epochs,
;; when the epoch parsing is refactored. ;; that will be cleaned up when the epoch parsing is refactored.
(let [epochs (metam/parse-traces @traces) (let [matches (:matches (metam/parse-traces @traces))
retained-epochs (take-last @number-of-epochs-to-retain (:matches epochs)) matches (remove (fn [match]
(let [event (get-in (metam/matched-event match) [:tags :event])]
(contains? @events-to-ignore (first event)))) matches)
retained-epochs (take-last @number-of-epochs-to-retain matches)
first-id-to-retain (:id (ffirst retained-epochs)) first-id-to-retain (:id (ffirst retained-epochs))
new-traces (into [] (drop-while #(< (:id %) first-id-to-retain)) @traces)] new-traces (into [] (drop-while #(< (:id %) first-id-to-retain)) @traces)]
(reset! traces new-traces) (reset! traces new-traces)
(reset! total-traces (count new-traces)) (reset! total-traces (count new-traces))
(rf/dispatch [:traces/update-traces new-traces]) (rf/dispatch [:traces/update-traces new-traces])
@ -71,6 +75,10 @@
m) m)
(dissoc m k))) (dissoc m k)))
(defn read-string-maybe [s]
(try (cljs.tools.reader.edn/read-string s)
(catch :default e
nil)))
(rf/reg-event-db (rf/reg-event-db
:settings/panel-width% :settings/panel-width%
@ -154,6 +162,38 @@
(localstorage/save! "retained-epochs" num) (localstorage/save! "retained-epochs" num)
(assoc-in db [:settings :number-of-epochs] num)))) (assoc-in db [:settings :number-of-epochs] num))))
(def ignored-event-mw
[(rf/path [:settings :ignored-events]) (rf/after #(localstorage/save! "ignored-events" %)) (rf/after #(reset! events-to-ignore (->> % vals (map :event-id) set)))])
(rf/reg-event-db
:settings/add-ignored-event
ignored-event-mw
(fn [ignored-events _]
(let [id (random-uuid)]
(assoc ignored-events id {:id id :event-str "" :event-id nil :sort (js/Date.now)}))))
(rf/reg-event-db
:settings/remove-ignored-event
ignored-event-mw
(fn [ignored-events [_ id]]
(dissoc ignored-events id)))
(rf/reg-event-db
:settings/update-ignored-event
ignored-event-mw
(fn [ignored-events [_ id event-str]]
;; TODO: this won't inform users if they type bad strings in.
(let [event (read-string-maybe event-str)]
(-> ignored-events
(assoc-in [id :event-str] event-str)
(update-in [id :event-id] (fn [old-event] (if event event old-event)))))))
(rf/reg-event-db
:settings/set-ignored-events
ignored-event-mw
(fn [_ [_ ignored-events]]
ignored-events))
(rf/reg-event-db (rf/reg-event-db
:settings/low-level-trace :settings/low-level-trace
[(rf/path [:settings :low-level-trace])] [(rf/path [:settings :low-level-trace])]
@ -163,27 +203,27 @@
;; Global ;; Global
(defn mount [popup-window popup-document] (defn mount [popup-window popup-document]
(let [app (.getElementById popup-document "--re-frame-trace--") (let [app (.getElementById popup-document " --re-frame-trace-- ")
doc js/document] doc js/document]
(styles/inject-trace-styles popup-document) (styles/inject-trace-styles popup-document)
(goog.object/set popup-window "onunload" #(rf/dispatch [:global/external-closed])) (goog.object/set popup-window " onunload " #(rf/dispatch [:global/external-closed]))
(r/render (r/render
[(r/create-class [(r/create-class
{:display-name "devtools outer external" {:display-name " devtools outer external "
:reagent-render (fn [] :reagent-render (fn []
[container/devtools-inner traces {:panel-type :popup} [container/devtools-inner traces {:panel-type :popup}
])})] ])})]
app))) app)))
(defn open-debugger-window (defn open-debugger-window
"Copied from re-frisk.devtool/open-debugger-window" " Copied from re-frisk.devtool/open-debugger-window "
[] []
(let [{:keys [ext_height ext_width]} (:prefs {}) (let [{:keys [ext_height ext_width]} (:prefs {})
w (js/window.open "" "Debugger" (str "width=" (or ext_width 800) ",height=" (or ext_height 800) w (js/window.open " " " Debugger " (str " width= " (or ext_width 800) ", height= " (or ext_height 800)
",resizable=yes,scrollbars=yes,status=no,directories=no,toolbar=no,menubar=no")) ", resizable=yes, scrollbars=yes, status=no, directories=no, toolbar=no, menubar=no "))
d (.-document w)] d (.-document w)]
(.open d) (.open d)
(.write d "<head></head><body style=\"margin: 0px;\"><div id=\"--re-frame-trace--\" class=\"external-window\"></div></body>") (.write d " <head></head><body style= \"margin: 0px ;\"><div id=\"--re-frame-trace--\" class=\"external-window\"></div></body>")
(goog.object/set w "onload" #(mount w d)) (goog.object/set w "onload" #(mount w d))
(.close d))) (.close d)))
@ -320,10 +360,7 @@
(fn [paths _] (fn [paths _]
(assoc paths (js/Date.now) {:diff? false :open? true :path nil :path-str "[]" :valid-path? true}))) (assoc paths (js/Date.now) {:diff? false :open? true :path nil :path-str "[]" :valid-path? true})))
(defn read-string-maybe [s]
(try (cljs.tools.reader.edn/read-string s)
(catch :default e
nil)))
;; The core idea with :app-db/update-path and :app-db/update-path-blur ;; The core idea with :app-db/update-path and :app-db/update-path-blur
;; is that we need to separate the users text input (`path-str`) with the ;; is that we need to separate the users text input (`path-str`) with the

View File

@ -40,6 +40,12 @@
(fn [settings] (fn [settings]
(:number-of-epochs settings))) (:number-of-epochs settings)))
(rf/reg-sub
:settings/ignored-events
:<- [:settings/root]
(fn [settings]
(sort-by :sort (vals (:ignored-events settings)))))
(rf/reg-sub (rf/reg-sub
:settings/low-level-trace :settings/low-level-trace
;; TODO: filter from traces panel ;; TODO: filter from traces panel

View File

@ -121,9 +121,8 @@
[[:p num-epochs " epochs currently retained, involving " num-traces " traces."]] [[:p num-epochs " epochs currently retained, involving " num-traces " traces."]]
settings-box-81]) settings-box-81])
;; TODO: ignore epochs for: [rc/line]
#_[rc/line] [settings-box
#_[settings-box
[[rc/h-box [[rc/h-box
:align :center :align :center
:gap horizontal-gap :gap horizontal-gap
@ -134,17 +133,18 @@
:label [rc/v-box :label [rc/v-box
:align :center :align :center
:children ["+ event-id"]] :children ["+ event-id"]]
:on-click #(add-item *ignore-items)]]] :on-click #(rf/dispatch [:settings/add-ignored-event])]]]
[rc/v-box [rc/v-box
:width comp-section-width :width comp-section-width
:gap vertical-gap :gap vertical-gap
:children (for [item @*ignore-items] :children (for [item @(rf/subscribe [:settings/ignored-events])
^{:key (:id item)} :let [id (:id item)]]
^{:key id}
[closeable-text-box [closeable-text-box
:model (:text item) :model (:event-str item)
:width "212px" :width "212px"
:on-close #(delete-item *ignore-items (:id item)) :on-close #(rf/dispatch [:settings/remove-ignored-event id])
:on-change #(update-item-field *ignore-items (:id item) :text %)])]] :on-change #(rf/dispatch [:settings/update-ignored-event id %])])]]
[[:p "All trace associated with these events will be ignored."] [[:p "All trace associated with these events will be ignored."]
[:p "Useful if you want to ignore a periodic background polling event."]] [:p "Useful if you want to ignore a periodic background polling event."]]
settings-box-131] settings-box-131]

View File

@ -224,7 +224,6 @@
(defn pod-section [] (defn pod-section []
(let [all-subs @(rf/subscribe [:subs/visible-subs]) (let [all-subs @(rf/subscribe [:subs/visible-subs])
sub-expansions @(rf/subscribe [:subs/sub-expansions])] sub-expansions @(rf/subscribe [:subs/sub-expansions])]
;(js/console.log sub-expansions)
[rc/v-box [rc/v-box
:size "1" :size "1"
;:gap pod-gap ;:gap pod-gap