From badb5c6a9b24051d1ad59b2e2da4f87540989c55 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 11 Jan 2022 12:40:23 +0100 Subject: [PATCH] :bug: Fix keep name of component equal to the shape name --- CHANGES.md | 1 + .../main/data/workspace/libraries_helpers.cljs | 7 ++++--- frontend/test/app/components_basic_test.cljs | 15 +++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8905d9746..967a1314d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -46,6 +46,7 @@ - Fix "open in new tab" on dashboard [Taiga #2235](https://tree.taiga.io/project/penpot/issue/2355) - Changing pages while comments activated will not close the panel [#1350](https://github.com/penpot/penpot/issues/1350) - Fix navigate comments in right sidebar [Taiga #2163](https://tree.taiga.io/project/penpot/issue/2163) +- Fix keep name of component equal to the shape name [Taiga #2341](https://tree.taiga.io/project/penpot/issue/2341) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index 852afb94c..b917a971d 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -130,11 +130,12 @@ (if (and (= (count shapes) 1) (:component-id (first shapes))) empty-changes - (let [[group rchanges uchanges] + (let [name (if (= 1 (count shapes)) (:name (first shapes)) "Component-1") + [group rchanges uchanges] (if (and (= (count shapes) 1) (= (:type (first shapes)) :group)) [(first shapes) [] []] - (dwg/prepare-create-group objects page-id shapes "Component-1" true)) + (dwg/prepare-create-group objects page-id shapes name true)) ;; Asserts for documentation purposes _ (us/assert vector? rchanges) @@ -146,7 +147,7 @@ rchanges (conj rchanges {:type :add-component :id (:id new-shape) - :name (:name new-shape) + :name name :shapes new-shapes}) rchanges (into rchanges diff --git a/frontend/test/app/components_basic_test.cljs b/frontend/test/app/components_basic_test.cljs index 30def79e5..6a22c61be 100644 --- a/frontend/test/app/components_basic_test.cljs +++ b/frontend/test/app/components_basic_test.cljs @@ -215,7 +215,7 @@ (let [state (-> thp/initial-state (thp/sample-page) (thp/sample-shape :shape1 :rect - {:name "Rect 1"}) + {:name "Rect-1"}) (thp/make-component :instance1 [(thp/id :shape1)])) @@ -247,8 +247,7 @@ new-state new-component-id)] - (t/is (= (:name component2) - "Component-2"))))) + (t/is (= (:name component2) "Rect-2"))))) (rx/subs done #(throw %)))))) @@ -292,7 +291,7 @@ (let [state (-> thp/initial-state (thp/sample-page) (thp/sample-shape :shape1 :rect - {:name "Rect 1"}) + {:name "Rect-1"}) (thp/make-component :instance1 [(thp/id :shape1)])) @@ -320,10 +319,10 @@ (t/is (not= (:id instance1) (:id instance2))) (t/is (= (:id component) component-id)) - (t/is (= (:name instance2) "Component-2")) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:name c-instance2) "Component-1")) - (t/is (= (:name c-shape2) "Rect 1"))))) + (t/is (= (:name instance2) "Rect-3")) + (t/is (= (:name shape2) "Rect-1")) + (t/is (= (:name c-instance2) "Rect-2")) + (t/is (= (:name c-shape2) "Rect-1"))))) (rx/subs done #(throw %))))))