From 18d120bbaa40735355fad82efdbb3c2e2554bbef Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Mon, 30 Sep 2024 15:04:12 +0200 Subject: [PATCH] Fix token creation without set --- frontend/src/app/main/data/tokens.cljs | 9 ++++----- frontend/src/app/main/ui/workspace/tokens/form.cljs | 11 +++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index e409f5f64..fe4d864d1 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -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 diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index ac90d9a42..d47811c3d 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -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!)))))))))]