Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Page/Block Creation Reporting #2090

Merged
merged 14 commits into from
Mar 30, 2022
22 changes: 22 additions & 0 deletions src/cljc/athens/common_events/graph/ops.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,25 @@
children? (conj move-children-op)
children? (conj close-new-block-op)))]
split-block-op))


(defn ops->new-page-titles
"Reduces Graph Ops into a set of titles of newly created pages."
[ops]
(let [page-new-ops (contains-op? ops :page/new)
new-titles (->> page-new-ops
(map :op/args)
(map :page/title)
set)]
new-titles))


(defn ops->new-block-uids
"Reduces Graph Ops into a set of block/uids of newly created blocks."
[ops]
(let [block-new-ops (contains-op? ops :block/new)
new-uids (->> block-new-ops
(map :op/args)
(map :block/new)
set)]
new-uids))
15 changes: 8 additions & 7 deletions src/cljs/athens/components.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
[athens.util :refer [recursively-modify-block-for-embed]]
[athens.views.blocks.core :as blocks]
[clojure.string :as str]
[re-frame.core :refer [dispatch subscribe]]
[re-frame.core :as rf :refer [dispatch subscribe]]
[reagent.core :as r]
[stylefy.core :as stylefy :refer [use-style]]))


(defn todo-on-click
[uid from-str to-str]
(let [current-block-content (:block/string (db/get-block [:block/uid uid]))
new-block-content (clojure.string/replace current-block-content
from-str
to-str)]
(dispatch [:block/save {:uid uid
:string new-block-content
:add-time? true}])))
new-block-content (str/replace current-block-content
from-str
to-str)]
(rf/dispatch [:block/save {:uid uid
:string new-block-content
:add-time? true
:source :todo-click}])))


(defn span-click-stop
Expand Down
12 changes: 7 additions & 5 deletions src/cljs/athens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[clojure.edn :as edn]
[clojure.string :as string]
[datascript.core :as d]
[re-frame.core :refer [dispatch]]))
[re-frame.core :as rf]))


;; -- Example Roam DBs ---------------------------------------------------
Expand Down Expand Up @@ -625,8 +625,10 @@

(defn transact-state-for-uid
"uid -> Current block
state -> Look at state atom in block-el"
[uid state]
state -> Look at state atom in block-el
source -> reporting source"
[uid state source]
(let [{:string/keys [local]} @state]
(dispatch [:block/save {:uid uid
:string local}])))
(rf/dispatch [:block/save {:uid uid
:string local
:source source}])))
8 changes: 8 additions & 0 deletions src/cljs/athens/electron/monitoring/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@
{:posthog/capture-event! {:event-name "feature/page.create"
:opts-map {:source source
:pages-created count}}}))


(rf/reg-event-fx
:reporting/block.create
(fn [{:keys [_db]} [_ {:keys [source count]}]]
{:posthog/capture-event! {:event-name "feature/block.create"
:opts-map {:source source
:blocks-created count}}}))
239 changes: 159 additions & 80 deletions src/cljs/athens/events.cljs

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/cljs/athens/views/athena.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@
:title query}))
(dispatch [:page/new {:title query
:block-uid block-uid
:shift? shift?}])
(dispatch [:reporting/page.create {:source :athena
:count 1}])
:shift? shift?
:source :athena}])
(dispatch [:reporting/navigation {:source :athena
:target (str "page/" query)
:pane (if shift?
Expand Down Expand Up @@ -301,9 +300,8 @@
shift? (.-shiftKey e)]
(dispatch [:athena/toggle])
(dispatch [:page/new {:title query
:block-uid block-uid}])
(dispatch [:reporting/page.create {:source :athena
:count 1}])
:block-uid block-uid
:source :athena}])
(dispatch [:reporting/navigation {:source :athena
:target (if parent
(str "block/" block-uid)
Expand Down
6 changes: 3 additions & 3 deletions src/cljs/athens/views/blocks/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@
:inline-refs/open false
:inline-refs/states {}
:block/uid uid})
save-fn #(db/transact-state-for-uid (or original-uid uid) state)
idle-fn (gfns/debounce save-fn 2000)]
save-fn (partial db/transact-state-for-uid (or original-uid uid) state)
idle-fn (gfns/debounce #(save-fn :autosave) 2000)]
(swap! state assoc
:string/save-fn save-fn
:string/save-fn #(save-fn :block-save)
:string/idle-fn idle-fn)

(fn [block linked-ref-data opts]
Expand Down
6 changes: 4 additions & 2 deletions src/cljs/athens/views/blocks/textarea_keydown.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@
(.blur target)
(dispatch [:page/new {:title link
:block-uid block-uid
:shift? shift}]))))
:shift? shift
:source :kbd-ctrl-o}]))))

;; same logic as link
(and (re-find #"(?s)#" head)
Expand All @@ -627,7 +628,8 @@
(.blur target)
(dispatch [:page/new {:title link
:block-uid block-uid
:shift? shift}]))))
:shift? shift
:source :kbd-ctrl-o}]))))

(and (re-find #"(?s)\(\(" head)
(re-find #"(?s)\)\)" tail)
Expand Down
9 changes: 5 additions & 4 deletions src/cljs/athens/views/pages/block_page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@
;; Helpers


(defn persist-textarea-string
(defn- persist-textarea-string
"A helper fn that takes `state` containing textarea changes and when user has made a text change dispatches `transact-string`.
Used in `block-page-el` function to log when there is a diff and `on-blur`"
[state block-uid]
(dispatch [:block/save {:uid block-uid
:string (:string/local state)
:add-time? true}]))
(rf/dispatch [:block/save {:uid block-uid
:string (:string/local state)
:add-time? true
:source :on-blur-block-save}]))


;; Components
Expand Down