From c17d2c1abae3684b257b82ba03d901bb290c35bb Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 8 Feb 2024 18:13:51 +0100 Subject: [PATCH] :bug: Fix problems when moving shapes in layouts --- common/src/app/common/types/container.cljc | 18 ++++++++++-------- .../app/main/data/workspace/transforms.cljs | 7 ++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 258f7cb73..1361cb1eb 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -428,12 +428,14 @@ comps-nesting-loop?))) (defn find-valid-parent-and-frame-ids - "Navigate trough the ancestors until find one that is valid" + "Navigate trough the ancestors until find one that is valid. Returns [ parent-id frame-id ]" [parent-id objects children] - (let [parent (get objects parent-id)] - (if (invalid-structure-for-component? objects parent children) - (find-valid-parent-and-frame-ids (:parent-id parent) objects children) - [parent-id - (if (= :frame (:type parent)) - parent-id - (:frame-id parent))]))) + (letfn [(get-frame [parent-id] + (if (cfh/frame-shape? objects parent-id) parent-id (get-in objects [parent-id :frame-id])))] + (let [parent (get objects parent-id) + ;; We can always move the children to the parent they already have + no-changes? + (->> children (every? #(= parent-id (:parent-id %))))] + (if (or no-changes? (not (invalid-structure-for-component? objects parent children))) + [parent-id (get-frame parent-id)] + (recur (:parent-id parent) objects children))))) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index f47b71b60..fb81c4d74 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -511,7 +511,11 @@ objects (wsh/lookup-page-objects state page-id) selected (wsh/lookup-selected state {:omit-blocked? true}) ids (if (nil? ids) selected ids) - shapes (mapv #(get objects %) ids) + shapes (into [] + (comp (map (d/getf objects)) + (remove ctk/in-component-copy-not-head?)) + ids) + duplicate-move-started? (get-in state [:workspace-local :duplicate-move-started?] false) stopper (->> stream @@ -670,6 +674,7 @@ {:keys [layout-grid-cells]} (->> children + (remove #(ctk/in-component-copy-not-head? (get objects %))) (keep #(ctl/get-cell-by-shape-id parent %)) (sort-by key-prop key-comp) (reduce (fn [parent {:keys [id row column row-span column-span]}]