mirror of
https://github.com/penpot/penpot.git
synced 2025-05-21 13:26:12 +02:00
🐛 Avoid theme overwrite on creating a theme with existing name
This commit is contained in:
parent
9d2117e2ac
commit
ebcf5b3177
4 changed files with 41 additions and 28 deletions
|
@ -66,19 +66,26 @@
|
|||
;; TOKENS Actions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn create-token-theme [token-theme]
|
||||
(defn create-token-theme
|
||||
[token-theme]
|
||||
(let [new-token-theme token-theme]
|
||||
(ptk/reify ::create-token-theme
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/set-token-theme (:group new-token-theme)
|
||||
(:name new-token-theme)
|
||||
new-token-theme))]
|
||||
(rx/of
|
||||
(dch/commit-changes changes)))))))
|
||||
(let [data (dsh/lookup-file-data state)
|
||||
tokens-lib (get data :tokens-lib)]
|
||||
|
||||
(if (and tokens-lib (ctob/get-theme tokens-lib (:group token-theme) (:name token-theme)))
|
||||
(rx/of (ntf/show {:content (tr "errors.token-theme-already-exists")
|
||||
:type :toast
|
||||
:level :error
|
||||
:timeout 9000}))
|
||||
(let [changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/set-token-theme (:group new-token-theme)
|
||||
(:name new-token-theme)
|
||||
new-token-theme))]
|
||||
(rx/of (dch/commit-changes changes)))))))))
|
||||
|
||||
(defn update-token-theme [[group name] token-theme]
|
||||
(ptk/reify ::update-token-theme
|
||||
|
|
|
@ -270,9 +270,9 @@
|
|||
(update :group str/trim)
|
||||
(update :description str/trim))]
|
||||
(when-not (str/empty? (:name theme))
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "create-tokens-theme"}))
|
||||
(st/emit! (wdt/create-token-theme theme))))
|
||||
(on-back)))
|
||||
(st/emit! (ptk/event ::ev/event {::ev/name "create-tokens-theme"})
|
||||
(wdt/create-token-theme theme)))
|
||||
(on-back))))
|
||||
|
||||
close-modal
|
||||
(mf/use-fn
|
||||
|
@ -423,12 +423,13 @@
|
|||
:on-save-form on-save-form
|
||||
:disabled? disabled?}]]]]]]))
|
||||
|
||||
(mf/defc themes-modal-body
|
||||
[_]
|
||||
(let [themes (mf/deref refs/workspace-token-themes-no-hidden)
|
||||
state (mf/use-state (if (empty? themes)
|
||||
{:type :create-theme}
|
||||
{:type :themes-overview}))
|
||||
(mf/defc themes-modal-body*
|
||||
{::mf/private true}
|
||||
[]
|
||||
(let [themes (mf/deref refs/workspace-token-themes-no-hidden)
|
||||
state (mf/use-state #(if (empty? themes)
|
||||
{:type :create-theme}
|
||||
{:type :themes-overview}))
|
||||
set-state (mf/use-fn #(swap! state %))
|
||||
component (case (:type @state)
|
||||
:empty-themes empty-themes
|
||||
|
@ -443,13 +444,12 @@
|
|||
::mf/register modal/components
|
||||
::mf/register-as :tokens/themes}
|
||||
[]
|
||||
(let [handle-close-dialog (mf/use-fn #(st/emit! (modal/hide)))]
|
||||
[:div {:class (stl/css :modal-overlay)}
|
||||
[:div {:class (stl/css :modal-dialog)
|
||||
:data-testid "token-theme-update-create-modal"}
|
||||
[:> icon-button* {:class (stl/css :close-btn)
|
||||
:on-click handle-close-dialog
|
||||
:aria-label (tr "labels.close")
|
||||
:variant "action"
|
||||
:icon "close"}]
|
||||
[:& themes-modal-body]]]))
|
||||
[:div {:class (stl/css :modal-overlay)}
|
||||
[:div {:class (stl/css :modal-dialog)
|
||||
:data-testid "token-theme-update-create-modal"}
|
||||
[:> icon-button* {:class (stl/css :close-btn)
|
||||
:on-click modal/hide!
|
||||
:aria-label (tr "labels.close")
|
||||
:variant "action"
|
||||
:icon "close"}]
|
||||
[:> themes-modal-body*]]])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue