0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 15:09:10 -05:00

Merge pull request #3371 from penpot/niwinz-bugfixes-2023-w26

🐛 Don't allow empty or whitespace-only names on components
This commit is contained in:
Alejandro 2023-07-04 06:52:05 +02:00 committed by GitHub
commit 45a909f5ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,6 +40,7 @@
[app.util.router :as rt]
[app.util.time :as dt]
[beicon.core :as rx]
[cuerdas.core :as str]
[potok.core :as ptk]))
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
@ -340,24 +341,20 @@
(defn rename-component
"Rename the component with the given id, in the current file library."
[id new-name]
(dm/assert! (uuid? id))
(dm/assert! (string? new-name))
(dm/verify! (uuid? id))
(dm/verify! (string? new-name))
(ptk/reify ::rename-component
ptk/WatchEvent
(watch [it state _]
(when (and (some? new-name) (not= "" new-name))
(let [new-name (str/trim new-name)]
(if (str/empty? new-name)
(rx/empty)
(let [data (get state :workspace-data)
[path name] (cph/parse-path-name new-name)
components-v2 (features/active-feature? state :components-v2)
update-fn
(fn [component]
;; NOTE: we need to ensure the component exists,
;; because there are small possibilities of race
;; conditions with component deletion.
;;
;; FIXME: this race conditon should be handled in pcb/update-component
(when component
(cond-> component
:always
(assoc :path path
@ -366,13 +363,13 @@
(not components-v2)
(update :objects
;; Give the same name to the root shape
#(assoc-in % [id :name] name)))))
#(assoc-in % [id :name] name))))
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/update-component id update-fn))]
(rx/of (dch/commit-changes changes)))))))
(rx/of (dch/commit-changes changes))))))))
(defn rename-component-and-main-instance
[component-id name]