diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index b88adac6d..b4e0c13f2 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -39,25 +39,9 @@ (->> (vals tokens) (group-by :type))) -(defn tokens-name-map - "Convert tokens into a map with their `:name` as the key. - - E.g.: {\"sm\" {:token-type :border-radius :id #uuid \"000\" ...}}" - [tokens] - (->> (map (fn [{:keys [name] :as token}] [name token]) tokens) - (into {}))) - -(defn tokens-name-map-for-type - "Convert tokens with `token-type` into a map with their `:name` as the key. - - E.g.: {\"sm\" {:token-type :border-radius :id #uuid \"000\" ...}}" - [token-type tokens] - (-> (group-tokens-by-type tokens) - (get token-type []) - (tokens-name-map))) (defn tokens-name-map->select-options [{:keys [shape tokens attributes selected-attributes]}] - (->> (tokens-name-map tokens) + (->> (wtt/token-names-map tokens) (map (fn [[_k {:keys [name] :as item}]] (cond-> (assoc item :label name) (wtt/token-applied? item shape (or selected-attributes attributes)) (assoc :selected? true)))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 8a742b4d5..1750db9f3 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -35,6 +35,14 @@ {:path (seq path) :selector selector})) +(defn token-names-map + "Convert tokens into a map with their `:name` as the key. + + E.g.: {\"sm\" {:token-type :border-radius :id #uuid \"000\" ...}}" + [tokens] + (->> (map (fn [{:keys [name] :as token}] [name token]) tokens) + (into {}))) + (defn token-names-tree "Convert tokens into a nested tree with their `:name` as the path." [tokens] diff --git a/frontend/test/token_tests/token_test.cljs b/frontend/test/token_tests/token_test.cljs index 2767bf335..3486bed83 100644 --- a/frontend/test/token_tests/token_test.cljs +++ b/frontend/test/token_tests/token_test.cljs @@ -37,6 +37,13 @@ (t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz"))) (t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo..bar.baz....")))) +(t/deftest tokens-name-map-test + (t/testing "creates a a names map from tokens" + (t/is (= {"border-radius.sm" {:name "border-radius.sm", :value "10"} + "border-radius.md" {:name "border-radius.md", :value "20"}} + (wtt/token-names-map [{:name "border-radius.sm" :value "10"} + {:name "border-radius.md" :value "20"}]))))) + (t/deftest tokens-name-tree-test (t/is (= {"foo" {"bar"