mirror of
https://github.com/penpot/penpot.git
synced 2025-02-02 04:19:08 -05:00
🐛 Fix user can rename a component with only spaces inside a group
This commit is contained in:
parent
d57bfa98a3
commit
85ac199d81
2 changed files with 22 additions and 13 deletions
|
@ -701,19 +701,23 @@
|
|||
(watch [_ state _]
|
||||
(when-let [shape-id (dm/get-in state [:workspace-local :shape-for-rename])]
|
||||
(let [shape (wsh/lookup-shape state shape-id)
|
||||
name (cfh/clean-path name)]
|
||||
name (str/trim name)
|
||||
clean-name (cfh/clean-path name)
|
||||
valid? (and (not (str/ends-with? name "/"))
|
||||
(string? clean-name)
|
||||
(not (str/blank? clean-name)))]
|
||||
(rx/concat
|
||||
;; Remove rename state from workspace local state
|
||||
(rx/of #(update % :workspace-local dissoc :shape-for-rename))
|
||||
|
||||
;; Rename the shape if string is not empty/blank
|
||||
(when (and (string? name) (not (str/blank? name)))
|
||||
(rx/of (update-shape shape-id {:name name})))
|
||||
(when valid?
|
||||
(rx/of (update-shape shape-id {:name clean-name})))
|
||||
|
||||
;; Update the component in case if shape is a main instance
|
||||
(when (and (string? name) (not (str/blank? name)) (:main-instance shape))
|
||||
(when (and valid? (:main-instance shape))
|
||||
(when-let [component-id (:component-id shape)]
|
||||
(rx/of (dwl/rename-component component-id name)))))))))))
|
||||
(rx/of (dwl/rename-component component-id clean-name)))))))))))
|
||||
|
||||
;; --- Update Selected Shapes attrs
|
||||
|
||||
|
|
|
@ -404,16 +404,21 @@
|
|||
(ptk/reify ::rename-component-and-main-instance
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(when-let [component (dm/get-in state [:workspace-data :components component-id])]
|
||||
(let [name (cfh/clean-path name)
|
||||
shape-id (:main-instance-id component)
|
||||
page-id (:main-instance-page component)]
|
||||
(rx/concat
|
||||
(rx/of (rename-component component-id name))
|
||||
(let [name (str/trim name)
|
||||
clean-name (cfh/clean-path name)
|
||||
valid? (and (not (str/ends-with? name "/"))
|
||||
(string? clean-name)
|
||||
(not (str/blank? clean-name)))
|
||||
component (dm/get-in state [:workspace-data :components component-id])]
|
||||
(when (and valid? component)
|
||||
(let [shape-id (:main-instance-id component)
|
||||
page-id (:main-instance-page component)]
|
||||
(rx/concat
|
||||
(rx/of (rename-component component-id clean-name))
|
||||
|
||||
;; NOTE: only when components-v2 is enabled
|
||||
(when (and shape-id page-id)
|
||||
(rx/of (dch/update-shapes [shape-id] #(assoc % :name name) {:page-id page-id :stack-undo? true})))))))))
|
||||
(when (and shape-id page-id)
|
||||
(rx/of (dch/update-shapes [shape-id] #(assoc % :name clean-name) {:page-id page-id :stack-undo? true}))))))))))
|
||||
|
||||
(defn duplicate-component
|
||||
"Create a new component copied from the one with the given id."
|
||||
|
|
Loading…
Add table
Reference in a new issue