mirror of
https://github.com/penpot/penpot.git
synced 2025-03-18 10:41:29 -05:00
🐛 Properly handle group naming on group creation.
This commit is contained in:
parent
08062e8ce8
commit
38292bcda7
4 changed files with 30 additions and 32 deletions
|
@ -23,19 +23,6 @@
|
|||
(map #(assoc % ::index (cp/position-on-parent (:id %) objects)))
|
||||
(sort-by ::index)))
|
||||
|
||||
(defn- make-group
|
||||
[shapes prefix keep-name]
|
||||
(let [selrect (gsh/selection-rect shapes)
|
||||
frame-id (-> shapes first :frame-id)
|
||||
group-name (if (and keep-name
|
||||
(= (count shapes) 1)
|
||||
(= (:type (first shapes)) :group))
|
||||
(:name (first shapes))
|
||||
(name (gensym prefix)))] ; TODO: we should something like in new shapes
|
||||
(-> (cp/make-minimal-group frame-id selrect group-name)
|
||||
(gsh/setup selrect)
|
||||
(assoc :shapes (mapv :id shapes)))))
|
||||
|
||||
(defn- get-empty-groups-after-group-creation
|
||||
"An auxiliar function that finds and returns a set of ids that
|
||||
corresponds to groups that should be deleted after a group creation.
|
||||
|
@ -77,10 +64,20 @@
|
|||
result)))))))
|
||||
|
||||
(defn prepare-create-group
|
||||
[objects page-id shapes prefix keep-name]
|
||||
(let [group (make-group shapes prefix keep-name)
|
||||
frame-id (:frame-id (first shapes))
|
||||
[objects page-id shapes base-name keep-name?]
|
||||
(let [frame-id (:frame-id (first shapes))
|
||||
parent-id (:parent-id (first shapes))
|
||||
gname (if (and keep-name?
|
||||
(= (count shapes) 1)
|
||||
(= (:type (first shapes)) :group))
|
||||
(:name (first shapes))
|
||||
(-> (dwc/retrieve-used-names objects)
|
||||
(dwc/generate-unique-name base-name)))
|
||||
|
||||
selrect (gsh/selection-rect shapes)
|
||||
group (-> (cp/make-minimal-group frame-id selrect gname)
|
||||
(gsh/setup selrect)
|
||||
(assoc :shapes (mapv :id shapes)))
|
||||
|
||||
rchanges [{:type :add-obj
|
||||
:id (:id group)
|
||||
|
@ -185,7 +182,7 @@
|
|||
shapes (shapes-for-grouping objects selected)]
|
||||
(when-not (empty? shapes)
|
||||
(let [[group rchanges uchanges]
|
||||
(prepare-create-group objects page-id shapes "Group-" false)]
|
||||
(prepare-create-group objects page-id shapes "Group" false)]
|
||||
(rx/of (dch/commit-changes {:redo-changes rchanges
|
||||
:undo-changes uchanges
|
||||
:origin it})
|
||||
|
@ -224,7 +221,7 @@
|
|||
(if (and (= (count shapes) 1)
|
||||
(= (:type (first shapes)) :group))
|
||||
[(first shapes) [] []]
|
||||
(prepare-create-group objects page-id shapes "Group-" true))
|
||||
(prepare-create-group objects page-id shapes "Group" true))
|
||||
|
||||
rchanges (d/concat rchanges
|
||||
[{:type :mod-obj
|
||||
|
|
|
@ -129,7 +129,7 @@
|
|||
(if (and (= (count shapes) 1)
|
||||
(= (:type (first shapes)) :group))
|
||||
[(first shapes) [] []]
|
||||
(dwg/prepare-create-group objects page-id shapes "Component-" true))
|
||||
(dwg/prepare-create-group objects page-id shapes "Component" true))
|
||||
|
||||
[new-shape new-shapes updated-shapes]
|
||||
(make-component-shape group objects file-id)
|
||||
|
|
|
@ -89,11 +89,11 @@
|
|||
|
||||
;; NOTE: the group name depends on having executed
|
||||
;; the previous test.
|
||||
(t/is (= (:name group) "Component-2"))
|
||||
(t/is (= (:name group) "Component-1"))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (= (:name component) "Component-2"))
|
||||
(t/is (= (:name c-group) "Component-2"))
|
||||
(t/is (= (:name component) "Component-1"))
|
||||
(t/is (= (:name c-group) "Component-1"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 2"))
|
||||
|
||||
|
@ -139,11 +139,11 @@
|
|||
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (= (:name group) "Group-3"))
|
||||
(t/is (= (:name component) "Group-3"))
|
||||
(t/is (= (:name group) "Group-1"))
|
||||
(t/is (= (:name component) "Group-1"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 2"))
|
||||
(t/is (= (:name c-group) "Group-3"))
|
||||
(t/is (= (:name c-group) "Group-1"))
|
||||
|
||||
(thl/is-from-file group file))))
|
||||
|
||||
|
@ -234,7 +234,7 @@
|
|||
new-component-id)]
|
||||
|
||||
(t/is (= (:name component2)
|
||||
"Component-6")))))
|
||||
"Component-2")))))
|
||||
|
||||
(rx/subs
|
||||
done
|
||||
|
@ -322,9 +322,9 @@
|
|||
|
||||
(t/is (not= (:id instance1) (:id instance2)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance2) "Component-8"))
|
||||
(t/is (= (:name instance2) "Component-2"))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (= (:name c-instance2) "Component-7"))
|
||||
(t/is (= (:name c-instance2) "Component-1"))
|
||||
(t/is (= (:name c-shape2) "Rect 1")))))
|
||||
|
||||
(rx/subs
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]))
|
||||
|
||||
|
@ -79,7 +80,7 @@
|
|||
:obj shape}]))))
|
||||
|
||||
(defn group-shapes
|
||||
([state label ids] (group-shapes state label ids "Group-"))
|
||||
([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)]
|
||||
|
@ -94,9 +95,9 @@
|
|||
|
||||
(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)
|
||||
(let [page (current-page state)
|
||||
objects (wsh/lookup-page-objects state (:id page))
|
||||
shapes (dwg/shapes-for-grouping objects ids)
|
||||
|
||||
[group rchanges uchanges]
|
||||
(dwlh/generate-add-component shapes
|
||||
|
|
Loading…
Add table
Reference in a new issue