From ec96e7918d98d57f41e039ae2df9430b1f95e558 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Wed, 25 Sep 2024 08:16:29 +0200 Subject: [PATCH] Token theme deletion --- common/src/app/common/files/changes.cljc | 5 ++--- common/src/app/common/files/changes_builder.cljc | 10 ++++++---- frontend/src/app/main/data/tokens.cljs | 4 ++-- .../app/main/ui/workspace/tokens/modals/themes.cljs | 11 ++++++----- .../app/main/ui/workspace/tokens/theme_select.cljs | 7 ++++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index fca19bc28..e4af8d1ed 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -281,7 +281,7 @@ [:del-token-theme [:map {:title "DelTokenThemeChange"} [:type [:= :del-token-theme]] - [:id ::sm/uuid] + [:group :string] [:name :string]]] [:add-token-set @@ -885,9 +885,8 @@ (update :sets (partial set-ids->names data)))))))))) (defmethod process-change :del-token-theme - [data {:keys [id group name]}] + [data {:keys [group name]}] (-> data - (ctotl/delete-token-theme id) (update :tokens-lib #(-> % (ctob/ensure-tokens-lib) diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 6fd4aac22..c422adb2c 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -20,7 +20,8 @@ [app.common.types.component :as ctk] [app.common.types.file :as ctf] [app.common.types.shape.layout :as ctl] - [app.common.uuid :as uuid])) + [app.common.uuid :as uuid] + [app.common.types.tokens-lib :as ctob])) ;; Auxiliary functions to help create a set of changes (undo + redo) @@ -724,12 +725,13 @@ (apply-changes-local))) (defn delete-token-theme - [changes token-theme-id] + [changes group name] (assert-library! changes) (let [library-data (::library-data (meta changes)) - prev-token-theme (get-in library-data [:token-themes-index token-theme-id])] + prev-token-theme (some-> (get library-data :tokens-lib) + (ctob/get-theme group name))] (-> changes - (update :redo-changes conj {:type :del-token-theme :id token-theme-id :name (:name prev-token-theme)}) + (update :redo-changes conj {:type :del-token-theme :group group :name name}) (update :undo-changes conj {:type :add-token-theme :token-theme prev-token-theme}) (apply-changes-local)))) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index fb0fd0ee0..44d913c45 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -154,14 +154,14 @@ (rx/of (dch/commit-changes changes)))))) -(defn delete-token-theme [token-theme-id] +(defn delete-token-theme [group name] (ptk/reify ::delete-token-theme ptk/WatchEvent (watch [it state _] (let [data (get state :workspace-data) changes (-> (pcb/empty-changes it) (pcb/with-library-data data) - (pcb/delete-token-theme token-theme-id))] + (pcb/delete-token-theme group name))] (rx/of (dch/commit-changes changes) (wtu/update-workspace-tokens)))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index c992ef46c..afc1d0c4f 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -70,9 +70,10 @@ (when (seq group) [:span {:class (stl/css :theme-group-label)} group]) [:ul {:class (stl/css :theme-group-rows-wrapper)} - (for [[_ {:keys [id group name] :as theme}] themes - :let [selected? (some? (get active-theme-ids (ctob/theme-path theme)))]] - [:li {:key (str "token-theme-" id) + (for [[_ {:keys [group name] :as theme}] themes + :let [theme-id (ctob/theme-path theme) + selected? (some? (get active-theme-ids theme-id))]] + [:li {:key theme-id :class (stl/css :theme-row)} [:div {:class (stl/css :theme-row-left)} [:div {:on-click (fn [e] @@ -97,7 +98,7 @@ [:button {:on-click (fn [e] (dom/prevent-default e) (dom/stop-propagation e) - (st/emit! (wdt/delete-token-theme id)))} + (st/emit! (wdt/delete-token-theme group name)))} i/delete]]]])]])] [:div {:class (stl/css :button-footer)} [:button {:class (stl/css :create-theme-button) @@ -195,7 +196,7 @@ [:button {:class (stl/css :button-secondary) :type "button" :on-click (fn [] - (st/emit! (wdt/delete-token-theme (:id theme))) + (st/emit! (wdt/delete-token-theme (:group theme) (:name theme))) (on-back))} "Delete"] [:div]) diff --git a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs index 49b169a78..c8a30f678 100644 --- a/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/theme_select.cljs @@ -23,9 +23,10 @@ [{:keys [themes active-theme-ids on-close grouped?]}] (when (seq themes) [:ul - (for [[_ {:keys [id group name] :as theme}] themes - :let [selected? (get active-theme-ids (ctob/theme-path theme))]] - [:li {:key id + (for [[_ {:keys [group name] :as theme}] themes + :let [theme-id (ctob/theme-path theme) + selected? (get active-theme-ids theme-id)]] + [:li {:key theme-id :class (stl/css-case :checked-element true :sub-item grouped?