0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Merge pull request #5038 from penpot/palba-add-export-event

🎉 Add export event for telemetry
This commit is contained in:
Alejandro 2024-09-03 12:51:06 +02:00 committed by GitHub
commit a62a083294
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 65 additions and 39 deletions

View file

@ -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]

View file

@ -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")

View file

@ -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]}

View file

@ -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

View file

@ -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

View file

@ -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