From be3137189204fd7e722c17b7d2c7a127c0341e65 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 26 Jan 2024 14:09:47 +0100 Subject: [PATCH] :bug: Fix bad page-id on undo delete component --- common/src/app/common/files/changes.cljc | 3 ++- common/src/app/common/files/changes_builder.cljc | 5 +++-- frontend/src/app/main/data/workspace.cljs | 2 +- frontend/src/app/main/data/workspace/libraries.cljs | 5 +++-- frontend/src/app/main/data/workspace/shapes.cljs | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index ccad7630a..e6373c31b 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -210,7 +210,8 @@ [:restore-component [:map {:title "RestoreComponentChange"} [:type [:= :restore-component]] - [:id ::sm/uuid]]] + [:id ::sm/uuid] + [:page-id ::sm/uuid]]] [:purge-component [:map {:title "PurgeComponentChange"} diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index edf5a0166..c2c905be9 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -742,13 +742,14 @@ changes))) (defn delete-component - [changes id] + [changes id page-id] (assert-library! changes) (-> changes (update :redo-changes conj {:type :del-component :id id}) (update :undo-changes conj {:type :restore-component - :id id}))) + :id id + :page-id page-id}))) (defn restore-component ([changes id] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 243772c99..5418a24e7 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -551,7 +551,7 @@ (map :component-id)) changes (reduce (fn [changes component-id] - (pcb/delete-component changes component-id)) + (pcb/delete-component changes component-id (:id page))) changes components-to-delete)] changes)) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index d24b8c95f..14669414a 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -483,9 +483,10 @@ (rx/of (dwt/clear-thumbnail (:current-file-id state) page-id root-id "component") (dwsh/delete-shapes page-id #{root-id}))) ;; Deleting main root triggers component delete - (let [changes (-> (pcb/empty-changes it) + (let [page-id (:current-page-id state) + changes (-> (pcb/empty-changes it) (pcb/with-library-data data) - (pcb/delete-component id))] + (pcb/delete-component id page-id))] (rx/of (dch/commit-changes changes)))))))) diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 2f77d12bc..6e47b0a13 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -240,7 +240,7 @@ changes (reduce (fn [changes component-id] ;; It's important to delete the component before the main instance, because we ;; need to store the instance position if we want to restore it later. - (pcb/delete-component changes component-id)) + (pcb/delete-component changes component-id (:id page))) changes components-to-delete)