From e9714c4fd06234acef126acae2ed7b582c931919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 3 Dec 2020 14:18:03 +0100 Subject: [PATCH] :bug: Fix synchronization when adding a subcomponent to a instance --- common/app/common/pages.cljc | 4 ++-- common/app/common/pages_helpers.cljc | 8 +++++--- .../app/main/data/workspace/libraries_helpers.cljs | 11 ++++++++--- frontend/src/app/main/store.cljs | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/app/common/pages.cljc b/common/app/common/pages.cljc index 558470b541..a93604229e 100644 --- a/common/app/common/pages.cljc +++ b/common/app/common/pages.cljc @@ -764,8 +764,8 @@ :frame-id frame-id :parent-id parent-id :id id)] - (if (and (contains? objects parent-id) - (contains? objects frame-id)) + (if (and (or (nil? parent-id) (contains? objects parent-id)) + (or (nil? frame-id) (contains? objects frame-id))) (-> data (update :objects assoc id obj) (update-in [:objects parent-id :shapes] diff --git a/common/app/common/pages_helpers.cljc b/common/app/common/pages_helpers.cljc index 2fb13a2e27..7c5aaa5b0a 100644 --- a/common/app/common/pages_helpers.cljc +++ b/common/app/common/pages_helpers.cljc @@ -10,8 +10,9 @@ (ns app.common.pages-helpers (:require [app.common.data :as d] - [app.common.uuid :as uuid] - [app.common.geom.shapes :as gsh])) + [app.common.geom.shapes :as gsh] + [app.common.spec :as us] + [app.common.uuid :as uuid])) (defn walk-pages "Go through all pages of a file and apply a function to each one" @@ -48,7 +49,7 @@ (defn page? [container] - (assert (some? (:type container))) + (us/assert some? (:type container)) (= (:type container) :page)) (defn component? @@ -246,6 +247,7 @@ (let [child-id (first child-ids) child (get objects child-id) + _ (us/assert some? child) [new-child new-child-objects updated-child-objects] (clone-object child new-id objects update-new-object update-original-object)] diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index 0d539806e9..cdf122c05f 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -664,8 +664,13 @@ root-instance)] (cond-> new-shape true - (assoc :shape-ref (:id original-shape) - :frame-id (:frame-id parent-shape)) + (assoc :frame-id (:frame-id parent-shape)) + + (nil? (:shape-ref original-shape)) + (assoc :shape-ref (:id original-shape)) + + (some? (:shape-ref original-shape)) + (assoc :shape-ref (:shape-ref original-shape)) (:component-id original-shape) (assoc :component-id (:component-id original-shape)) @@ -685,7 +690,7 @@ [new-shape new-shapes _] (cph/clone-object component-shape (:id parent-shape) - (get container :objects) + (get component :objects) update-new-shape update-original-shape) diff --git a/frontend/src/app/main/store.cljs b/frontend/src/app/main/store.cljs index 8860679b3b..e182969f3e 100644 --- a/frontend/src/app/main/store.cljs +++ b/frontend/src/app/main/store.cljs @@ -148,7 +148,7 @@ (when component-file (str/format "<%s> " (:name component-file))) (:name component))))))))] - (println "[Workspace]") + (println "[Page]") (show-shape (:id root) 0 objects) (dorun (for [component (vals components)]