0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -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/reify ::update-create-token
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [tlib (get-tokens-lib state) (let [token-set (wtts/get-selected-token-set state)
token-set (wtts/get-selected-token-set state) token-set-name (or (:name token-set) "Global")
changes (if (not token-set) changes (if (not token-set)
;; No set created add a global set ;; No set created add a global set
(->> (ctob/make-token-set tlib :name "Global") (->> (ctob/make-token-set :name token-set-name :tokens {(:name token) token})
(ctob/add-token token)
(pcb/add-token-set (pcb/empty-changes))) (pcb/add-token-set (pcb/empty-changes)))
;; Either update or add token to existing set ;; Either update or add token to existing set
(if-let [prev-token (ctob/get-token token-set (:name token))] (if-let [prev-token (ctob/get-token token-set (:name token))]
(pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token) (pcb/update-token (pcb/empty-changes) (:name token-set) token prev-token)
(pcb/add-token (pcb/empty-changes) (:name token-set) token)))] (pcb/add-token (pcb/empty-changes) (:name token-set) token)))]
(rx/of (rx/of
(set-selected-token-set-id (:name token-set)) (set-selected-token-set-id token-set-name)
(dch/commit-changes changes)))))) (dch/commit-changes changes))))))
(defn delete-token (defn delete-token

View file

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