♻️ Simplifies RPC pattern for token sets (#6045)

* ♻️ Add set removal methods to tokens library

* ♻️ Add `set-token-set` method to changes

* ♻️ Add `set-token-set` to changes builder

* ♻️ Use new method in the token set creation

* ♻️ Use `set-token-set` in frontend events

* ♻️ Remove unused binding

* ♻️ Add tests

* ♻️ Remove old API methods

* ♻️ Remove unused parts of schema and multimethods

* ♻️ Make `:tokens` key optional in schema

* ♻️ Add `with-library-data` calls before `set-token-set`

* ♻️ Fix DOM properties error
This commit is contained in:
Andrei Fëdorov 2025-03-11 16:03:52 +01:00 committed by GitHub
parent f35723e772
commit b52e8bc87c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 165 additions and 90 deletions

View file

@ -127,11 +127,17 @@
(update state :workspace-tokens dissoc :token-set-new-path))
ptk/WatchEvent
(watch [it _ _]
(let [token-set (update token-set :name #(if (empty? %) set-name (ctob/join-set-path [% set-name])))
(watch [it state _]
(let [token-set' (-> token-set
(update :name #(if (empty? %)
set-name
(ctob/join-set-path [% set-name]))))
data (dsh/lookup-file-data state)
token-set-name (:name token-set')
changes (-> (pcb/empty-changes it)
(pcb/add-token-set token-set))]
(rx/of (set-selected-token-set-name (:name token-set))
(pcb/with-library-data data)
(pcb/set-token-set token-set-name false token-set'))]
(rx/of (set-selected-token-set-name token-set-name)
(dch/commit-changes changes))))))
(defn rename-token-set-group [set-group-path set-group-fname]
@ -147,10 +153,10 @@
(ptk/reify ::update-token-set
ptk/WatchEvent
(watch [it state _]
(let [prev-token-set (some-> (get-tokens-lib state)
(ctob/get-set set-name))
(let [data (dsh/lookup-file-data state)
changes (-> (pcb/empty-changes it)
(pcb/update-token-set token-set prev-token-set))]
(pcb/with-library-data data)
(pcb/set-token-set set-name false token-set))]
(rx/of
(set-selected-token-set-name (:name token-set))
(dch/commit-changes changes))))))
@ -196,7 +202,7 @@
(let [data (dsh/lookup-file-data state)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
(pcb/delete-token-set-path group? path))]
(pcb/set-token-set (ctob/join-set-path path) group? nil))]
(rx/of (dch/commit-changes changes)
(wtu/update-workspace-tokens))))))
@ -245,9 +251,11 @@
[token]
(ptk/reify ::create-token-and-set
ptk/WatchEvent
(watch [_ _ _]
(watch [_ state _]
(let [set-name "Global"
data (dsh/lookup-file-data state)
token-set
(-> (ctob/make-token-set :name set-name)
(ctob/add-token token))
@ -259,7 +267,9 @@
(ctob/enable-set hidden-theme set-name)
changes
(pcb/add-token-set (pcb/empty-changes) token-set)
(-> (pcb/empty-changes)
(pcb/with-library-data data)
(pcb/set-token-set set-name false token-set))
changes
(-> changes

View file

@ -492,7 +492,7 @@
:auto-focus true
:label (tr "workspace.token.token-name")
:default-value @name-ref
:maxlength 256
:max-length 256
:on-blur on-blur-name
:on-change on-update-name}])
@ -515,7 +515,7 @@
{:id "token-value"
:placeholder (tr "workspace.token.enter-token-value")
:label (tr "workspace.token.token-value")
:maxlength 256
:max-length 256
:default-value @value-ref
:ref value-input-ref
:on-change on-update-value
@ -534,7 +534,7 @@
{:id "token-description"
:placeholder (tr "workspace.token.enter-token-description")
:label (tr "workspace.token.token-description")
:maxlength 256
:max-length 256
:default-value @description-ref
:on-blur on-update-description
:on-change on-update-description}]