0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-08 13:01:24 -05:00

Fix set renaming not being updated in themes

This commit is contained in:
Florian Schroedl 2024-09-26 17:21:02 +02:00
parent 7c4cbe5265
commit 1d50bacfbc
2 changed files with 25 additions and 7 deletions

View file

@ -882,11 +882,14 @@
[data {:keys [name token-set]}]
(-> data
(update :tokens-lib
#(-> %
(ctob/ensure-tokens-lib)
(ctob/update-set name (fn [prev-set]
(merge prev-set
(dissoc token-set :tokens))))))))
(fn [element]
(let [path-changed? (not= name (:name token-set))
lib (-> element
(ctob/ensure-tokens-lib)
(ctob/update-set name (fn [prev-set]
(merge prev-set (dissoc token-set :tokens)))))]
(cond-> lib
path-changed? (ctob/update-set-name name (:name token-set))))))))
(defmethod process-change :del-token-set
[data {:keys [name]}]

View file

@ -6,6 +6,7 @@
(ns app.common.types.tokens-lib
(:require
#?(:clj [app.common.fressian :as fres])
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.schema :as sm]
@ -13,8 +14,8 @@
[app.common.transit :as t]
[app.common.types.token :as cto]
[clojure.set :as set]
[cuerdas.core :as str]
#?(:clj [app.common.fressian :as fres])))
[clojure.walk :as walk]
[cuerdas.core :as str]))
;; === Groups handling
@ -391,6 +392,7 @@
(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")
(update-set-name [_ old-set-name new-set-name] "updates set name in themes")
(validate [_]))
(deftype TokensLib [sets set-groups themes active-themes]
@ -614,6 +616,19 @@
acc))
(d/ordered-map) (tree-seq d/ordered-map? vals themes)))
(update-set-name [_ old-set-name new-set-name]
(TokensLib. sets
set-groups
(walk/postwalk
(fn [form]
(if (instance? TokenTheme form)
(-> form
(update :sets disj old-set-name)
(update :sets conj new-set-name))
form))
themes)
active-themes))
(validate [_]
(and (valid-token-sets? sets) ;; TODO: validate set-groups
(valid-token-themes? themes)