From 0a09ff8e36064c8377734f52dc3df7ac23811f1e Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 26 Feb 2024 11:23:23 +0100 Subject: [PATCH] :bug: Fix impossible to move an element when it's in a main component --- common/src/app/common/types/container.cljc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 4265329ea..f1f67d058 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -392,7 +392,7 @@ (has-any-copy-parent? objects (:parent-id shape)))))) (defn has-any-main? - "Check if the shape has any children or parent that is a main component." + "Check if the shape is a main component or has any children or parent that is a main component." [objects shape] (let [children (cfh/get-children-with-self objects (:id shape)) parents (cfh/get-parents objects (:id shape))] @@ -400,6 +400,12 @@ (some ctk/main-instance? children) (some ctk/main-instance? parents)))) +(defn has-any-main-children? + "Check if the shape is a main component or has any children that is a main component." + [objects shape] + (let [children (cfh/get-children-with-self objects (:id shape))] + (some ctk/main-instance? children))) + (defn valid-shape-for-component? "Check if a main component can be generated from this shape in terms of nested components: - A main can't be the ancestor of another main @@ -412,7 +418,7 @@ (defn- invalid-structure-for-component? "Check if the structure generated nesting children in parent is invalid in terms of nested components" [objects parent children] - (let [selected-main-instance? (some true? (map #(has-any-main? objects %) children)) + (let [selected-main-instance? (some true? (map #(has-any-main-children? objects %) children)) parent-in-component? (in-any-component? objects parent) comps-nesting-loop? (not (->> children (map #(cfh/components-nesting-loop? objects (:id %) (:id parent)))