diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index f75d2b905..518c3e930 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1237,6 +1237,20 @@ (update data :tokens-lib update-tokens-lib) data))) +(defmethod migrate-data "Add token theme id" + [data _] + (letfn [(update-tokens-lib [tokens-lib] + (let [themes (ctob/get-themes tokens-lib)] + (reduce (fn [lib theme] + (if (:id theme) + lib + (ctob/update-theme lib (:group theme) (:name theme) #(assoc % :id (str (uuid/next)))))) + tokens-lib + themes)))] + (if (contains? data :tokens-lib) + (update data :tokens-lib update-tokens-lib) + data))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1291,4 +1305,5 @@ "legacy-65" "legacy-66" "legacy-67" - "Add hidden theme"])) + "Add hidden theme" + "Add token theme id"])) diff --git a/common/src/app/common/types/token_theme.cljc b/common/src/app/common/types/token_theme.cljc index 0482fa8c5..e4c699b73 100644 --- a/common/src/app/common/types/token_theme.cljc +++ b/common/src/app/common/types/token_theme.cljc @@ -15,6 +15,7 @@ [:group :string] [:description [:maybe :string]] [:is-source :boolean] + [:id :string] [:modified-at {:optional true} ::sm/inst] [:sets :any]]) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index cde6d9fa6..4b8ffd9b3 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -13,6 +13,7 @@ [app.common.time :as dt] [app.common.transit :as t] [app.common.types.token :as cto] + [app.common.uuid :as uuid] [clojure.set :as set] [clojure.walk :as walk] [cuerdas.core :as str])) @@ -496,13 +497,14 @@ (theme-matches-group-name [_ group name] "if a theme matches the given group & name") (hidden-temporary-theme? [_] "if a theme is the (from the user ui) hidden temporary theme")) -(defrecord TokenTheme [name group description is-source modified-at sets] +(defrecord TokenTheme [name group description is-source id modified-at sets] ITokenTheme (set-sets [_ set-names] (TokenTheme. name group description is-source + id (dt/now) set-names)) @@ -529,6 +531,7 @@ group description is-source + id (dt/now) (conj (disj sets prev-set-name) set-name)) this)) @@ -553,6 +556,7 @@ [:group :string] [:description [:maybe :string]] [:is-source [:maybe :boolean]] + [:id :string] [:modified-at ::sm/inst] [:sets [:set {:gen/max 5} :string]]]) @@ -583,10 +587,11 @@ [& {:as attrs}] (-> attrs (update :group d/nilv top-level-theme-group-name) + (update :description d/nilv "") (update :is-source d/nilv false) + (update :id d/nilv (str (uuid/next))) (update :modified-at #(or % (dt/now))) (update :sets set) - (update :description d/nilv "") (check-token-theme-attrs) (map->TokenTheme))) @@ -595,6 +600,7 @@ (-> attrs (assoc :group hidden-token-theme-group) (assoc :name hidden-token-theme-name) + (assoc :id (str uuid/zero)) (make-token-theme))) ;; === TokenThemes (collection) @@ -1269,11 +1275,12 @@ Will return a value that matches this schema: (if-let [themes-data (seq themes-data)] (as-> lib' $ (reduce - (fn [lib {:strs [name group description is-source modified-at sets]}] + (fn [lib {:strs [name group description is-source id modified-at sets]}] (add-theme lib (TokenTheme. name (or group "") description (some? is-source) + (or id (str (uuid/next))) (or (some-> modified-at (dt/parse-instant)) (dt/now)) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 44f76ac6c..384522718 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -1257,6 +1257,7 @@ :value "{accent.default}"})})) (ctob/add-theme (ctob/make-token-theme :name "theme-1" :group "group-1" + :id "test-id-00" :modified-at now :sets #{"core"}))) result (ctob/encode-dtcg tokens-lib) @@ -1264,6 +1265,7 @@ "group" "group-1" "is-source" false "modified-at" now + "id" "test-id-00" "name" "theme-1" "selectedTokenSets" {"core" "enabled"}}] "$metadata" {"tokenSetOrder" ["core"] @@ -1304,6 +1306,7 @@ {:name "button.primary.background" :type :color :value "{accent.default}"})}))) + encoded (ctob/encode-dtcg tokens-lib) with-prev-tokens-lib (ctob/decode-dtcg-json tokens-lib encoded) with-empty-tokens-lib (ctob/decode-dtcg-json (ctob/ensure-tokens-lib nil) encoded)] @@ -1374,6 +1377,7 @@ :value "{accent.default}"})})) (ctob/add-theme (ctob/make-token-theme :name "theme-1" :group "group-1" + :id "test-id-01" :modified-at now :sets #{"core"})) (ctob/toggle-theme-active? "group-1" "theme-1")) @@ -1382,6 +1386,7 @@ "group" "group-1" "is-source" false "modified-at" now + "id" "test-id-01" "name" "theme-1" "selectedTokenSets" {"core" "enabled"}}] "$metadata" {"tokenSetOrder" ["core"] diff --git a/frontend/playwright/data/workspace/get-file-tokens.json b/frontend/playwright/data/workspace/get-file-tokens.json index ba15a126a..84143b7a4 100644 --- a/frontend/playwright/data/workspace/get-file-tokens.json +++ b/frontend/playwright/data/workspace/get-file-tokens.json @@ -1748,6 +1748,7 @@ "~:group": "Core", "~:description": null, "~:is-source": false, + "~:id": "core-light", "~:modified-at": "~m1737542746842", "~:sets": { "~#set": ["LightDark/light", "theme", "core"] @@ -1763,6 +1764,7 @@ "~:group": "Core", "~:description": null, "~:is-source": false, + "~:id": "core-dark", "~:modified-at": "~m1737542746842", "~:sets": { "~#set": ["LightDark/dark", "theme", "core"] @@ -1785,6 +1787,7 @@ "~:group": "", "~:description": null, "~:is-source": false, + "~:id": "hidden-theme", "~:modified-at": "~m1737542683555", "~:sets": { "~#set": ["LightDark/light", "theme", "core"]