mirror of
https://github.com/penpot/penpot.git
synced 2025-05-24 00:06:11 +02:00
🐛 Don't allow empty or whitespace-only names on components
This commit is contained in:
parent
6849a5b0e0
commit
dcc15e485d
1 changed files with 16 additions and 19 deletions
|
@ -40,6 +40,7 @@
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
[cuerdas.core :as str]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
;; Change this to :info :debug or :trace to debug this module, or :warn to reset to default
|
||||||
|
@ -340,24 +341,20 @@
|
||||||
(defn rename-component
|
(defn rename-component
|
||||||
"Rename the component with the given id, in the current file library."
|
"Rename the component with the given id, in the current file library."
|
||||||
[id new-name]
|
[id new-name]
|
||||||
(dm/assert! (uuid? id))
|
(dm/verify! (uuid? id))
|
||||||
(dm/assert! (string? new-name))
|
(dm/verify! (string? new-name))
|
||||||
(ptk/reify ::rename-component
|
(ptk/reify ::rename-component
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(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)
|
(let [data (get state :workspace-data)
|
||||||
[path name] (cph/parse-path-name new-name)
|
[path name] (cph/parse-path-name new-name)
|
||||||
components-v2 (features/active-feature? state :components-v2)
|
components-v2 (features/active-feature? state :components-v2)
|
||||||
|
|
||||||
update-fn
|
update-fn
|
||||||
(fn [component]
|
(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
|
(cond-> component
|
||||||
:always
|
:always
|
||||||
(assoc :path path
|
(assoc :path path
|
||||||
|
@ -366,13 +363,13 @@
|
||||||
(not components-v2)
|
(not components-v2)
|
||||||
(update :objects
|
(update :objects
|
||||||
;; Give the same name to the root shape
|
;; Give the same name to the root shape
|
||||||
#(assoc-in % [id :name] name)))))
|
#(assoc-in % [id :name] name))))
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it)
|
changes (-> (pcb/empty-changes it)
|
||||||
(pcb/with-library-data data)
|
(pcb/with-library-data data)
|
||||||
(pcb/update-component id update-fn))]
|
(pcb/update-component id update-fn))]
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes)))))))
|
(rx/of (dch/commit-changes changes))))))))
|
||||||
|
|
||||||
(defn rename-component-and-main-instance
|
(defn rename-component-and-main-instance
|
||||||
[component-id name]
|
[component-id name]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue