🐛 Fix form not being saveable when editing composite token and switching tabs

This commit is contained in:
Florian Schroedl 2025-10-01 16:57:42 +02:00 committed by Andrés Moya
parent 979b4276ca
commit 17fe012f7e
2 changed files with 11 additions and 8 deletions

View File

@ -277,7 +277,8 @@ on-get-token-value: Custom function to get the input value from the dom
Custom component props: Custom component props:
custom-input-token-value: Custom component for editing/displaying the token value custom-input-token-value: Custom component for editing/displaying the token value
custom-input-token-value-props: Custom props passed to the custom-input-token-value merged with the default props" custom-input-token-value-props: Custom props passed to the custom-input-token-value merged with the default props"
[{:keys [token [{:keys [is-create
token
token-type token-type
selected-token-set-id selected-token-set-id
action action
@ -292,8 +293,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
custom-input-token-value custom-input-token-value
custom-input-token-value-props] custom-input-token-value-props]
:or {validate-token default-validate-token}}] :or {validate-token default-validate-token}}]
(let [create? (not (instance? ctob/Token token)) (let [token (or token {:type token-type})
token (or token {:type token-type})
token-properties (dwta/get-token-properties token) token-properties (dwta/get-token-properties token)
tokens-in-selected-set (mf/deref refs/workspace-all-tokens-in-selected-set) tokens-in-selected-set (mf/deref refs/workspace-all-tokens-in-selected-set)
@ -451,7 +451,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
on-submit on-submit
(mf/use-fn (mf/use-fn
(mf/deps create? validate-name validate-descripion token active-theme-tokens validate-token) (mf/deps is-create validate-name validate-descripion token active-theme-tokens validate-token)
(fn [e] (fn [e]
(dom/prevent-default e) (dom/prevent-default e)
;; We have to re-validate the current form values before submitting ;; We have to re-validate the current form values before submitting
@ -478,7 +478,7 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
(rx/subs! (rx/subs!
(fn [valid-token] (fn [valid-token]
(st/emit! (st/emit!
(if create? (if is-create
(dwtl/create-token {:name final-name (dwtl/create-token {:name final-name
:type token-type :type token-type
:value (:value valid-token) :value (:value valid-token)
@ -534,9 +534,10 @@ custom-input-token-value-props: Custom props passed to the custom-input-token-va
;; Update the value when editing an existing token ;; Update the value when editing an existing token
;; so the user doesn't have to interact with the form to validate the token ;; so the user doesn't have to interact with the form to validate the token
(mf/use-effect (mf/use-effect
(mf/deps create? resolved-tokens token token-resolve-result set-resolve-value) (mf/deps is-create token resolved-tokens token-resolve-result set-resolve-value)
(fn [] (fn []
(when (and (not create?) (when (and (not is-create)
(:value token) ;; Don't retrigger this effect when switching tabs on composite tokens
(not token-resolve-result) (not token-resolve-result)
resolved-tokens) resolved-tokens)
(-> (get resolved-tokens @token-name-ref) (-> (get resolved-tokens @token-name-ref)

View File

@ -8,6 +8,7 @@
(:require-macros [app.main.style :as stl]) (:require-macros [app.main.style :as stl])
(:require (:require
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.types.tokens-lib :as ctob]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.ui.ds.buttons.icon-button :refer [icon-button*]] [app.main.ui.ds.buttons.icon-button :refer [icon-button*]]
@ -88,7 +89,8 @@
:icon i/close :icon i/close
:variant "action" :variant "action"
:aria-label (tr "labels.close")}] :aria-label (tr "labels.close")}]
[:> form-wrapper* {:token token [:> form-wrapper* {:is-create (not (ctob/token? token))
:token token
:action action :action action
:selected-token-set-id selected-token-set-id :selected-token-set-id selected-token-set-id
:token-type token-type :token-type token-type