From 5e301605ade4bb9c80b3a4942030928424c47866 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 15 May 2024 17:44:06 +0200 Subject: [PATCH] Extract token grouping to core --- frontend/src/app/main/ui/workspace/tokens/core.cljs | 6 ++++++ frontend/src/app/main/ui/workspace/tokens/sidebar.cljs | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index b1e0aabbff..2fd5bfc1a5 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -37,6 +37,12 @@ int-or-double (throw (ex-info (str "Implement token value resolve for " value) token)))) +(defn group-tokens-by-type + "Groups tokens by their `:type` property." + [tokens] + (->> (vals tokens) + (group-by :type))) + ;; Update functions ------------------------------------------------------------ (defn on-apply-token [{:keys [token token-type-props selected-shapes] :as _props}] diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index ae607051cd..015d2635f1 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -113,13 +113,12 @@ "Separate token-types into groups of `:empty` or `:filled` depending if tokens exist for that type. Sort each group alphabetically (by their `:token-key`)." [tokens] - (let [tokens-by-group (->> (vals tokens) - (group-by :type)) + (let [tokens-by-type (wtc/group-tokens-by-type tokens) {:keys [empty filled]} (->> wtc/token-types (map (fn [[token-key token-type-props]] {:token-key token-key :token-type-props token-type-props - :tokens (get tokens-by-group token-key [])})) + :tokens (get tokens-by-type token-key [])})) (group-by (fn [{:keys [tokens]}] (if (empty? tokens) :empty :filled))))] {:empty (sort-by :token-key empty)