mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Merge pull request #284 from tokens-studio/refactor-theme-groups
tokens-lib refactor: Get collection of theme groups
This commit is contained in:
commit
1a9d703bb1
3 changed files with 35 additions and 6 deletions
|
@ -283,11 +283,18 @@
|
|||
(def check-token-theme!
|
||||
(sm/check-fn ::token-theme))
|
||||
|
||||
(def top-level-theme-group-name
|
||||
"Top level theme groups have an empty string as the theme group."
|
||||
"")
|
||||
|
||||
(defn top-level-theme-group? [group]
|
||||
(= group top-level-theme-group-name))
|
||||
|
||||
(defn make-token-theme
|
||||
[& {:keys [] :as params}]
|
||||
(let [params (-> params
|
||||
(dissoc :id)
|
||||
(update :group #(or % ""))
|
||||
(update :group #(or % top-level-theme-group-name))
|
||||
(update :is-source #(or % false))
|
||||
(update :modified-at #(or % (dt/now)))
|
||||
(update :sets #(into (d/ordered-set) %)))
|
||||
|
@ -308,7 +315,8 @@
|
|||
(theme-count [_] "get the total number if themes in the library")
|
||||
(get-theme-tree [_] "get a nested tree of all themes in the library")
|
||||
(get-themes [_] "get an ordered sequence of all themes in the library")
|
||||
(get-theme [_ group name] "get one theme looking for name"))
|
||||
(get-theme [_ group name] "get one theme looking for name")
|
||||
(get-theme-groups [_] "get a sequence of group names by order"))
|
||||
|
||||
(def schema:token-themes
|
||||
[:and
|
||||
|
@ -431,6 +439,12 @@
|
|||
(get-theme-tree [_]
|
||||
themes)
|
||||
|
||||
(get-theme-groups [_]
|
||||
(into [] (comp
|
||||
(map key)
|
||||
(remove top-level-theme-group?))
|
||||
themes))
|
||||
|
||||
(get-themes [_]
|
||||
(->> (tree-seq d/ordered-map? vals themes)
|
||||
(filter (partial instance? TokenTheme))))
|
||||
|
|
|
@ -872,6 +872,15 @@
|
|||
(t/is (= (:description token-theme') "some description"))
|
||||
(t/is (dt/is-after? (:modified-at token-theme') (:modified-at token-theme)))))
|
||||
|
||||
(t/deftest get-theme-groups
|
||||
(let [token-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-2"))
|
||||
(ctob/add-theme (ctob/make-token-theme :group "group1" :name "token-theme-3"))
|
||||
(ctob/add-theme (ctob/make-token-theme :group "group2" :name "token-theme-4")))
|
||||
token-groups (ctob/get-theme-groups token-lib)]
|
||||
(t/is (= token-groups ["group1" "group2"]))))
|
||||
|
||||
(t/deftest rename-theme-in-groups
|
||||
(let [tokens-lib (-> (ctob/make-tokens-lib)
|
||||
(ctob/add-theme (ctob/make-token-theme :group "" :name "token-theme-1"))
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.workspace.tokens.token-set :as wtts]
|
||||
[okulary.core :as l]))
|
||||
[okulary.core :as l]
|
||||
[app.common.types.tokens-lib :as ctob]))
|
||||
|
||||
;; ---- Global refs
|
||||
|
||||
|
@ -240,13 +241,18 @@
|
|||
st/state
|
||||
=))
|
||||
|
||||
;; ---- Tokens
|
||||
|
||||
(def tokens-lib
|
||||
(l/derived :tokens-lib workspace-data))
|
||||
|
||||
(def workspace-token-theme-groups
|
||||
(l/derived #(some-> % ctob/get-theme-groups) tokens-lib))
|
||||
|
||||
(defn workspace-token-theme
|
||||
[id]
|
||||
(l/derived #(wtts/get-workspace-theme id %) st/state))
|
||||
|
||||
(def workspace-token-theme-groups
|
||||
(l/derived wtts/get-workspace-theme-groups st/state))
|
||||
|
||||
(def workspace-active-theme-ids
|
||||
(l/derived wtts/get-active-theme-ids st/state))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue