From 2a13c2ec005ecf450b98d766f5fb8a967ab7e3c8 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 30 Aug 2024 15:54:57 +0200 Subject: [PATCH] :tada: Add export event for telemetry --- frontend/src/app/main/data/exports.cljs | 47 +++++++++---------- .../app/main/data/workspace/shortcuts.cljs | 2 +- frontend/src/app/main/ui/export.cljs | 21 ++++++--- .../app/main/ui/viewer/inspect/exports.cljs | 12 ++++- .../src/app/main/ui/workspace/main_menu.cljs | 2 +- .../sidebar/options/menus/exports.cljs | 20 ++++++-- 6 files changed, 65 insertions(+), 39 deletions(-) diff --git a/frontend/src/app/main/data/exports.cljs b/frontend/src/app/main/data/exports.cljs index d77a4a021..ebea22149 100644 --- a/frontend/src/app/main/data/exports.cljs +++ b/frontend/src/app/main/data/exports.cljs @@ -49,31 +49,30 @@ (defn show-workspace-export-dialog - ([] (show-workspace-export-dialog nil)) - ([{:keys [selected]}] - (ptk/reify ::show-workspace-export-dialog - ptk/WatchEvent - (watch [_ state _] - (let [file-id (:current-file-id state) - page-id (:current-page-id state) - selected (or selected (wsh/lookup-selected state page-id {})) + [{:keys [selected origin]}] + (ptk/reify ::show-workspace-export-dialog + ptk/WatchEvent + (watch [_ state _] + (let [file-id (:current-file-id state) + page-id (:current-page-id state) + selected (or selected (wsh/lookup-selected state page-id {})) - shapes (if (seq selected) - (wsh/lookup-shapes state selected) - (reverse (wsh/filter-shapes state #(pos? (count (:exports %)))))) + shapes (if (seq selected) + (wsh/lookup-shapes state selected) + (reverse (wsh/filter-shapes state #(pos? (count (:exports %)))))) - exports (for [shape shapes - export (:exports shape)] - (-> export - (assoc :enabled true) - (assoc :page-id page-id) - (assoc :file-id file-id) - (assoc :object-id (:id shape)) - (assoc :shape (dissoc shape :exports)) - (assoc :name (:name shape))))] + exports (for [shape shapes + export (:exports shape)] + (-> export + (assoc :enabled true) + (assoc :page-id page-id) + (assoc :file-id file-id) + (assoc :object-id (:id shape)) + (assoc :shape (dissoc shape :exports)) + (assoc :name (:name shape))))] - (rx/of (modal/show :export-shapes - {:exports (vec exports)}))))))) + (rx/of (modal/show :export-shapes + {:exports (vec exports) :origin origin})))))) (defn show-viewer-export-dialog [{:keys [shapes page-id file-id share-id exports]}] @@ -90,7 +89,7 @@ (assoc :shape (dissoc shape :exports)) (assoc :name (:name shape)) (cond-> share-id (assoc :share-id share-id))))] - (rx/of (modal/show :export-shapes {:exports (vec exports)})))))) #_TODO + (rx/of (modal/show :export-shapes {:exports (vec exports) :origin "viewer"})))))) #_TODO (defn show-workspace-export-frames-dialog [frames] @@ -108,7 +107,7 @@ :name (:name frame)})] (rx/of (modal/show :export-frames - {:exports (vec exports)})))))) + {:exports (vec exports) :origin "workspace:menu"})))))) (defn- initialize-export-status [exports cmd resource] diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index bd0071602..fe1342d55 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -396,7 +396,7 @@ :command (ds/c-mod "shift+e") :subsections [:basics :main-menu] :fn #(st/emit! - (de/show-workspace-export-dialog))} + (de/show-workspace-export-dialog {:origin "workspace:shortcuts"}))} :toggle-snap-ruler-guide {:tooltip (ds/meta-shift "G") :command (ds/c-mod "shift+g") diff --git a/frontend/src/app/main/ui/export.cljs b/frontend/src/app/main/ui/export.cljs index c13b074a4..ff14251a9 100644 --- a/frontend/src/app/main/ui/export.cljs +++ b/frontend/src/app/main/ui/export.cljs @@ -11,6 +11,7 @@ [app.common.colors :as clr] [app.common.data :as d] [app.common.data.macros :as dm] + [app.main.data.events :as ev] [app.main.data.exports :as de] [app.main.data.modal :as modal] [app.main.refs :as refs] @@ -23,6 +24,7 @@ [app.util.strings :as ust] [beicon.v2.core :as rx] [cuerdas.core :as str] + [potok.v2.core :as ptk] [rumext.v2 :as mf])) (def ^:private neutral-icon @@ -35,10 +37,9 @@ (i/icon-xref :close (stl/css :close-icon))) (mf/defc export-multiple-dialog - [{:keys [exports title cmd no-selection]}] + [{:keys [exports title cmd no-selection origin]}] (let [lstate (mf/deref refs/export) in-progress? (:in-progress lstate) - exports (mf/use-state exports) all-exports (deref exports) @@ -61,7 +62,11 @@ (st/emit! (modal/hide) (de/request-multiple-export {:exports enabled-exports - :cmd cmd}))) + :cmd cmd}) + (ptk/event + ::ev/event {::ev/name "export-shapes" + ::ev/origin origin + :num-shapes (count enabled-exports)}))) on-toggle-enabled (mf/use-fn @@ -186,23 +191,25 @@ (mf/defc export-shapes-dialog {::mf/register modal/components ::mf/register-as :export-shapes} - [{:keys [exports]}] + [{:keys [exports origin]}] (let [title (tr "dashboard.export-shapes.title")] [:& export-multiple-dialog {:exports exports :title title :cmd :export-shapes - :no-selection shapes-no-selection}])) + :no-selection shapes-no-selection + :origin origin}])) (mf/defc export-frames {::mf/register modal/components ::mf/register-as :export-frames} - [{:keys [exports]}] + [{:keys [exports origin]}] (let [title (tr "dashboard.export-frames.title")] [:& export-multiple-dialog {:exports exports :title title - :cmd :export-frames}])) + :cmd :export-frames + :origin origin}])) (mf/defc export-progress-widget {::mf/wrap [mf/memo]} diff --git a/frontend/src/app/main/ui/viewer/inspect/exports.cljs b/frontend/src/app/main/ui/viewer/inspect/exports.cljs index 392b6d8cd..2e38efd40 100644 --- a/frontend/src/app/main/ui/viewer/inspect/exports.cljs +++ b/frontend/src/app/main/ui/viewer/inspect/exports.cljs @@ -8,6 +8,7 @@ (:require-macros [app.main.style :as stl]) (:require [app.common.data :as d] + [app.main.data.events :as ev] [app.main.data.exports :as de] [app.main.refs :as refs] [app.main.store :as st] @@ -17,6 +18,7 @@ [app.util.dom :as dom] [app.util.i18n :refer [tr c]] [app.util.keyboard :as kbd] + [potok.v2.core :as ptk] [rumext.v2 :as mf])) (mf/defc exports @@ -62,8 +64,14 @@ (cond-> share-id (assoc :share-id share-id))) exports (mapv #(merge % defaults) @exports)] (if (= 1 (count exports)) - (st/emit! (de/request-simple-export {:export (first exports)})) - (st/emit! (de/request-multiple-export {:exports exports :filename filename})))))) + (st/emit! + (de/request-simple-export {:export (first exports)}) + (ptk/event + ::ev/event {::ev/name "export-shapes" ::ev/origin "viewer" :num-shapes 1})) + (st/emit! + (de/request-multiple-export {:exports exports}) + (ptk/event + ::ev/event {::ev/name "export-shapes" ::ev/origin "viewer" :num-shapes (count exports)})))))) add-export (mf/use-callback diff --git a/frontend/src/app/main/ui/workspace/main_menu.cljs b/frontend/src/app/main/ui/workspace/main_menu.cljs index 2abca79a0..8fb4b6135 100644 --- a/frontend/src/app/main/ui/workspace/main_menu.cljs +++ b/frontend/src/app/main/ui/workspace/main_menu.cljs @@ -508,7 +508,7 @@ (on-add-shared event)))) on-export-shapes - (mf/use-fn #(st/emit! (de/show-workspace-export-dialog))) + (mf/use-fn #(st/emit! (de/show-workspace-export-dialog {:origin "workspace:menu"}))) on-export-shapes-key-down (mf/use-fn diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs index a1981f191..13133cc47 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs @@ -8,6 +8,7 @@ (:require-macros [app.main.style :as stl]) (:require [app.common.data :as d] + [app.main.data.events :as ev] [app.main.data.exports :as de] [app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.state-helpers :as wsh] @@ -20,6 +21,7 @@ [app.util.dom :as dom] [app.util.i18n :refer [tr c]] [app.util.keyboard :as kbd] + [potok.v2.core :as ptk] [rumext.v2 :as mf])) (def exports-attrs @@ -75,8 +77,12 @@ (cond-> sname (some? suffix) (str suffix)) - (st/emit! (de/request-simple-export {:export (merge export defaults)}))) - (st/emit! (de/show-workspace-export-dialog {:selected (reverse ids)}))) + (st/emit! + (de/request-simple-export {:export (merge export defaults)}) + (ptk/event + ::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes 1}))) + (st/emit! + (de/show-workspace-export-dialog {:selected (reverse ids) :origin "workspace:sidebar"}))) ;; In other all cases we only allowed to have a single ;; shape-id because multiple shape-ids are handled @@ -88,8 +94,14 @@ exports (mapv #(merge % defaults) exports)] (if (= 1 (count exports)) (let [export (first exports)] - (st/emit! (de/request-simple-export {:export export}))) - (st/emit! (de/request-multiple-export {:exports exports}))))))) + (st/emit! + (de/request-simple-export {:export export}) + (ptk/event + ::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes 1}))) + (st/emit! + (de/request-multiple-export {:exports exports}) + (ptk/event + ::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes (count exports)}))))))) ;; TODO: maybe move to specific events for avoid to have this logic here? add-export