From e7a82579c132f67721bdf37a77dd05ca263ec90b Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Tue, 1 Aug 2023 18:56:17 +0200 Subject: [PATCH] :bug: Fix paste groups without shapes attr --- common/src/app/common/types/shape.cljc | 4 ++-- frontend/src/app/main/data/workspace.cljs | 7 ++++++- frontend/src/app/main/data/workspace/selection.cljs | 10 ++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index 961e8e2ed5..8f297c4819 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -156,7 +156,7 @@ [:map {:title "GroupAttrs"} [:type [:= :group]] [:id ::sm/uuid] - [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]) + [:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]]) (sm/def! ::frame-attrs [:map {:title "FrameAttrs"} @@ -172,7 +172,7 @@ [:map {:title "BoolAttrs"} [:type [:= :bool]] [:id ::sm/uuid] - [:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]] + [:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]] ;; FIXME: improve this schema [:bool-type :keyword] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 7d744a65ba..777a034379 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1820,9 +1820,14 @@ detach? (or (foreign-instance? shape paste-objects state) (and (ctk/in-component-copy-not-root? shape) (not= (:id component-shape) - (:id component-shape-parent))))] + (:id component-shape-parent)))) + assign-shapes? (and (or (cph/group-shape? shape) + (cph/bool-shape? shape)) + (nil? (:shapes shape)))] (-> shape (assoc :frame-id frame-id :parent-id parent-id) + (cond-> assign-shapes? + (assoc :shapes [])) (cond-> detach? (-> ;; this is used later, if the paste needs to create a new component from the detached shape diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index efffe23655..eac3221338 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -409,6 +409,8 @@ :else (let [frame? (cph/frame-shape? obj) + group? (cph/group-shape? obj) + bool? (cph/bool-shape? obj) new-id (ids-map (:id obj)) parent-id (or parent-id frame-id) name (:name obj) @@ -427,8 +429,12 @@ :name name :parent-id parent-id :frame-id frame-id) - (dissoc :shapes - :main-instance? + + (cond-> + (or group? bool?) + (assoc :shapes [])) + + (dissoc :main-instance? :use-for-thumbnail?) (gsh/move delta) (d/update-when :interactions #(ctsi/remap-interactions % ids-map objects)))