From 1d50bacfbc412ceca036820ade12fbd952a5c75e Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 26 Sep 2024 17:21:02 +0200 Subject: [PATCH] Fix set renaming not being updated in themes --- common/src/app/common/files/changes.cljc | 13 ++++++++----- common/src/app/common/types/tokens_lib.cljc | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index eb65fd669..f43fb7199 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -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]}] diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 1ca3e0987..2811a13d9 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -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)