Fix undo deleting the token on update

This commit is contained in:
Florian Schroedl 2024-08-01 09:41:28 +02:00
parent 68415b6668
commit ac27f95091
3 changed files with 19 additions and 15 deletions

View file

@ -672,11 +672,11 @@
(apply-changes-local))) (apply-changes-local)))
(defn update-token (defn update-token
[changes token] [changes {:keys [id] :as token} prev-token]
(let [token-id (:id token)] (-> changes
(-> changes (update :redo-changes conj {:type :mod-token :id id :token token})
(update :redo-changes conj {:type :mod-token :id token-id :token token}) (update :undo-changes conj {:type :mod-token :id id :token (or prev-token token)})
(apply-changes-local)))) (apply-changes-local)))
(defn delete-token (defn delete-token
[changes token-id] [changes token-id]

View file

@ -95,14 +95,18 @@
(let [workspace-data (deref refs/workspace-data)] (let [workspace-data (deref refs/workspace-data)]
(get (:tokens workspace-data) id))) (get (:tokens workspace-data) id)))
(defn add-token (defn update-create-token
[token] [token]
(let [token (update token :id #(or % (uuid/next)))] (let [token (update token :id #(or % (uuid/next)))]
(ptk/reify ::add-token (ptk/reify ::add-token
ptk/WatchEvent ptk/WatchEvent
(watch [it _ _] (watch [it _ _]
(let [changes (-> (pcb/empty-changes it) (let [prev-token (get-token-data-from-token-id (:id token))
(pcb/add-token token))] changes (if prev-token
(-> (pcb/empty-changes it)
(pcb/update-token token prev-token))
(-> (pcb/empty-changes it)
(pcb/add-token token)))]
(rx/of (dch/commit-changes changes))))))) (rx/of (dch/commit-changes changes)))))))
(defn delete-token (defn delete-token
@ -122,7 +126,7 @@
(let [new-token (-> (get-token-data-from-token-id id) (let [new-token (-> (get-token-data-from-token-id id)
(dissoc :id) (dissoc :id)
(update :name #(str/concat % "-copy")))] (update :name #(str/concat % "-copy")))]
(add-token new-token))) (update-create-token new-token)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TEMP (Move to test) ;; TEMP (Move to test)

View file

@ -241,12 +241,12 @@ 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 [token (cond-> {:name final-name (let [new-token (cond-> {: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) final-description (assoc :description final-description)
(:id token) (assoc :id (:id token)))] (:id token) (assoc :id (:id token)))]
(st/emit! (dt/add-token token)) (st/emit! (dt/update-create-token new-token))
(st/emit! (wtu/update-workspace-tokens-event)) (st/emit! (wtu/update-workspace-tokens-event))
(modal/hide!)))))))))] (modal/hide!)))))))))]
[:form [:form