-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
subs.cljs
391 lines (355 loc) · 19.7 KB
/
subs.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
(ns day8.re-frame-10x.view.subs
(:require [day8.re-frame-10x.view.app-db :refer [pod-gap pod-padding border-radius pod-border-edge
pod-header-section cljs-dev-tools-background]]
[day8.re-frame-10x.utils.utils :as utils]
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.core :as rf]
[day8.re-frame-10x.inlined-deps.reagent.v1v0v0.reagent.core :as r]
[day8.re-frame-10x.utils.re-com :as rc :refer [css-join]]
[day8.re-frame-10x.common-styles :as common]
[day8.re-frame-10x.view.components :as components]
[day8.re-frame-10x.inlined-deps.garden.v1v3v10.garden.units :as units]
[day8.re-frame-10x.svgs :as svgs]
[clojure.data]
[day8.re-frame-10x.material :as material])
(:require-macros
[day8.re-frame-10x.utils.re-com :refer [handler-fn]]))
;(s/def ::query-v any?)
;(s/def ::dyn-v any?)
;(s/def ::query-cache-params (s/tuple ::query-v ::dyn-v))
;(s/def ::deref #(satisfies? IDeref %))
;(s/def ::query-cache (s/map-of ::query-cache-params ::deref))
;(assert (s/valid? ::query-cache (rc/deref-or-value-peek subs/query->reaction)))
(defn sub-tag-class [type]
(case type
:sub/create "rft-tag__subscription_created"
:sub/dispose "rft-tag__subscription_destroyed"
:sub/run "rft-tag__subscription_re_run"
:sub/not-run "rft-tag__subscription_not_run"
""))
(def tag-types {:sub/create {:long "CREATED" :short "C"}
:sub/dispose {:long "DISPOSED" :short "D"}
:sub/run {:long "RUN" :short "R"}
:sub/not-run {:long "NOT-RUN" :short "N"}
nil {:long "NIL" :short "NIL"}})
(defn long-tag-desc [type]
(get-in tag-types [type :long] (str type)))
(defn short-tag-desc [type]
(get-in tag-types [type :short] (str type)))
(defn sub-tag [type label]
[components/tag (sub-tag-class type) label])
(defn short-sub-tag [type label]
[components/tag (str (sub-tag-class type) " rft-tag__short") label])
(defn title-tag [type title label]
[rc/v-box
:class "noselect"
:align :center
:gap "2px"
:children [[:span {:style {:font-size "9px"}} title]
[components/tag (sub-tag-class type) label]]])
(defn panel-header []
(let [created-count (rf/subscribe [:subs/created-count])
re-run-count (rf/subscribe [:subs/re-run-count])
destroyed-count (rf/subscribe [:subs/destroyed-count])
not-run-count (rf/subscribe [:subs/not-run-count])
ignore-unchanged-l2-subs? (rf/subscribe [:subs/ignore-unchanged-l2-subs?])
ignore-unchanged-l2-count (rf/subscribe [:subs/unchanged-l2-subs-count])]
[rc/h-box
:justify :between
:align :center
:style {:flex-flow "row wrap"}
:margin (css-join common/gs-19s "0px")
:children [[rc/h-box
:align :center
:gap common/gs-19s
:height "48px"
:padding (css-join "0px" common/gs-19s)
:style {:background-color "#fafbfc"
:border "1px solid #e3e9ed"
:border-radius border-radius}
:children [[:span {:style {:color "#828282"
:font-size "18px"
:font-weight "lighter"}}
"Summary:"]
[title-tag :sub/create (long-tag-desc :sub/create) @created-count]
[title-tag :sub/run (long-tag-desc :sub/run) @re-run-count]
[title-tag :sub/dispose (long-tag-desc :sub/dispose) @destroyed-count]
[title-tag :sub/not-run (long-tag-desc :sub/not-run) @not-run-count]]]
[rc/h-box
:align :center
:gap common/gs-19s
:height "48px"
:padding (css-join "0px" common/gs-19s)
:style {:background-color "#fafbfc"
:border "1px solid #e3e9ed"
:border-radius border-radius}
:children [[rc/checkbox
:model ignore-unchanged-l2-subs?
:label [:span "Ignore " [:b {:style {:font-weight "700"}} @ignore-unchanged-l2-count] " unchanged" [:br]
[rc/link {:label (str "layer 2 " (utils/pluralize- @ignore-unchanged-l2-count "sub"))
:href "https://github.com/day8/re-frame-10x/blob/master/docs/HyperlinkedInformation/UnchangedLayer2.md"}]]
:style {:margin-top "6px"}
:on-change #(rf/dispatch [:subs/ignore-unchanged-l2-subs? %])]]]]]))
(defn pod-header [{:keys [id layer path open? diff? pin? run-times order]}]
[rc/h-box
:class (str "app-db-path--header"
(when pin? " subscription-pinned"))
:align :center
:height common/gs-31s
:children [[pod-header-section
:children [[rc/box
:width common/gs-31s
:height common/gs-31s
:class "noselect"
:style {:cursor "pointer"}
:attr {:title (str (if open? "Close" "Open") " the pod bay doors, HAL")
:on-click (handler-fn (rf/dispatch [:subs/open-pod? id (not open?)]))}
:child [rc/box
:margin "auto"
:child [:span.arrow
(if open?
[material/arrow-drop-down :fill "#6EC0E6"]
[material/arrow-right :fill "#6EC0E6"])]]]]]
#_[rc/box
;:width "64px" ;; (100-36)px from box above
:child [sub-tag (first order) (short-tag-desc (first order))]]
;; TODO: report if a sub was run multiple times
#_(when run-times
[:span "Warning: run " run-times " times"])
[rc/h-box
:class "app-db-path--path-header"
:size "auto"
:style {:height common/gs-31s
:border-right pod-border-edge}
:background-color "white"
:align :center
:children [[rc/input-text
:style {:height "25px"
:border "none"
:padding (css-join "0px" common/gs-7s)
:width "-webkit-fill-available"} ;; This took a bit of finding!
:width "100%"
:model path
:disabled? true]]]
[pod-header-section
:min-width "50px"
:children [[rc/label :label (str id)]]]
[pod-header-section
:min-width "106px" ;; common/gs-131s - (2 * 12px padding) - (1px border)
:gap common/gs-12s
:style {:padding "0px 12px"}
:children (into []
(comp
(take 3)
(map (fn [o] [short-sub-tag o (short-tag-desc o)])))
order)]
[pod-header-section
:width common/gs-31s
:children [[rc/box
:style {:width common/gs-19s
:height common/gs-19s
:border pod-border-edge
:border-radius "50%"
:margin "auto"
:background-color "white"}
:child (if (some? layer)
[:div {:style {:margin "auto"}} layer]
[rc/link {:label "?"
:style {:margin "auto"}
:href "https://github.com/day8/re-frame-10x/blob/master/docs/HyperlinkedInformation/UnchangedLayer2.md#why-do-i-sometimes-see-layer--when-viewing-a-subscription"}])]]]
[pod-header-section
:width "50px"
:attr {:on-click (handler-fn (rf/dispatch [:subs/set-pinned id (not pin?)]))}
:children [[rc/box
:style {:margin "auto"}
:child [rc/checkbox
:model pin?
:label ""
:style {:margin-left "6px"
:margin-top "1px"}
:on-change #(rf/dispatch [:subs/set-pinned id (not pin?)])]]]]
[pod-header-section
:width "50px"
:attr {:on-click (handler-fn (rf/dispatch [:subs/set-diff-visibility id (not diff?)]))}
:last? true
:children [[rc/box
:style {:margin "auto"}
:child [rc/checkbox
:model diff?
:label ""
:style {:margin-left "6px"
:margin-top "1px"}
:on-change #(rf/dispatch [:subs/set-diff-visibility id (not diff?)])]]]]]])
(def no-prev-value-msg [:p {:style {:font-style "italic"}} "No previous value exists to diff"])
(def unchanged-value-msg [:p {:style {:font-style "italic"}} "Subscription value is unchanged"])
(def sub-not-run-msg [:p {:style {:font-style "italic"}} "Subscription not run, so no diff is available"])
(def not-run-yet-msg [rc/label :style {:font-style "italic"} :label "Subscription not run yet, so no value is available"])
(defn pod [{:keys [id layer path open? diff?] :as pod-info}]
(let [render-diff? (and open? diff?)
value? (contains? pod-info :value)
previous-value? (contains? pod-info :previous-value)]
[rc/v-box
:style {:margin-bottom pod-gap
:margin-right "1px"}
:children [[pod-header pod-info]
[rc/v-box
:class (when open? "app-db-path--pod-border")
:children [(when open?
(let [main-value (:value pod-info)
#_(cond value? (:value pod-info)
previous-value? (:previous-value pod-info)
:else nil)]
[rc/v-box
:class "data-viewer"
:style {:margin (css-join pod-padding pod-padding "0px" pod-padding)
:overflow-x "auto"
:overflow-y "hidden"}
:children [(if (or value? #_previous-value?)
[components/simple-render
main-value
["sub-path" path]]
not-run-yet-msg)]]))
(when render-diff?
(let [diffable? (and value? previous-value?)
not-run? (= (:order pod-info) [:sub/not-run])
previous-value (:previous-value pod-info)
value (:value pod-info)
unchanged-value? (get-in pod-info [:sub/traits :unchanged?] false)
[diff-before diff-after _] (clojure.data/diff previous-value value)]
[rc/v-box
:children [[rc/v-box
:class "app-db-path--link"
:style {:background-color cljs-dev-tools-background}
:justify :end
:children [[rc/hyperlink-href
;:class "app-db-path--label"
:label "ONLY BEFORE"
:style {:margin-left common/gs-7s}
:attr {:rel "noopener noreferrer"}
:target "_blank"
:href utils/diff-link]]]
[rc/v-box
:class "data-viewer data-viewer--top-rule"
:style {:overflow-x "auto"
:overflow-y "hidden"}
:children [(cond
not-run? sub-not-run-msg
unchanged-value? unchanged-value-msg
diffable? [components/simple-render
diff-before
["app-db-diff" path]]
:else no-prev-value-msg)]]
[rc/v-box
:class "app-db-path--link"
:style {:background-color cljs-dev-tools-background}
:justify :end
:children [[rc/hyperlink-href
;:class "app-db-path--label"
:label "ONLY AFTER"
:style {:margin-left common/gs-7s
:background-color cljs-dev-tools-background}
:attr {:rel "noopener noreferrer"}
:target "_blank"
:href utils/diff-link]]]
[rc/v-box
:class "data-viewer data-viewer--top-rule"
:style {:overflow-x "auto"
:overflow-y "hidden"}
:children [(cond
not-run? sub-not-run-msg
unchanged-value? unchanged-value-msg
diffable? [components/simple-render
diff-after
["app-db-diff" path]]
:else no-prev-value-msg)]]]]))
(when open?
[rc/gap-f :size pod-padding])]]]]))
(defn no-pods []
[rc/h-box
:margin (css-join "0px 0px 0px" common/gs-19s)
:gap common/gs-7s
:align :start
:align-self :start
:children [[rc/label :label "There are no subscriptions to show"]]])
(defn pod-header-column-titles
[]
[rc/h-box
:height common/gs-19s
:align :center
:style {:margin-right "1px"}
:children [[rc/box
:size "1"
:child ""]
[rc/box
:width "132px" ;; common/gs-131s + 1 border
:justify :center
:child [rc/label :style {:font-size "9px"} :label "ACTIVITY"]]
[rc/box
:width "32px" ;; common/gs-31s + 1 border
:justify :center
:child [rc/label :style {:font-size "9px"} :label "LAYER"]]
[rc/box
:width "51px" ;; 50px + 1 border
:justify :center
:child [rc/label :style {:font-size "9px"} :label "PINNED"]]
[rc/box
:width "51px" ;; 50px + 1 border
:justify :center
:child [rc/label :style {:font-size "9px"} :label "DIFFS"]]
[rc/gap-f :size "6px"]]]) ;; Add extra space to look better when there is/aren't scrollbars
(defn pod-section []
(let [visible-subs @(rf/subscribe [:subs/visible-subs])
intra-epoch-subs @(rf/subscribe [:subs/intra-epoch-subs])
sub-expansions @(rf/subscribe [:subs/sub-expansions])
sub-pins @(rf/subscribe [:subs/sub-pins])
all-subs (if @(rf/subscribe [:settings/debug?])
(cons {:path [:subs/current-epoch-sub-state] :id "debug" :value @(rf/subscribe [:subs/current-epoch-sub-state])} visible-subs)
visible-subs)]
[rc/v-box
:size "1"
:style {:overflow-y "auto"}
:children [(if (empty? all-subs)
[no-pods]
[pod-header-column-titles])
[rc/v-box
:size "auto"
:style {:overflow-x "hidden"
:overflow-y "auto"}
:children [(for [p all-subs]
^{:key (:id p)}
[pod (merge p
(get sub-expansions (:id p))
(get sub-pins (:id p)))])
(when (seq intra-epoch-subs)
(list
^{:key "intra-epoch-line"}
[rc/line :size "5px"
:style {:margin "19px 0px"}]
^{:key "intra-epoch-title"}
[:h2 {:class "bm-heading-text"
:style {:margin "19px 0px"}}
[rc/link
{:href "https://github.com/day8/re-frame-10x/blob/master/docs/HyperlinkedInformation/IntraEpoch.md"
:label "Intra-Epoch Subscriptions"}]]
(for [p intra-epoch-subs]
^{:key (:id p)}
[pod (merge p (get sub-expansions (:id p)))])))]]]]))
(defn filter-section []
(let [filter-str (rf/subscribe [:subs/filter-str])]
[:div.filter
[:div.filter-control
[:div.filter-control-input {:style {:margin-left 10}}
[:input {:type "text"
:value @filter-str
:placeholder "Type to filter subs"
:on-change #(rf/dispatch [:subs/set-filter
(-> % .-target .-value)])}]]]]))
(defn render []
[]
[rc/v-box
:size "1"
:style {:margin-right common/gs-19s
:width "100%"}
:children [[panel-header]
[filter-section]
[pod-section]
[rc/gap-f :size common/gs-19s]]])