0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-13 15:31:26 -05:00

Token theme deletion

This commit is contained in:
Florian Schroedl 2024-09-25 08:16:29 +02:00
parent 844819a50c
commit ec96e7918d
5 changed files with 20 additions and 17 deletions

View file

@ -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)

View file

@ -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))))

View file

@ -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))))))

View file

@ -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])

View file

@ -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?