From 0ffcda404b7fc7e41a36fc0e847584be12b53f61 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 2 Oct 2024 11:09:52 +0200 Subject: [PATCH] Cleanup --- .../app/main/ui/workspace/tokens/core.cljs | 22 +------------------ .../app/main/ui/workspace/tokens/sidebar.cljs | 5 +++-- .../app/main/ui/workspace/tokens/token.cljs | 19 ++++++++-------- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/tokens/core.cljs b/frontend/src/app/main/ui/workspace/tokens/core.cljs index b511f5c4b..c37ace5a2 100644 --- a/frontend/src/app/main/ui/workspace/tokens/core.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/core.cljs @@ -11,8 +11,7 @@ [app.main.ui.workspace.tokens.token :as wtt] [app.util.dom :as dom] [app.util.webapi :as wapi] - [cuerdas.core :as str] - [app.common.data.macros :as dm])) + [cuerdas.core :as str])) ;; Helpers --------------------------------------------------------------------- @@ -24,25 +23,6 @@ (defn maybe-resolve-token-value [{:keys [value] :as token}] (when value (resolve-token-value token))) -(defn group-tokens-by-type - "Groups tokens by their `:type` property." - [tokens] - (->> (vals tokens) - (group-by :type))) - -(dm/legacy - (defn group-tokens-by-type-OLD - "Groups tokens by their `:type` property." - [tokens] - (->> (vals tokens) - (group-by :type)))) - -(defn tokens-name-map->select-options-OLD [{:keys [shape tokens attributes selected-attributes]}] - (->> (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)))))) - (defn tokens->select-options [{:keys [shape tokens attributes selected-attributes]}] (map (fn [{:keys [name] :as item}] diff --git a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs index 9bc807478..683265113 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sidebar.cljs @@ -32,7 +32,8 @@ [cuerdas.core :as str] [okulary.core :as l] [rumext.v2 :as mf] - [shadow.resource])) + [shadow.resource] + [app.common.types.tokens-lib :as ctob])) (def lens:token-type-open-status (l/derived (l/in [:workspace-tokens :open-status]) st/state)) @@ -150,7 +151,7 @@ "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-type (wtc/group-tokens-by-type tokens) + (let [tokens-by-type (ctob/group-by-type tokens) {:keys [empty filled]} (->> wtty/token-types (map (fn [[token-key token-type-props]] {:token-key token-key diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index c55f5c60f..b12ce4e55 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -117,16 +117,15 @@ :ids-map {}} tokens)) -(dm/legacy - (defn token-names-tree - "Convert tokens into a nested tree with their `:name` as the path." - [tokens] - (reduce - (fn [acc [_ {:keys [name] :as token}]] - (when (string? name) - (let [path (token-name->path name)] - (assoc-in acc path token)))) - {} tokens))) +(defn token-names-tree + "Convert tokens into a nested tree with their `:name` as the path." + [tokens] + (reduce + (fn [acc [_ {:keys [name] :as token}]] + (when (string? name) + (let [path (token-name->path name)] + (assoc-in acc path token)))) + {} tokens)) (defn token-name-path-exists? "Traverses the path from `token-name` down a `token-tree` and checks if a token at that path exists.