mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 23:47:10 +02: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)))
|
(map #(assoc % ::index (cp/position-on-parent (:id %) objects)))
|
||||||
(sort-by ::index)))
|
(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
|
(defn- get-empty-groups-after-group-creation
|
||||||
"An auxiliar function that finds and returns a set of ids that
|
"An auxiliar function that finds and returns a set of ids that
|
||||||
corresponds to groups that should be deleted after a group creation.
|
corresponds to groups that should be deleted after a group creation.
|
||||||
|
@ -77,10 +64,20 @@
|
||||||
result)))))))
|
result)))))))
|
||||||
|
|
||||||
(defn prepare-create-group
|
(defn prepare-create-group
|
||||||
[objects page-id shapes prefix keep-name]
|
[objects page-id shapes base-name keep-name?]
|
||||||
(let [group (make-group shapes prefix keep-name)
|
(let [frame-id (:frame-id (first shapes))
|
||||||
frame-id (:frame-id (first shapes))
|
|
||||||
parent-id (:parent-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
|
rchanges [{:type :add-obj
|
||||||
:id (:id group)
|
:id (:id group)
|
||||||
|
@ -185,7 +182,7 @@
|
||||||
shapes (shapes-for-grouping objects selected)]
|
shapes (shapes-for-grouping objects selected)]
|
||||||
(when-not (empty? shapes)
|
(when-not (empty? shapes)
|
||||||
(let [[group rchanges uchanges]
|
(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
|
(rx/of (dch/commit-changes {:redo-changes rchanges
|
||||||
:undo-changes uchanges
|
:undo-changes uchanges
|
||||||
:origin it})
|
:origin it})
|
||||||
|
@ -224,7 +221,7 @@
|
||||||
(if (and (= (count shapes) 1)
|
(if (and (= (count shapes) 1)
|
||||||
(= (:type (first shapes)) :group))
|
(= (:type (first shapes)) :group))
|
||||||
[(first shapes) [] []]
|
[(first shapes) [] []]
|
||||||
(prepare-create-group objects page-id shapes "Group-" true))
|
(prepare-create-group objects page-id shapes "Group" true))
|
||||||
|
|
||||||
rchanges (d/concat rchanges
|
rchanges (d/concat rchanges
|
||||||
[{:type :mod-obj
|
[{:type :mod-obj
|
||||||
|
|
|
@ -129,7 +129,7 @@
|
||||||
(if (and (= (count shapes) 1)
|
(if (and (= (count shapes) 1)
|
||||||
(= (:type (first shapes)) :group))
|
(= (:type (first shapes)) :group))
|
||||||
[(first shapes) [] []]
|
[(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]
|
[new-shape new-shapes updated-shapes]
|
||||||
(make-component-shape group objects file-id)
|
(make-component-shape group objects file-id)
|
||||||
|
|
|
@ -89,11 +89,11 @@
|
||||||
|
|
||||||
;; NOTE: the group name depends on having executed
|
;; NOTE: the group name depends on having executed
|
||||||
;; the previous test.
|
;; the previous test.
|
||||||
(t/is (= (:name group) "Component-2"))
|
(t/is (= (:name group) "Component-1"))
|
||||||
(t/is (= (:name shape1) "Rect 1"))
|
(t/is (= (:name shape1) "Rect 1"))
|
||||||
(t/is (= (:name shape2) "Rect 2"))
|
(t/is (= (:name shape2) "Rect 2"))
|
||||||
(t/is (= (:name component) "Component-2"))
|
(t/is (= (:name component) "Component-1"))
|
||||||
(t/is (= (:name c-group) "Component-2"))
|
(t/is (= (:name c-group) "Component-1"))
|
||||||
(t/is (= (:name c-shape1) "Rect 1"))
|
(t/is (= (:name c-shape1) "Rect 1"))
|
||||||
(t/is (= (:name c-shape2) "Rect 2"))
|
(t/is (= (:name c-shape2) "Rect 2"))
|
||||||
|
|
||||||
|
@ -139,11 +139,11 @@
|
||||||
|
|
||||||
(t/is (= (:name shape1) "Rect 1"))
|
(t/is (= (:name shape1) "Rect 1"))
|
||||||
(t/is (= (:name shape2) "Rect 2"))
|
(t/is (= (:name shape2) "Rect 2"))
|
||||||
(t/is (= (:name group) "Group-3"))
|
(t/is (= (:name group) "Group-1"))
|
||||||
(t/is (= (:name component) "Group-3"))
|
(t/is (= (:name component) "Group-1"))
|
||||||
(t/is (= (:name c-shape1) "Rect 1"))
|
(t/is (= (:name c-shape1) "Rect 1"))
|
||||||
(t/is (= (:name c-shape2) "Rect 2"))
|
(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))))
|
(thl/is-from-file group file))))
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@
|
||||||
new-component-id)]
|
new-component-id)]
|
||||||
|
|
||||||
(t/is (= (:name component2)
|
(t/is (= (:name component2)
|
||||||
"Component-6")))))
|
"Component-2")))))
|
||||||
|
|
||||||
(rx/subs
|
(rx/subs
|
||||||
done
|
done
|
||||||
|
@ -322,9 +322,9 @@
|
||||||
|
|
||||||
(t/is (not= (:id instance1) (:id instance2)))
|
(t/is (not= (:id instance1) (:id instance2)))
|
||||||
(t/is (= (:id component) component-id))
|
(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 shape2) "Rect 1"))
|
||||||
(t/is (= (:name c-instance2) "Component-7"))
|
(t/is (= (:name c-instance2) "Component-1"))
|
||||||
(t/is (= (:name c-shape2) "Rect 1")))))
|
(t/is (= (:name c-shape2) "Rect 1")))))
|
||||||
|
|
||||||
(rx/subs
|
(rx/subs
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.main.data.workspace :as dw]
|
[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.groups :as dwg]
|
||||||
[app.main.data.workspace.libraries-helpers :as dwlh]))
|
[app.main.data.workspace.libraries-helpers :as dwlh]))
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@
|
||||||
:obj shape}]))))
|
:obj shape}]))))
|
||||||
|
|
||||||
(defn group-shapes
|
(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]
|
([state label ids prefix]
|
||||||
(let [page (current-page state)
|
(let [page (current-page state)
|
||||||
shapes (dwg/shapes-for-grouping (:objects page) ids)]
|
shapes (dwg/shapes-for-grouping (:objects page) ids)]
|
||||||
|
@ -94,9 +95,9 @@
|
||||||
|
|
||||||
(defn make-component
|
(defn make-component
|
||||||
[state label ids]
|
[state label ids]
|
||||||
(let [page (current-page state)
|
(let [page (current-page state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state (:id page))
|
||||||
shapes (dwg/shapes-for-grouping objects ids)
|
shapes (dwg/shapes-for-grouping objects ids)
|
||||||
|
|
||||||
[group rchanges uchanges]
|
[group rchanges uchanges]
|
||||||
(dwlh/generate-add-component shapes
|
(dwlh/generate-add-component shapes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue