Skip to content

Commit 7cc75d3

Browse files
committed
feat(dashboard): tests and toogle for homepage
1 parent db390de commit 7cc75d3

File tree

9 files changed

+232
-95
lines changed

9 files changed

+232
-95
lines changed

shadow-cljs.edn

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
:closure-defines {codes.clj.docs.frontend.config/BASE_URL #shadow/env ["BASE_URL"]
1818
codes.clj.docs.frontend.config/CLIENT_ID #shadow/env ["CLIENT_ID"]
1919
codes.clj.docs.frontend.config/REDIRECT_URI #shadow/env ["REDIRECT_URI"]
20-
codes.clj.docs.frontend.config/GA_TAG_ID #shadow/env ["GA_TAG_ID"]}}
20+
codes.clj.docs.frontend.config/GA_TAG_ID #shadow/env ["GA_TAG_ID"]
21+
codes.clj.docs.frontend.config/SHOW_DASHBOARD #shadow/env ["SHOW_DASHBOARD"]}}
2122
:build-hooks [(codes.clj.docs.frontend.dev.shadow.hooks/hashed-files
2223
["resources/public/css/app.css"
2324
"resources/public/js/core.js"])

src/codes/clj/docs/frontend/config.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
(goog-define CLIENT_ID "46d86692f00ed9c613a1")
2222
(goog-define REDIRECT_URI "https://docs.clj.codes/github-callback")
2323
(goog-define GA_TAG_ID "")
24+
(goog-define SHOW_DASHBOARD "true")
2425

2526
(def config
2627
(let [debug? goog.DEBUG]
2728
{:debug? debug?
29+
:show-dashboard (= SHOW_DASHBOARD "true")
2830
:ga-tag-id (if debug?
2931
""
3032
GA_TAG_ID)

src/codes/clj/docs/frontend/components/query.cljs renamed to src/codes/clj/docs/frontend/panels/dashboards/components.cljs

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns codes.clj.docs.frontend.components.query
1+
(ns codes.clj.docs.frontend.panels.dashboards.components
22
(:require ["@mantine/core" :refer [Alert Anchor Avatar Box Grid Group
33
Indicator LoadingOverlay SimpleGrid Text
44
Title Tooltip]]
@@ -8,8 +8,8 @@
88
[codes.clj.docs.frontend.infra.helix :refer [defnc]]
99
[helix.core :refer [$]]))
1010

11-
(defnc latest-interactions [{:keys [value loading? error]}]
12-
($ SimpleGrid {:cols 1}
11+
(defnc latest-interactions-list [{:keys [value loading? error]}]
12+
($ SimpleGrid {:cols 1 :data-testid "latest-interactions-list"}
1313
($ Title {:order 1} "Recently Updated")
1414

1515
(if error
@@ -25,24 +25,26 @@
2525
(fn [{:keys [note-id example-id see-also-id definition-id author created-at]}]
2626
(let [id (str "latest" (or note-id example-id see-also-id))
2727
action (cond
28-
note-id " authored a note for "
29-
example-id " authored an example for "
30-
see-also-id " added a see also on ")
28+
note-id "authored a note for"
29+
example-id "authored an example for"
30+
see-also-id "added a see also on")
3131
definition (str/replace definition-id #"/0$" "")
3232
ago (adapters.time/time-since created-at (.now js/Date))
3333
{:keys [login account-source avatar-url]} author]
34-
($ Group {:key id :wrap "nowrap"}
34+
($ Group {:key id :id id
35+
:wrap "nowrap"
36+
:className "interaction-text"}
3537
($ Anchor {:href (str "/author/" login "/" account-source)}
3638
($ Avatar {:src avatar-url}))
37-
($ Text {:size "sm"} login
39+
($ Text {:size "sm"} login " "
3840
($ Text {:component "span"}
3941
action " "
4042
($ Anchor {:href definition-id} definition)
4143
" " ago ".")))))
4244
value))))))
4345

44-
(defnc top-author [{:keys [value loading? error]}]
45-
($ SimpleGrid {:cols 1}
46+
(defnc top-authors-list [{:keys [value loading? error]}]
47+
($ SimpleGrid {:cols 1 :data-testid "top-authors-list"}
4648
($ Title {:order 1} "Top Authors")
4749

4850
(if error
@@ -59,7 +61,8 @@
5961
($ (.-Col Grid) {:key (str "top" author-id)
6062
:span "lg"}
6163
($ Indicator {:withBorder true :inline true :label interactions :size 16 :position "bottom-end"}
62-
($ Anchor {:href (str "/author/" login "/" account-source)}
64+
($ Anchor {:href (str "/author/" login "/" account-source)
65+
:className "author-interaction-anchor"}
6366
($ Tooltip {:label (str login " with " interactions " interactions")
6467
:withArrow true}
6568
($ Avatar {:size "md" :src avatar-url}))))))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(ns codes.clj.docs.frontend.panels.dashboards.state
2+
(:require [codes.clj.docs.frontend.infra.http :as http]
3+
[town.lilac.flex :as flex]
4+
[town.lilac.flex.promise :as flex.promise]))
5+
6+
(def latest-interactions-fetch
7+
(flex.promise/resource
8+
#(-> (http/request! {:path "social/query/latest-interactions"
9+
:method :get
10+
:query-params {:limit 15}})
11+
(.then (fn [response]
12+
(-> response
13+
:body
14+
(subvec 0 10))))
15+
(.catch (fn [error]
16+
(js/console.error error)
17+
(throw error))))))
18+
19+
(def latest-interactions-response
20+
(flex/signal {:state @(:state latest-interactions-fetch)
21+
:value @(:value latest-interactions-fetch)
22+
:error @(:error latest-interactions-fetch)
23+
:loading? @(:loading? latest-interactions-fetch)}))
24+
25+
(def top-authors-fetch
26+
(flex.promise/resource
27+
#(-> (http/request! {:path "social/query/top-authors"
28+
:method :get
29+
:query-params {:limit 100}})
30+
(.then (fn [response]
31+
(:body response)))
32+
(.catch (fn [error]
33+
(js/console.error error)
34+
(throw error))))))
35+
36+
(def top-authors-response
37+
(flex/signal {:state @(:state top-authors-fetch)
38+
:value @(:value top-authors-fetch)
39+
:error @(:error top-authors-fetch)
40+
:loading? @(:loading? top-authors-fetch)}))
41+
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
11
(ns codes.clj.docs.frontend.panels.dashboards.view
22
(:require ["@mantine/core" :refer [Container Space]]
3-
[codes.clj.docs.frontend.components.query :as components.query]
3+
[codes.clj.docs.frontend.infra.flex.hook :refer [use-flex]]
44
[codes.clj.docs.frontend.infra.helix :refer [defnc]]
5-
[helix.core :refer [$]]))
5+
[codes.clj.docs.frontend.panels.dashboards.components :as components]
6+
[codes.clj.docs.frontend.panels.dashboards.state :as state]
7+
[helix.core :refer [$]]
8+
[helix.hooks :refer [use-effect]]))
69

7-
(def latest-interactions
8-
[{:see-also-id #uuid "6e7aa601-1ce6-4801-83a3-5bbad76084d0", :definition-id "org.clojure/clojure/clojure.core/contains?/0", :definition-id-to "org.clojure/clojure/clojure.string/includes?/0", :created-at #inst "2024-05-03T21:59:49.844695000-00:00", :author {:author-id #uuid "b58e81a2-3647-4c71-aa4f-1499cff15c59", :login "strobelt", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/669994?v=4", :created-at #inst "2024-05-03T21:43:23.766762000-00:00"}}
9-
{:example-id #uuid "14f2c72d-e0b3-466d-bd69-8dfdf7bb4bff", :definition-id "org.clojure/clojure/clojure.core/contains?/0", :body ";; contains? looks for keys in a map and not values in a sequence\n;; so this works as expected\n(contains? {:a 1} :a) ;=> true\n\n;; but this doesn't\n(contains? [:a :b :c] :b) ;=> false\n(contains? \"Clojure is awesome\" \"awesome\") ;=> false\n\n;; For strings you can use clojure.string/includes?\n(clojure.string/includes? \"Clojure is awesome\" \"awesome\") ;=> true\n\n;; And for vectors you can use java's .indexOf\n(.indexOf [:a :b :c] :b) ;=> 1", :created-at #inst "2024-05-03T21:59:38.985240000-00:00", :author {:author-id #uuid "b58e81a2-3647-4c71-aa4f-1499cff15c59", :login "strobelt", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/669994?v=4", :created-at #inst "2024-05-03T21:43:23.766762000-00:00"}, :editors [{:author-id #uuid "b58e81a2-3647-4c71-aa4f-1499cff15c59", :login "strobelt", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/669994?v=4", :created-at #inst "2024-05-03T21:43:23.766762000-00:00", :edited-at #inst "2024-05-03T21:59:38.985240000-00:00"}]}
10-
{:example-id #uuid "c9e76ca3-f41c-4846-9d7b-e563fd79dc45", :definition-id "org.clojure/clojure/clojure.core/defmulti/0", :body ";; Define the multimethod\n(defmulti my-test\n (fn [param1 param2] {:param1 param1 :param2 param2}))\n\n;; Defining handlers/implementation for resulting dispatch values \n(s/defmethod my-test {:param1 :something\n :param2 :something-else}\n [param1 :- s/Keyword\n param2 :- s/Keyword]\n (+ 3 4))\n\n(s/defmethod my-test {:param1 :this\n :param2 :that}\n [param1 :- s/Keyword\n param2 :- s/Keyword]\n (+ 4 5))\n\n(s/defmethod my-test :default\n [param1 :- s/Keyword\n param2 :- s/Keyword]\n \"ERROR\")\n\n;; Invoking it\n(my-test :something :something-else)\n;; => 7\n\n(my-test :something :undefined)\n;; Should go do the default because no other implementation was found, return \n;; => \"ERROR\"\n", :created-at #inst "2024-04-03T20:17:11.131558000-00:00", :author {:author-id #uuid "05c01718-00b0-4ebe-a28b-280cd1be9a31", :login "kroncatti", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/56690659?v=4", :created-at #inst "2024-03-25T16:07:54.244916000-00:00"}, :editors [{:author-id #uuid "05c01718-00b0-4ebe-a28b-280cd1be9a31", :login "kroncatti", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/56690659?v=4", :created-at #inst "2024-03-25T16:07:54.244916000-00:00", :edited-at #inst "2024-04-03T20:12:24.936298000-00:00"} {:author-id #uuid "05c01718-00b0-4ebe-a28b-280cd1be9a31", :login "kroncatti", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/56690659?v=4", :created-at #inst "2024-03-25T16:07:54.244916000-00:00", :edited-at #inst "2024-04-03T20:17:11.131558000-00:00"}]}
11-
{:see-also-id #uuid "8d18bf94-195e-4459-81ad-f3a0fcb2b85d", :definition-id "org.clojure/clojure/clojure.core/take/0", :definition-id-to "org.clojure/clojure/clojure.core/repeatedly/0", :created-at #inst "2024-03-28T15:37:09.314558000-00:00", :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}
12-
{:example-id #uuid "dcaccd23-50fe-4a10-a66b-611fc4e776d5", :definition-id "org.clojure/clojure/clojure.core/take/0", :body "; 6 random integers (from 0 to 60)\n(take 6 (repeatedly #(rand-int 60)))", :created-at #inst "2024-03-28T15:36:49.571386000-00:00", :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}, :editors [{:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00", :edited-at #inst "2024-03-28T15:36:49.571386000-00:00"}]}
13-
{:see-also-id #uuid "3daba272-d969-4e55-92f4-052c7ce64a64", :definition-id "org.clojure/clojure/clojure.core/remove/0", :definition-id-to "org.clojure/clojure/clojure.core/keep/0", :created-at #inst "2024-03-27T11:43:50.674432000-00:00", :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}
14-
{:see-also-id #uuid "2657682d-fb87-4b71-807d-9ba86c9160ba", :definition-id "org.clojure/clojure/clojure.core/keep/0", :definition-id-to "org.clojure/clojure/clojure.core/remove/0", :created-at #inst "2024-03-27T11:43:32.582037000-00:00", :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}}
15-
{:example-id #uuid "2a0253a8-6edf-4f94-9b63-c9f558064c55", :definition-id "org.clojure/clojure/clojure.core/keep/0", :body "; removes nil from list or vector\n(keep identity [:a :b nil :d nil :f])\n; => (:a :b :d :f)", :created-at #inst "2024-03-27T11:41:57.364949000-00:00", :author {:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00"}, :editors [{:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00", :edited-at #inst "2024-03-27T11:41:57.364949000-00:00"}]}
16-
{:example-id #uuid "a00a79c8-d3a2-44c8-8688-b61b4a7672b9", :definition-id "nubank/matcher-combinators/matcher-combinators.matchers/embeds/0", :body "(flow \"Return transactions by category\"\n (match? {:status 200 :body {:transactions (m/embeds [{:category \"Food\"}])}}\n (servlet/request {:method :get :uri \"/transaction/:category\" \n :replace {:category \"Food\"}})", :created-at #inst "2024-03-26T20:43:52.489997000-00:00", :author {:author-id #uuid "750b1ede-fcb5-4989-bb56-f6bbad2b9e66", :login "dimmyjr-nu", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/87130196?v=4", :created-at #inst "2024-03-25T19:20:38.580572000-00:00"}, :editors [{:author-id #uuid "750b1ede-fcb5-4989-bb56-f6bbad2b9e66", :login "dimmyjr-nu", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/87130196?v=4", :created-at #inst "2024-03-25T19:20:38.580572000-00:00", :edited-at #inst "2024-03-26T20:43:52.489997000-00:00"}]}
17-
{:note-id #uuid "1fcfb904-306c-4aa7-94e1-755dcaab45ab", :definition-id "org.clojure/clojure/clojure.core/assoc/0", :body "just be aware that assoc can do this:\n\n```clojure\n(assoc {} :a nil) ;; {:a nil}\n```", :created-at #inst "2024-03-21T10:21:18.790781000-00:00", :author {:author-id #uuid "86ebb308-6839-46d0-b3da-b3832c94ad9e", :login "matheusfrancisco", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6428732?v=4", :created-at #inst "2024-03-16T08:24:15.745224000-00:00"}}])
10+
(defnc all []
11+
(let [latest-interactions-response (use-flex state/latest-interactions-response)
12+
top-authors-response (use-flex state/top-authors-response)]
1813

19-
(def top-author
20-
[{:author-id #uuid "36a91f13-2cf9-4b80-a9f0-619b5dbe6ec5", :login "rafaeldelboni", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1683898?v=4", :created-at #inst "2024-03-11T14:16:54.404609000-00:00", :interactions 10}
21-
{:author-id #uuid "3b5b49a2-a731-4c12-81c0-88b1d74415a2", :login "vloth", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/49727703?v=4", :created-at #inst "2024-03-16T10:43:31.732700000-00:00", :interactions 3} {:author-id #uuid "86ebb308-6839-46d0-b3da-b3832c94ad9e", :login "matheusfrancisco", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6428732?v=4", :created-at #inst "2024-03-16T08:24:15.745224000-00:00", :interactions 2} {:author-id #uuid "b58e81a2-3647-4c71-aa4f-1499cff15c59", :login "strobelt", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/669994?v=4", :created-at #inst "2024-05-03T21:43:23.766762000-00:00", :interactions 2} {:author-id #uuid "05c01718-00b0-4ebe-a28b-280cd1be9a31", :login "kroncatti", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/56690659?v=4", :created-at #inst "2024-03-25T16:07:54.244916000-00:00", :interactions 2} {:author-id #uuid "750b1ede-fcb5-4989-bb56-f6bbad2b9e66", :login "dimmyjr-nu", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/87130196?v=4", :created-at #inst "2024-03-25T19:20:38.580572000-00:00", :interactions 1} {:author-id #uuid "d6e7b8d2-590d-4e53-9691-c8a900703d16", :login "daveliepmann", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/974443?v=4", :created-at #inst "2024-03-25T15:30:44.171709000-00:00", :interactions 1}])
14+
(use-effect
15+
:once
16+
(state/latest-interactions-fetch)
17+
(state/top-authors-fetch))
2218

23-
(defnc all []
24-
; todo get from fetch
25-
(let [latest-interactions-response {:value latest-interactions
26-
:loading? false
27-
:error nil}
28-
top-author-response {:value top-author
29-
:loading? false
30-
:error nil}]
3119
($ Container {:p "sm"}
3220

33-
($ components.query/latest-interactions {:& latest-interactions-response})
21+
($ components/top-authors-list {:& top-authors-response})
3422

3523
($ Space {:h "xl"})
3624

37-
($ components.query/top-author {:& top-author-response}))))
25+
($ components/latest-interactions-list {:& latest-interactions-response}))))

0 commit comments

Comments
 (0)