Move files around

This commit is contained in:
Daniel Compton 2017-11-03 13:31:46 +13:00
parent 900bb414e9
commit 6950c81e6e
12 changed files with 192 additions and 182 deletions

View File

@ -1,9 +1,10 @@
(ns day8.re-frame.trace
(:require [day8.re-frame.trace.subvis :as subvis]
[day8.re-frame.trace.app-db :as app-state]
(:require [day8.re-frame.trace.panels.subvis :as subvis]
[day8.re-frame.trace.panels.app-db :as app-db]
[day8.re-frame.trace.styles :as styles]
[day8.re-frame.trace.components :as components]
[day8.re-frame.trace.localstorage :as localstorage]
[day8.re-frame.trace.components.components :as components]
[day8.re-frame.trace.utils.localstorage :as localstorage]
[day8.re-frame.trace.panels.traces :as traces]
[re-frame.trace :as trace :include-macros true]
[re-frame.db :as db]
[cljs.pprint :as pprint]
@ -148,170 +149,6 @@
[]
(monkey-patch-reagent))
(defn query->fn [query]
(if (= :contains (:filter-type query))
(fn [trace]
(str/includes? (str/lower-case (str (:operation trace) " " (:op-type trace)))
(:query query)))
(fn [trace]
(< (:query query) (:duration trace)))))
(defn add-filter [filter-items filter-input filter-type]
;; prevent duplicate filter strings
(when-not (some #(= filter-input (:query %)) @filter-items)
;; if existing, remove prior filter for :slower-than
(when (and (= :slower-than filter-type)
(some #(= filter-type (:filter-type %)) @filter-items))
(swap! filter-items (fn [item]
(remove #(= :slower-than (:filter-type %)) item))))
;; add new filter
(swap! filter-items conj {:id (random-uuid)
:query (if (= filter-type :contains)
(str/lower-case filter-input)
(js/parseFloat filter-input))
:filter-type filter-type})))
(defn render-traces [visible-traces filter-items filter-input trace-detail-expansions]
(doall
(->>
visible-traces
(map-indexed (fn [index {:keys [op-type id operation tags duration] :as trace}]
(let [show-row? (get-in @trace-detail-expansions [:overrides id]
(:show-all? @trace-detail-expansions))
op-name (if (vector? operation)
(second operation)
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 %))))
:class (str/join " " ["trace--trace"
(case op-type
:sub/create "trace--sub-create"
:sub/run "trace--sub-run"
:event "trace--event"
:render "trace--render"
:re-frame.router/fsm-trigger "trace--fsm-trigger"
nil)])}
[:td.trace--toggle
[:button.expansion-button (if show-row? "▼" "▶")]]
[:td.trace--op
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-type) :contains)
(.stopPropagation ev))}
(str op-type)]]
[:td.trace--op-string
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-name) :contains)
(.stopPropagation ev))}
(str op-name)]]
[:td.trace--meta
(.toFixed duration 1) " ms"]]
(when show-row?
[:tr.trace--details {:key (str id "-details")
:tab-index 0}
[:td]
[:td.trace--details-tags {:col-span 2
:on-click #(.log js/console tags)}
[:div.trace--details-tags-text
(let [tag-str (with-out-str (pprint/pprint tags))
string-size-limit 400]
(if (< string-size-limit (count tag-str))
(str (subs tag-str 0 string-size-limit) " ...")
tag-str))]]
[:td.trace--meta.trace--details-icon
{:on-click #(.log js/console tags)}]]))))))))
(defn render-trace-panel []
(let [filter-input (r/atom "")
filter-items (r/atom (localstorage/get "filter-items" []))
filter-type (r/atom :contains)
input-error (r/atom false)
categories (r/atom #{:event :sub/run :sub/create})
trace-detail-expansions (r/atom {:show-all? false :overrides {}})]
(add-watch filter-items
:update-localstorage
(fn [_ _ _ new-state]
(localstorage/save! "filter-items" new-state)))
(fn []
(let [toggle-category-fn (fn [category-keys]
(swap! categories #(if (set/superset? % category-keys)
(set/difference % category-keys)
(set/union % category-keys))))
visible-traces (cond->> @traces
(seq @categories) (filter (fn [trace] (when (contains? @categories (:op-type trace)) trace)))
(seq @filter-items) (filter (apply every-pred (map query->fn @filter-items))))
save-query (fn [_]
(if (and (= @filter-type :slower-than)
(js/isNaN (js/parseFloat @filter-input)))
(reset! input-error true)
(do
(reset! input-error false)
(add-filter filter-items @filter-input @filter-type))))]
[:div.tab-contents
[:div.filter
[:div.filter-control
[:ul.filter-categories "show: "
[:li.filter-category {:class (when (contains? @categories :event) "active")
:on-click #(toggle-category-fn #{:event})}
"events"]
[:li.filter-category {:class (when (contains? @categories :sub/run) "active")
:on-click #(toggle-category-fn #{:sub/run :sub/create})}
"subscriptions"]
[:li.filter-category {:class (when (contains? @categories :render) "active")
:on-click #(toggle-category-fn #{:render})}
"reagent"]
[:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active")
:on-click #(toggle-category-fn #{:re-frame.router/fsm-trigger :componentWillUnmount})}
"internals"]]
[:div.filter-fields
[:select {:value @filter-type
:on-change #(reset! filter-type (keyword (.. % -target -value)))}
[:option {:value "contains"} "contains"]
[:option {:value "slower-than"} "slower than"]]
[:div.filter-control-input {:style {:margin-left 10}}
[components/search-input {:on-save save-query
:on-change #(reset! filter-input (.. % -target -value))}]
(if @input-error
[:div.input-error {:style {:color "red" :margin-top 5}}
"Please enter a valid number."])]]]
[:ul.filter-items
(map (fn [item]
^{:key (:id item)}
[:li.filter-item
[:button.button
{:style {:margin 0}
:on-click (fn [event] (swap! filter-items #(remove (comp (partial = (:query item)) :query) %)))}
(:filter-type item) ": " [:span.filter-item-string (:query item)]]])
@filter-items)]]
[components/autoscroll-list {:class "panel-content-scrollable" :scroll? true}
[:table
[:thead>tr
[: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))}
(if (:show-all? @trace-detail-expansions) "-" "+")]]
[:th "operations"]
[:th
[:button {:class (str/join " " ["filter-items-count"
(when (pos? (count @filter-items)) "active")])
:on-click #(reset! filter-items [])}
(when (pos? (count @filter-items))
(str (count visible-traces) " of "))
(str (count @traces))]
" traces "
(when (pos? (count @traces))
[:span "(" [:button.text-button {:on-click #(do (trace/reset-tracing!) (reset! traces []))} "clear"] ")"])]
[:th {:style {:text-align "right"}} "meta"]]
[:tbody (render-traces visible-traces filter-items filter-input trace-detail-expansions)]]]]))))
(defn resizer-style [draggable-area]
{:position "absolute" :z-index 2 :opacity 0
@ -409,11 +246,11 @@
#_[:button {:class (str "tab button " (when (= @selected-tab :subvis) "active"))
:on-click #(reset! selected-tab :subvis)} "SubVis"]]]
(case @selected-tab
:traces [render-trace-panel]
:app-db [app-state/render-state db/app-db]
:traces [traces/render-trace-panel traces]
:app-db [app-db/render-state db/app-db]
:subvis [subvis/render-subvis traces
[:div.panel-content-scrollable]]
[app-state/render-state db/app-db])]]]))})))
[app-db/render-state db/app-db])]]]))})))
(defn panel-div []
(let [id "--re-frame-trace--"

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.components
(ns day8.re-frame.trace.components.components
(:require [reagent.core :as r]
[clojure.string :as str]
[goog.fx.dom :as fx]))

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.d3
(ns day8.re-frame.trace.components.d3
(:require [reagent.core :as r]))
(defn no-op [desc]

View File

@ -1 +0,0 @@
(ns day8.re-frame.trace.log)

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.app-db
(ns day8.re-frame.trace.panels.app-db
(:require-macros [day8.re-frame.trace.macros :refer [with-cljs-devtools-prefs]])
(:require [reagent.core :as r]
[clojure.string :as str]

View File

@ -1,7 +1,7 @@
(ns day8.re-frame.trace.subvis
(ns day8.re-frame.trace.panels.subvis
(:require cljsjs.d3
[day8.re-frame.trace.d3 :as d3t]
[day8.re-frame.trace.graph :as graph]
[day8.re-frame.trace.components.d3 :as d3t]
[day8.re-frame.trace.utils.graph :as graph]
[reagent.core :as r]
[re-frame.interop :as interop]
[re-frame.db :as db]

View File

@ -0,0 +1,173 @@
(ns day8.re-frame.trace.panels.traces
(:require [day8.re-frame.trace.components.components :as components]
[re-frame.trace :as trace]
[clojure.string :as str]
[reagent.core :as r]
[day8.re-frame.trace.utils.localstorage :as localstorage]
[cljs.pprint :as pprint]
[clojure.set :as set]))
(defn query->fn [query]
(if (= :contains (:filter-type query))
(fn [trace]
(str/includes? (str/lower-case (str (:operation trace) " " (:op-type trace)))
(:query query)))
(fn [trace]
(< (:query query) (:duration trace)))))
(defn add-filter [filter-items filter-input filter-type]
;; prevent duplicate filter strings
(when-not (some #(= filter-input (:query %)) @filter-items)
;; if existing, remove prior filter for :slower-than
(when (and (= :slower-than filter-type)
(some #(= filter-type (:filter-type %)) @filter-items))
(swap! filter-items (fn [item]
(remove #(= :slower-than (:filter-type %)) item))))
;; add new filter
(swap! filter-items conj {:id (random-uuid)
:query (if (= filter-type :contains)
(str/lower-case filter-input)
(js/parseFloat filter-input))
:filter-type filter-type})))
(defn render-traces [visible-traces filter-items filter-input trace-detail-expansions]
(doall
(->>
visible-traces
(map-indexed (fn [index {:keys [op-type id operation tags duration] :as trace}]
(let [show-row? (get-in @trace-detail-expansions [:overrides id]
(:show-all? @trace-detail-expansions))
op-name (if (vector? operation)
(second operation)
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 %))))
:class (str/join " " ["trace--trace"
(case op-type
:sub/create "trace--sub-create"
:sub/run "trace--sub-run"
:event "trace--event"
:render "trace--render"
:re-frame.router/fsm-trigger "trace--fsm-trigger"
nil)])}
[:td.trace--toggle
[:button.expansion-button (if show-row? "▼" "▶")]]
[:td.trace--op
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-type) :contains)
(.stopPropagation ev))}
(str op-type)]]
[:td.trace--op-string
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-name) :contains)
(.stopPropagation ev))}
(str op-name)]]
[:td.trace--meta
(.toFixed duration 1) " ms"]]
(when show-row?
[:tr.trace--details {:key (str id "-details")
:tab-index 0}
[:td]
[:td.trace--details-tags {:col-span 2
:on-click #(.log js/console tags)}
[:div.trace--details-tags-text
(let [tag-str (with-out-str (pprint/pprint tags))
string-size-limit 400]
(if (< string-size-limit (count tag-str))
(str (subs tag-str 0 string-size-limit) " ...")
tag-str))]]
[:td.trace--meta.trace--details-icon
{:on-click #(.log js/console tags)}]]))))))))
(defn render-trace-panel [traces]
(let [filter-input (r/atom "")
filter-items (r/atom (localstorage/get "filter-items" []))
filter-type (r/atom :contains)
input-error (r/atom false)
categories (r/atom #{:event :sub/run :sub/create})
trace-detail-expansions (r/atom {:show-all? false :overrides {}})]
(add-watch filter-items
:update-localstorage
(fn [_ _ _ new-state]
(localstorage/save! "filter-items" new-state)))
(fn []
(let [toggle-category-fn (fn [category-keys]
(swap! categories #(if (set/superset? % category-keys)
(set/difference % category-keys)
(set/union % category-keys))))
visible-traces (cond->> @traces
(seq @categories) (filter (fn [trace] (when (contains? @categories (:op-type trace)) trace)))
(seq @filter-items) (filter (apply every-pred (map query->fn @filter-items))))
save-query (fn [_]
(if (and (= @filter-type :slower-than)
(js/isNaN (js/parseFloat @filter-input)))
(reset! input-error true)
(do
(reset! input-error false)
(add-filter filter-items @filter-input @filter-type))))]
[:div.tab-contents
[:div.filter
[:div.filter-control
[:ul.filter-categories "show: "
[:li.filter-category {:class (when (contains? @categories :event) "active")
:on-click #(toggle-category-fn #{:event})}
"events"]
[:li.filter-category {:class (when (contains? @categories :sub/run) "active")
:on-click #(toggle-category-fn #{:sub/run :sub/create})}
"subscriptions"]
[:li.filter-category {:class (when (contains? @categories :render) "active")
:on-click #(toggle-category-fn #{:render})}
"reagent"]
[:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active")
:on-click #(toggle-category-fn #{:re-frame.router/fsm-trigger :componentWillUnmount})}
"internals"]]
[:div.filter-fields
[:select {:value @filter-type
:on-change #(reset! filter-type (keyword (.. % -target -value)))}
[:option {:value "contains"} "contains"]
[:option {:value "slower-than"} "slower than"]]
[:div.filter-control-input {:style {:margin-left 10}}
[components/search-input {:on-save save-query
:on-change #(reset! filter-input (.. % -target -value))}]
(if @input-error
[:div.input-error {:style {:color "red" :margin-top 5}}
"Please enter a valid number."])]]]
[:ul.filter-items
(map (fn [item]
^{:key (:id item)}
[:li.filter-item
[:button.button
{:style {:margin 0}
:on-click (fn [event] (swap! filter-items #(remove (comp (partial = (:query item)) :query) %)))}
(:filter-type item) ": " [:span.filter-item-string (:query item)]]])
@filter-items)]]
[components/autoscroll-list {:class "panel-content-scrollable" :scroll? true}
[:table
[:thead>tr
[: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))}
(if (:show-all? @trace-detail-expansions) "-" "+")]]
[:th "operations"]
[:th
[:button {:class (str/join " " ["filter-items-count"
(when (pos? (count @filter-items)) "active")])
:on-click #(reset! filter-items [])}
(when (pos? (count @filter-items))
(str (count visible-traces) " of "))
(str (count @traces))]
" traces "
(when (pos? (count @traces))
[:span "(" [:button.text-button {:on-click #(do (trace/reset-tracing!) (reset! traces []))} "clear"] ")"])]
[:th {:style {:text-align "right"}} "meta"]]
[:tbody (render-traces visible-traces filter-items filter-input trace-detail-expansions)]]]]))))

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.styles
(:require-macros [day8.re-frame.trace.macros :as macros]))
(:require-macros [day8.re-frame.trace.utils.macros :as macros]))
(def panel-styles (macros/slurp-macro "day8/re_frame/trace/main.css"))

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.graph
(ns day8.re-frame.trace.utils.graph
(:require [clojure.set :as set]))
(defn select-type [type traces]

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.localstorage
(ns day8.re-frame.trace.utils.localstorage
(:require [goog.storage.Storage :as Storage]
[goog.storage.mechanism.HTML5LocalStorage :as html5localstore]
[cljs.reader :as reader])

View File

@ -0,0 +1 @@
(ns day8.re-frame.trace.utils.log)

View File

@ -1,4 +1,4 @@
(ns day8.re-frame.trace.macros
(ns day8.re-frame.trace.utils.macros
(:require [clojure.java.io :as io]))
(defmacro slurp-macro