0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 15:51:37 -05:00

Add audit events for shape layout creation

This commit is contained in:
Andrey Antukh 2024-02-28 16:08:02 +01:00 committed by Alonso Torres
parent 467e4c76a6
commit 8eaf93f08a
3 changed files with 25 additions and 12 deletions

View file

@ -19,6 +19,7 @@
[app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[app.main.data.events :as ev]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.colors :as cl]
[app.main.data.workspace.grid-layout.editor :as dwge]
@ -192,7 +193,7 @@
(defn remove-layout
[ids]
(ptk/reify ::remove-layout
(ptk/reify ::remove-shape-layout
ptk/WatchEvent
(watch [_ _ _]
(let [undo-id (js/Symbol)]
@ -204,7 +205,11 @@
(defn create-layout
[type]
(ptk/reify ::create-layout
(ptk/reify ::create-shape-layout
ev/Event
(-data [_]
{:layout (name type)})
ptk/WatchEvent
(watch [_ state _]
(let [page-id (:current-page-id state)
@ -224,19 +229,21 @@
(defn toggle-layout
[type]
(ptk/reify ::toggle-layout-flex
(ptk/reify ::toggle-shape-layout
ptk/WatchEvent
(watch [_ state _]
(watch [it state _]
(let [objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state)
selected-shapes (map (d/getf objects) selected)
single? (= (count selected-shapes) 1)
has-layout? (and single? (ctl/any-layout? objects (:id (first selected-shapes))))]
has-layout? (and single?
(ctl/any-layout? objects (:id (first selected-shapes))))]
(when (not= 0 (count selected))
(if has-layout?
(rx/of (remove-layout selected))
(rx/of (create-layout type))))))))
(let [event (if has-layout?
(remove-layout selected)
(create-layout type))]
(rx/of (with-meta event (meta it)))))))))
(defn update-layout
[ids changes]

View file

@ -222,13 +222,16 @@
:toggle-layout-flex {:tooltip (ds/shift "A")
:command "shift+a"
:subsections [:modify-layers]
:fn #(emit-when-no-readonly (dwsl/toggle-layout :flex))}
:fn #(emit-when-no-readonly
(with-meta (dwsl/toggle-layout :flex)
{::ev/origin "workspace:shortcuts"}))}
:toggle-layout-grid {:tooltip (ds/meta-shift "A")
:command (ds/c-mod "shift+a")
:subsections [:modify-layers]
:fn #(emit-when-no-readonly (dwsl/toggle-layout :grid))}
:fn #(emit-when-no-readonly
(with-meta (dwsl/toggle-layout :grid)
{::ev/origin "workspace:shortcuts"}))}
;; TOOLS
:draw-frame {:tooltip "B"

View file

@ -12,6 +12,7 @@
[app.common.math :as mth]
[app.common.types.shape.layout :as ctl]
[app.config :as cf]
[app.main.data.events :as-alias ev]
[app.main.data.workspace :as udw]
[app.main.data.workspace.grid-layout.editor :as dwge]
[app.main.data.workspace.shape-layout :as dwsl]
@ -855,7 +856,9 @@
(let [type (-> (dom/get-current-target event)
(dom/get-data "type")
(keyword))]
(st/emit! (dwsl/create-layout type))
(st/emit! (with-meta (dwsl/create-layout type)
{::ev/origin "workspace:sidebar"}))
(reset! open* true))))
on-remove-layout