From d3dd9ffd9b5f40b60f0cfbb7a36ea25849dcc746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 14 Feb 2024 16:06:32 +0100 Subject: [PATCH 1/2] :bug: Pack swap component in a single transaction and undo group --- .../app/main/data/workspace/libraries.cljs | 22 +++++++++++----- .../src/app/main/data/workspace/shapes.cljs | 26 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 5edcafbe0..4fbf5d1e0 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -865,7 +865,7 @@ 0))))) (defn- add-component-for-swap - [shape file-id id-new-component index target-cell keep-props-values] + [shape file-id id-new-component index target-cell keep-props-values {:keys [undo-group]}] (dm/assert! (uuid? id-new-component)) (dm/assert! (uuid? file-id)) (ptk/reify ::add-component-for-swap @@ -877,6 +877,7 @@ objects (:objects page) position (gpt/point (:x shape) (:y shape)) changes (-> (pcb/empty-changes it (:id page)) + (pcb/set-undo-group undo-group) (pcb/with-objects objects)) position (-> position (with-meta {:cell target-cell})) @@ -925,10 +926,20 @@ index (find-shape-index objects (:parent-id shape) (:id shape)) ;; Store the properties that need to be maintained when the component is swapped - keep-props-values (select-keys shape ctk/swap-keep-attrs)] - (rx/of (dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true}) - (add-component-for-swap shape file-id id-new-component index target-cell keep-props-values) - (ptk/data-event :layout/update [(:parent-id shape)])))))) + keep-props-values (select-keys shape ctk/swap-keep-attrs) + + undo-id (js/Symbol) + undo-group (uuid/next)] + + (rx/of + (dwu/start-undo-transaction undo-id) + (dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true + :undo-id undo-id + :undo-group undo-group}) + (add-component-for-swap shape file-id id-new-component index target-cell keep-props-values + {:undo-group undo-group}) + (ptk/data-event :layout/update [(:parent-id shape)]) + (dwu/commit-undo-transaction undo-id)))))) (defn component-multi-swap "Swaps several components with another one" @@ -946,7 +957,6 @@ (rx/of (dwu/commit-undo-transaction undo-id)) (rx/of (dwsp/open-specialized-panel :component-swap))))))) - (def valid-asset-types #{:colors :components :typographies}) diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 805669e4d..e541c0abb 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -137,22 +137,25 @@ ids-to-hide))))) [ids []]) - undo-id (js/Symbol)] + undo-id (or (:undo-id options) (js/Symbol))] (rx/concat (rx/of (dwu/start-undo-transaction undo-id) (update-shape-flags ids-to-hide {:hidden true})) - (real-delete-shapes file page objects ids-to-delete it components-v2 (:component-swap options)) + (real-delete-shapes file page objects ids-to-delete it {:components-v2 components-v2 + :ignore-touched (:component-swap options) + :undo-group (:undo-group options)}) (rx/of (dwu/commit-undo-transaction undo-id)))))))) (defn- real-delete-shapes-changes - ([file page objects ids it components-v2 ignore-touched] + ([file page objects ids it {:keys [undo-group] :as options}] (let [changes (-> (pcb/empty-changes it (:id page)) + (pcb/set-undo-group undo-group) (pcb/with-page page) (pcb/with-objects objects) (pcb/with-library-data file))] - (real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched))) - ([changes file page objects ids _it components-v2 ignore-touched] + (real-delete-shapes-changes changes file page objects ids it options))) + ([changes file page objects ids _it {:keys [components-v2 ignore-touched]}] (let [lookup (d/getf objects) groups-to-unmask (reduce (fn [group-ids id] @@ -275,12 +278,19 @@ (defn delete-shapes-changes [changes file page objects ids it components-v2 ignore-touched] - (let [[changes _all-parents] (real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched)] + (let [[changes _all-parents] (real-delete-shapes-changes changes + file + page + objects + ids + it + {:components-v2 components-v2 + :ignore-touched ignore-touched})] changes)) (defn- real-delete-shapes - [file page objects ids it components-v2 ignore-touched] - (let [[changes all-parents] (real-delete-shapes-changes file page objects ids it components-v2 ignore-touched) + [file page objects ids it options] + (let [[changes all-parents] (real-delete-shapes-changes file page objects ids it options) undo-id (js/Symbol)] (rx/of (dwu/start-undo-transaction undo-id) (dc/detach-comment-thread ids) From f8b574be816bedc95878043f061f4cba3b069602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 14 Feb 2024 16:54:08 +0100 Subject: [PATCH 2/2] :lipstick: Improve debug traces of libraries helpers --- .../data/workspace/libraries_helpers.cljs | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index ada7e31af..fd830bb20 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -64,6 +64,11 @@ "" (str "<" (get-in state [:workspace-libraries file-id :name]) ">"))) +(defn pretty-uuid + [uuid] + (let [uuid-str (str uuid)] + (subs uuid-str (- (count uuid-str) 6)))) + ;; ---- Components and instances creation ---- (defn duplicate-component @@ -1004,7 +1009,10 @@ (defn- add-shape-to-instance [changes component-shape index component-page container root-instance root-main omit-touched? set-remote-synced?] - (log/info :msg (str "ADD [P] " (:name component-shape))) + (log/info :msg (str "ADD [P " (pretty-uuid (:id container)) "] " + (:name component-shape) + " " + (pretty-uuid (:id component-shape)))) (let [component-parent-shape (ctn/get-shape component-page (:parent-id component-shape)) parent-shape (d/seek #(ctk/is-main-of? component-parent-shape %) (cfh/get-children-with-self (:objects container) @@ -1075,7 +1083,10 @@ (defn- add-shape-to-main [changes shape index component component-container page root-instance root-main] - (log/info :msg (str "ADD [C] " (:name shape))) + (log/info :msg (str "ADD [C " (pretty-uuid (:id component-container)) "] " + (:name shape) + " " + (pretty-uuid (:id shape)))) (let [parent-shape (ctn/get-shape page (:parent-id shape)) component-parent-shape (d/seek #(ctk/is-main-of? % parent-shape) (cfh/get-children-with-self (:objects component-container) @@ -1176,8 +1187,11 @@ (defn- remove-shape [changes shape container omit-touched?] (log/info :msg (str "REMOVE-SHAPE " - (if (cfh/page? container) "[P] " "[C] ") - (:name shape))) + (if (cfh/page? container) "[P " "[C ") + (pretty-uuid (:id container)) "] " + (:name shape) + " " + (pretty-uuid (:id shape)))) (let [objects (get container :objects) parents (cfh/get-parent-ids objects (:id shape)) parent (first parents) @@ -1225,9 +1239,12 @@ (defn- move-shape [changes shape index-before index-after container omit-touched?] (log/info :msg (str "MOVE " - (if (cfh/page? container) "[P] " "[C] ") + (if (cfh/page? container) "[P " "[C ") + (pretty-uuid (:id container)) "] " (:name shape) " " + (pretty-uuid (:id shape)) + " " index-before " -> " index-after)) @@ -1263,8 +1280,11 @@ changes (do (log/info :msg (str "CHANGE-TOUCHED " - (if (cfh/page? container) "[P] " "[C] ") - (:name dest-shape)) + (if (cfh/page? container) "[P " "[C ") + (pretty-uuid (:id container)) "] " + (:name dest-shape) + " " + (pretty-uuid (:id dest-shape))) :options options) (let [new-touched (cond reset-touched? @@ -1298,8 +1318,11 @@ changes (do (log/info :msg (str "CHANGE-REMOTE-SYNCED? " - (if (cfh/page? container) "[P] " "[C] ") - (:name shape)) + (if (cfh/page? container) "[P " "[C ") + (pretty-uuid (:id container)) "] " + (:name shape) + " " + (pretty-uuid (:id shape))) :remote-synced remote-synced?) (-> changes (update :redo-changes conj (make-change @@ -1327,9 +1350,14 @@ (log/info :msg (str "SYNC " (:name origin-shape) + " " + (pretty-uuid (:id origin-shape)) " -> " - (if (cfh/page? container) "[P] " "[C] ") - (:name dest-shape))) + (if (cfh/page? container) "[P " "[C ") + (pretty-uuid (:id container)) "] " + (:name dest-shape) + " " + (pretty-uuid (:id dest-shape)))) (let [;; To synchronize geometry attributes we need to make a prior ;; operation, because coordinates are absolute, but we need to