diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index 4c87649d3..bbd355337 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -210,7 +210,7 @@ (wtu/update-workspace-tokens)))))) (defn update-create-token - [token] + [{:keys [token prev-token-name]}] (ptk/reify ::update-create-token ptk/WatchEvent (watch [_ state _] @@ -221,7 +221,7 @@ (->> (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))] + (if-let [prev-token (ctob/get-token token-set (or prev-token-name (: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 @@ -251,7 +251,7 @@ (ctob/get-token token-name) (update :name #(str/concat % "-copy")))] (rx/of - (update-create-token token)))))) + (update-create-token {:token token})))))) (defn set-token-type-section-open [token-type open?] diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index d47811c3d..3bb0339f4 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -317,13 +317,13 @@ 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 (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!)))))))))] + (st/emit! (dt/update-create-token {:token (ctob/make-token :name final-name + :type (or (:type token) token-type) + :value final-value + :description final-description) + :prev-token-name (:name token)})) + (st/emit! (wtu/update-workspace-tokens)) + (modal/hide!))))))))] [:form {:class (stl/css :form-wrapper) :on-submit on-submit}