mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
Update token sets
This commit is contained in:
parent
9aadb8c72f
commit
1135b7e2db
3 changed files with 28 additions and 8 deletions
|
@ -7,7 +7,6 @@
|
||||||
(ns app.common.types.tokens-theme-list
|
(ns app.common.types.tokens-theme-list
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex]
|
|
||||||
[app.common.time :as dt]))
|
[app.common.time :as dt]))
|
||||||
|
|
||||||
(defn- touch
|
(defn- touch
|
||||||
|
@ -28,11 +27,9 @@
|
||||||
(update :token-sets-index assoc id token-set)))
|
(update :token-sets-index assoc id token-set)))
|
||||||
|
|
||||||
(defn update-token-set
|
(defn update-token-set
|
||||||
[file-data token-id f & args]
|
[file-data token-set-id f & args]
|
||||||
#_(ex/raise :type :not-implemented)
|
(d/update-in-when file-data [:token-sets-index token-set-id] #(-> (apply f % args) (touch))))
|
||||||
file-data)
|
|
||||||
|
|
||||||
(defn delete-token-set
|
(defn delete-token-set
|
||||||
[file-data token-id]
|
[file-data token-id]
|
||||||
#_(ex/raise :type :not-implemented)
|
|
||||||
file-data)
|
file-data)
|
||||||
|
|
|
@ -131,6 +131,9 @@
|
||||||
new-token-set {:id (uuid/next)
|
new-token-set {:id (uuid/next)
|
||||||
:name "Global"
|
:name "Global"
|
||||||
:tokens [(:id token)]}
|
:tokens [(:id token)]}
|
||||||
|
selected-token-set-id (if create-set?
|
||||||
|
(:id new-token-set)
|
||||||
|
(:id token-set))
|
||||||
changes (cond
|
changes (cond
|
||||||
create-set? (-> token-changes
|
create-set? (-> token-changes
|
||||||
(pcb/add-token-set new-token-set))
|
(pcb/add-token-set new-token-set))
|
||||||
|
@ -138,9 +141,9 @@
|
||||||
token-set
|
token-set
|
||||||
(update token-set :tokens conj (:id token)))]
|
(update token-set :tokens conj (:id token)))]
|
||||||
(-> token-changes
|
(-> token-changes
|
||||||
(pcb/update-token-set token-set updated-token-set))))]
|
(pcb/update-token-set updated-token-set token-set))))]
|
||||||
(rx/of
|
(rx/of
|
||||||
(set-selected-token-set-id (:id new-token-set))
|
(set-selected-token-set-id selected-token-set-id)
|
||||||
(dch/commit-changes changes)))))))
|
(dch/commit-changes changes)))))))
|
||||||
|
|
||||||
(defn delete-token
|
(defn delete-token
|
||||||
|
|
|
@ -59,10 +59,30 @@
|
||||||
(t/testing "selects created workspace set and adds token to it"
|
(t/testing "selects created workspace set and adds token to it"
|
||||||
(t/is (some? selected-token-set))
|
(t/is (some? selected-token-set))
|
||||||
(t/is (= 1 (count (:tokens selected-token-set))))
|
(t/is (= 1 (count (:tokens selected-token-set))))
|
||||||
(t/is (= (list border-radius-token) (map #(dissoc % :id :modified-at) set-tokens))))
|
(t/is (= (list border-radius-token) (map #(dissoc % :id :modified-at) set-tokens)))))))))))
|
||||||
|
|
||||||
|
(t/deftest test-create-multiple-tokens
|
||||||
|
(t/testing "uses selected tokens set when creating multiple tokens"
|
||||||
|
(t/async
|
||||||
|
done
|
||||||
|
(let [file (setup-file)
|
||||||
|
store (ths/setup-store file)
|
||||||
|
events [(wdt/update-create-token border-radius-token)
|
||||||
|
(wdt/update-create-token reference-border-radius-token)]]
|
||||||
|
(tohs/run-store-async
|
||||||
|
store done events
|
||||||
|
(fn [new-state]
|
||||||
|
(let [selected-token-set (wdt/get-selected-token-set new-state)
|
||||||
|
file' (ths/get-file-from-store new-state)
|
||||||
|
set-tokens (wdt/get-token-set-tokens selected-token-set file')]
|
||||||
|
(t/testing "selects created workspace set and adds token to it"
|
||||||
|
(t/is (some? selected-token-set))
|
||||||
|
(t/is (= 2 (count (:tokens selected-token-set))))
|
||||||
|
(t/is (= (list border-radius-token reference-border-radius-token) (map #(dissoc % :id :modified-at) set-tokens))))
|
||||||
(reset! a new-state))))))))
|
(reset! a new-state))))))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
(wdt/get-selected-token-set @a)
|
||||||
@a
|
@a
|
||||||
(t/run-tests)
|
(t/run-tests)
|
||||||
nil)
|
nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue