From 55d2768807df69f91d11fd04e5b6750cd452ebfb Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 31 May 2021 10:45:11 +0200 Subject: [PATCH] :bug: Fix problem with create component --- .../app/main/data/workspace/libraries.cljs | 12 +++++------- .../data/workspace/libraries_helpers.cljs | 6 ++---- frontend/tests/app/test_helpers/pages.cljs | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 7609759fa..57e654c43 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -10,24 +10,21 @@ [app.common.geom.point :as gpt] [app.common.geom.shapes :as geom] [app.common.pages :as cp] - [app.common.pages :as cp] [app.common.spec :as us] [app.common.uuid :as uuid] [app.main.data.messages :as dm] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.common :as dwc] + [app.main.data.workspace.groups :as dwg] [app.main.data.workspace.libraries-helpers :as dwlh] [app.main.data.workspace.state-helpers :as wsh] [app.main.repo :as rp] [app.main.store :as st] - [app.main.streams :as ms] - [app.util.color :as color] [app.util.i18n :refer [tr]] [app.util.logging :as log] [app.util.router :as rt] [app.util.time :as dt] [beicon.core :as rx] - [cljs.spec.alpha :as s] [potok.core :as ptk])) ;; Change this to :info :debug or :trace to debug this module @@ -263,10 +260,11 @@ page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) selected (wsh/lookup-selected state) - selected (cp/clean-loops objects selected)] - (when-not (empty? selected) + selected (cp/clean-loops objects selected) + shapes (dwg/shapes-for-grouping objects selected)] + (when-not (empty? shapes) (let [[group rchanges uchanges] - (dwlh/generate-add-component selected objects page-id file-id)] + (dwlh/generate-add-component shapes objects page-id file-id)] (when-not (empty? rchanges) (rx/of (dch/commit-changes {:redo-changes rchanges :undo-changes uchanges diff --git a/frontend/src/app/main/data/workspace/libraries_helpers.cljs b/frontend/src/app/main/data/workspace/libraries_helpers.cljs index c59050916..738491e7d 100644 --- a/frontend/src/app/main/data/workspace/libraries_helpers.cljs +++ b/frontend/src/app/main/data/workspace/libraries_helpers.cljs @@ -124,10 +124,8 @@ "If there is exactly one id, and it's a group, use it as root. Otherwise, create a group that contains all ids. Then, make a component with it, and link all shapes to their corresponding one in the component." - [ids objects page-id file-id] - (let [shapes (dwg/shapes-for-grouping objects ids) - - [group rchanges uchanges] + [shapes objects page-id file-id] + (let [[group rchanges uchanges] (if (and (= (count shapes) 1) (= (:type (first shapes)) :group)) [(first shapes) [] []] diff --git a/frontend/tests/app/test_helpers/pages.cljs b/frontend/tests/app/test_helpers/pages.cljs index 6fb14c6d1..4ea7265aa 100644 --- a/frontend/tests/app/test_helpers/pages.cljs +++ b/frontend/tests/app/test_helpers/pages.cljs @@ -82,21 +82,24 @@ ([state label ids] (group-shapes state label ids "Group-")) ([state label ids prefix] (let [page (current-page state) - shapes (dwg/shapes-for-grouping (:objects page) ids) + shapes (dwg/shapes-for-grouping (:objects page) ids)] + (if (empty? shapes) + state + (let [[group rchanges uchanges] + (dwg/prepare-create-group (:objects page) (:id page) shapes prefix true)] - [group rchanges uchanges] - (dwg/prepare-create-group (:objects page) (:id page) shapes prefix true)] - - (swap! idmap assoc label (:id group)) - (update state :workspace-data - cp/process-changes rchanges)))) + (swap! idmap assoc label (:id group)) + (update state :workspace-data + cp/process-changes rchanges)))))) (defn make-component [state label ids] (let [page (current-page state) + objects (wsh/lookup-page-objects state page-id) + shapes (dwg/shapes-for-grouping objects ids) [group rchanges uchanges] - (dwlh/generate-add-component ids + (dwlh/generate-add-component shapes (:objects page) (:id page) current-file-id)]