0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Fix token creation without set

This commit is contained in:
Florian Schroedl 2024-09-30 15:04:12 +02:00
parent c75ab61732
commit 18d120bbaa
2 changed files with 9 additions and 11 deletions

View file

@ -246,19 +246,18 @@
(ptk/reify ::update-create-token
ptk/WatchEvent
(watch [_ state _]
(let [tlib (get-tokens-lib state)
token-set (wtts/get-selected-token-set state)
(let [token-set (wtts/get-selected-token-set state)
token-set-name (or (:name token-set) "Global")
changes (if (not token-set)
;; No set created add a global set
(->> (ctob/make-token-set tlib :name "Global")
(ctob/add-token token)
(->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token})
(pcb/add-token-set (pcb/empty-changes)))
;; Either update or add token to existing set
(if-let [prev-token (ctob/get-token token-set (:name token))]
(pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token)
(pcb/add-token (pcb/empty-changes) (:name token-set) token)))]
(rx/of
(set-selected-token-set-id (:name token-set))
(set-selected-token-set-id token-set-name)
(dch/commit-changes changes))))))
(defn delete-token

View file

@ -10,6 +10,7 @@
["lodash.debounce" :as debounce]
[app.common.colors :as c]
[app.common.data :as d]
[app.common.types.tokens-lib :as ctob]
[app.main.data.modal :as modal]
[app.main.data.tokens :as dt]
[app.main.refs :as refs]
@ -25,7 +26,6 @@
[app.main.ui.workspace.tokens.update :as wtu]
[app.util.dom :as dom]
[cuerdas.core :as str]
[linked.map :as lkm]
[malli.core :as m]
[malli.error :as me]
[promesa.core :as p]
@ -317,11 +317,10 @@ Token names should only contain letters and digits separated by . characters.")}
;; The result should be a vector of all resolved validations
;; We do not handle the error case as it will be handled by the components validations
(when (and (seq result) (not err))
(let [new-token (cond-> {:name final-name
:type (or (:type token) token-type)
:value final-value}
final-description (assoc :description final-description)
(:id token) (assoc :id (:id token)))]
(let [new-token (ctob/make-token :name final-name
:type (or (:type token) token-type)
:value final-value
:description final-description)]
(st/emit! (dt/update-create-token new-token))
(st/emit! (wtu/update-workspace-tokens))
(modal/hide!)))))))))]