mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -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:
commit
45a909f5ff
1 changed files with 16 additions and 19 deletions
|
@ -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 [data (get state :workspace-data)
|
||||
[path name] (cph/parse-path-name new-name)
|
||||
components-v2 (features/active-feature? state :components-v2)
|
||||
(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
|
||||
update-fn
|
||||
(fn [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))]
|
||||
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]
|
||||
|
|
Loading…
Add table
Reference in a new issue