From 99e551925aa6cc3d12c8fcce9cc7a6564dabbb6b Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 11:08:54 +0200 Subject: [PATCH] Updates --- common/src/app/common/types/tokens_lib.cljc | 17 ++++++++++++++ .../common_tests/types/tokens_lib_test.cljc | 13 +++++++++++ frontend/src/app/main/refs.cljs | 13 ++++++----- .../app/main/ui/workspace/tokens/sets.cljs | 23 ++++++++++--------- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 5dd6e2a53..927f7ee8c 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -363,6 +363,8 @@ (update-token-in-set [_ set-name token-name f] "update a token in a set") (delete-token-from-set [_ set-name token-name] "delete a token from a set") (toggle-set-in-theme [_ group-name theme-name set-name] "toggle a set used / not used in a theme") + (get-active-themes-set-names [_] "set of set names that are active in the the active themes") + (get-active-themes-set-tokens [_] "set of set names that are active in the the active themes") (validate [_])) (deftype TokensLib [sets set-groups themes active-themes] @@ -571,6 +573,21 @@ active-themes) this)) + (get-active-themes-set-names [this] + (into #{} + (mapcat :sets) + (get-active-themes this))) + + (get-active-themes-set-tokens [this] + (mapcat (fn [x] + (->> (get x :sets) + (map (fn [y] + (-> + (get-set this y) + :tokens))))) + (get-active-themes this))) + + (validate [_] (and (valid-token-sets? sets) ;; TODO: validate set-groups (valid-token-themes? themes) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 377372a84..8c4d9f469 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -182,6 +182,19 @@ (t/is (dt/is-after? (:modified-at token-set') (:modified-at token-set))))) (t/deftest delete-token-set + (let [tokens-lib (-> (ctob/make-tokens-lib) + (ctob/add-set (ctob/make-token-set :name "test-token-set"))) + + tokens-lib' (-> tokens-lib + (ctob/delete-set "test-token-set") + (ctob/delete-set "not-existing-set")) + + token-set' (ctob/get-set tokens-lib' "updated-name")] + + (t/is (= (ctob/set-count tokens-lib') 0)) + (t/is (nil? token-set')))) + + (t/deftest active-themes-set-names (let [tokens-lib (-> (ctob/make-tokens-lib) (ctob/add-set (ctob/make-token-set :name "test-token-set"))) diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index e8b0b7b32..2e460ffb0 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -474,16 +474,17 @@ (def workspace-active-theme-paths (l/derived #(some-> % ctob/get-active-theme-paths) tokens-lib)) +(def workspace-active-set-names + (l/derived #(some-> % ctob/get-active-themes-set-names) tokens-lib)) + +(def workspace-active-theme-sets-tokens + #_(l/derived wtts/get-active-theme-sets-tokens-names-map st/state =) + (l/derived #(some-> % ctob/get-active-themes-set-tokens) tokens-lib)) + (dm/legacy (def workspace-temp-theme-id (l/derived wtts/get-temp-theme-id st/state)) - (def workspace-active-set-ids - (l/derived wtts/get-active-set-ids st/state)) - - (def workspace-active-theme-sets-tokens - (l/derived wtts/get-active-theme-sets-tokens-names-map st/state =)) - (def workspace-ordered-token-sets-tokens (l/derived wtts/get-workspace-ordered-sets-tokens st/state =)) diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index fade69a90..48beaa723 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.sets (:require-macros [app.main.style :as stl]) (:require + [app.common.data.macros :as dm] [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] @@ -26,9 +27,9 @@ (defn on-select-token-set-click [name] (st/emit! (wdt/set-selected-token-set-id name))) -(defn on-delete-token-set-click [id name event] +(defn on-delete-token-set-click [name event] (dom/stop-propagation event) - (st/emit! (wdt/delete-token-set id name))) + (st/emit! (wdt/delete-token-set (dm/legacy nil) name))) (defn on-update-token-set [token-set] (st/emit! (wdt/update-token-set token-set))) @@ -71,13 +72,13 @@ on-submit on-cancel] :as _props}] - (let [{:keys [id name _children]} token-set + (let [{:keys [name _children]} token-set selected? (and set? (token-set-selected? name)) - visible? (token-set-active? id) + visible? (token-set-active? name) collapsed? (mf/use-state false) set? true #_(= type :set) group? false #_(= type :group) - editing-node? (editing? id) + editing-node? (editing? name) on-select (mf/use-callback (mf/deps editing-node?) (fn [event] @@ -85,7 +86,7 @@ (when-not editing-node? (on-select name)))) on-context-menu (mf/use-callback - (mf/deps editing-node? id) + (mf/deps editing-node? name) (fn [event] (dom/prevent-default event) (dom/stop-propagation event) @@ -93,11 +94,11 @@ (st/emit! (wdt/show-token-set-context-menu {:position (dom/get-client-position event) - :token-set-id id + :token-set-id name :token-set-name name})))))] [:div {:class (stl/css :set-item-container) :on-click on-select - :on-double-click #(on-edit id) + :on-double-click #(on-edit name) :on-context-menu on-context-menu} [:div {:class (stl/css-case :set-item-group group? :set-item-set set? @@ -116,14 +117,14 @@ [:* [:div {:class (stl/css :set-name)} name] [:div {:class (stl/css :delete-set)} - [:button {:on-click #(on-delete-token-set-click id name %) + [:button {:on-click #(on-delete-token-set-click name %) :type "button"} i/delete]] (if set? [:span {:class (stl/css :action-btn) :on-click (fn [event] (dom/stop-propagation event) - (on-toggle id))} + (on-toggle name))} (if visible? i/shown i/hide)] nil #_(when (and children (not @collapsed?)) @@ -181,7 +182,7 @@ (mf/deps selected-token-set-id) (fn [set-name] (= set-name selected-token-set-id))) - active-token-set-ids (mf/deref refs/workspace-active-set-ids) + active-token-set-ids (mf/deref refs/workspace-active-set-names) token-set-active? (mf/use-callback (mf/deps active-token-set-ids) (fn [id]