0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-07 23:08:24 -05:00

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)))
(defn update-token
[changes token]
(let [token-id (:id token)]
(-> changes
(update :redo-changes conj {:type :mod-token :id token-id :token token})
(apply-changes-local))))
[changes {:keys [id] :as token} prev-token]
(-> changes
(update :redo-changes conj {:type :mod-token :id id :token token})
(update :undo-changes conj {:type :mod-token :id id :token (or prev-token token)})
(apply-changes-local)))
(defn delete-token
[changes token-id]

View file

@ -95,14 +95,18 @@
(let [workspace-data (deref refs/workspace-data)]
(get (:tokens workspace-data) id)))
(defn add-token
(defn update-create-token
[token]
(let [token (update token :id #(or % (uuid/next)))]
(ptk/reify ::add-token
ptk/WatchEvent
(watch [it _ _]
(let [changes (-> (pcb/empty-changes it)
(pcb/add-token token))]
(let [prev-token (get-token-data-from-token-id (:id 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)))))))
(defn delete-token
@ -122,7 +126,7 @@
(let [new-token (-> (get-token-data-from-token-id id)
(dissoc :id)
(update :name #(str/concat % "-copy")))]
(add-token new-token)))
(update-create-token new-token)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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
;; We do not handle the error case as it will be handled by the components validations
(when (and (seq result) (not err))
(let [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)))]
(st/emit! (dt/add-token token))
(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)))]
(st/emit! (dt/update-create-token new-token))
(st/emit! (wtu/update-workspace-tokens-event))
(modal/hide!)))))))))]
[:form