From a868dcf8e642ef80b8ad3ac20f22482cddf9df9e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 4 Jul 2023 11:14:49 +0200 Subject: [PATCH] :bug: Don't allow empty strings and whitespace-only strings on media name --- CHANGES.md | 1 + .../app/main/data/workspace/libraries.cljs | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 41a249760..5c178ec7a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -31,6 +31,7 @@ - Fix create and account only with spaces [Taiga #5518](https://tree.taiga.io/project/penpot/issue/5518) - Fix context menu outside screen [Taiga #5524](https://tree.taiga.io/project/penpot/issue/5524) - Fix graphic item rename on assets pannel [Taiga #5556](https://tree.taiga.io/project/penpot/issue/5556) +- Fix component and media name validation on assets panel [Taiga #5555](https://tree.taiga.io/project/penpot/issue/5555) ### :heart: Community contributions by (Thank you!) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 32f69ec02..d27d5794f 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -185,21 +185,22 @@ (defn rename-media [id new-name] - (dm/assert! (uuid? id)) - (dm/assert! (string? new-name)) + (dm/verify! (uuid? id)) + (dm/verify! (string? new-name)) (ptk/reify ::rename-media 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) - object (get-in data [:media id]) - new-object (assoc object :path path :name name) - changes (-> (pcb/empty-changes it) - (pcb/with-library-data data) - (pcb/update-media new-object))] - (rx/of (dch/commit-changes changes))))))) - + (let [new-name (str/trim new-name)] + (if (str/empty? new-name) + (rx/empty) + (let [[path name] (cph/parse-path-name new-name) + data (get state :workspace-data) + object (get-in data [:media id]) + new-object (assoc object :path path :name name) + changes (-> (pcb/empty-changes it) + (pcb/with-library-data data) + (pcb/update-media new-object))] + (rx/of (dch/commit-changes changes)))))))) (defn delete-media [{:keys [id] :as params}]