From 052282cff9ad9d00a89f57974b173e438986a443 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 25 Feb 2025 10:41:07 +0100 Subject: [PATCH] :bug: Fix problem updating layout when duplicating component --- common/src/app/common/logic/libraries.cljc | 37 ++++++++++++------- .../logic/comp_creation_test.cljc | 11 +++--- .../app/main/data/workspace/libraries.cljs | 9 +++-- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 9962ccaae..f7104d7ee 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -193,20 +193,29 @@ new-main-instance-shape new-main-instance-shapes] (duplicate-component component new-component-id (:data library))] - (-> changes - (pcb/with-page main-instance-page) - (pcb/with-objects (:objects main-instance-page)) - (pcb/add-objects new-main-instance-shapes {:ignore-touched true}) - (pcb/add-component (if components-v2 - new-component-id - (:id new-component-shape)) - (:path component) - new-name - new-component-shapes - [] - (:id new-main-instance-shape) - (:id main-instance-page) - (:annotation component))))) + [new-main-instance-shape + (-> changes + (pcb/with-page main-instance-page) + (pcb/with-objects (:objects main-instance-page)) + (pcb/add-objects new-main-instance-shapes {:ignore-touched true}) + (pcb/add-component (if components-v2 + new-component-id + (:id new-component-shape)) + (:path component) + new-name + new-component-shapes + [] + (:id new-main-instance-shape) + (:id main-instance-page) + (:annotation component)) + ;; Update grid layout if the new main instance is inside + (pcb/update-shapes + [(:frame-id new-main-instance-shape)] + (fn [shape objects] + (cond-> shape + (ctl/grid-layout? shape) + (ctl/assign-cells objects))) + {:with-objects? true}))])) (defn generate-instantiate-component diff --git a/common/test/common_tests/logic/comp_creation_test.cljc b/common/test/common_tests/logic/comp_creation_test.cljc index a57aa7693..f06ca3a93 100644 --- a/common/test/common_tests/logic/comp_creation_test.cljc +++ b/common/test/common_tests/logic/comp_creation_test.cljc @@ -286,11 +286,12 @@ component (thc/get-component file :component1) ;; ==== Action - changes (cll/generate-duplicate-component (pcb/empty-changes) - file - (:id component) - (uuid/next) - true) + [_ changes] + (cll/generate-duplicate-component (pcb/empty-changes) + file + (:id component) + (uuid/next) + true) file' (thf/apply-changes file changes) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index fa21b6ce2..b24b7a807 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -529,10 +529,13 @@ (let [libraries (dsh/lookup-libraries state) library (get libraries library-id) components-v2 (features/active-feature? state "components/v2") - changes (-> (pcb/empty-changes it nil) - (cll/generate-duplicate-component library component-id new-component-id components-v2))] - (rx/of (dch/commit-changes changes))))))) + [main-instance changes] + (-> (pcb/empty-changes it nil) + (cll/generate-duplicate-component library component-id new-component-id components-v2))] + (rx/of + (ptk/data-event :layout/update {:ids [(:id main-instance)]}) + (dch/commit-changes changes))))))) (defn delete-component "Delete the component with the given id, from the current file library."