diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 1ef5f483d..a830bdefc 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -376,11 +376,6 @@ [:type [:= :update-active-token-themes]] [:theme-ids [:set :string]]]] - [:add-token-sets - [:map {:title "AddTokenSetsChange"} - [:type [:= :add-token-sets]] - [:token-sets [:sequential ::ctot/token-set]]]] - [:rename-token-set-group [:map {:title "RenameTokenSetGroup"} [:type [:= :rename-token-set-group]] @@ -1049,12 +1044,6 @@ (update data :tokens-lib #(-> % (ctob/ensure-tokens-lib) (ctob/set-active-themes theme-ids)))) -(defmethod process-change :add-token-sets - [data {:keys [token-sets]}] - (update data :tokens-lib #(-> % - (ctob/ensure-tokens-lib) - (ctob/add-sets (map ctob/make-token-set token-sets))))) - (defmethod process-change :rename-token-set-group [data {:keys [set-group-path set-group-fname]}] (update data :tokens-lib (fn [lib] diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 4fa55c3ed..3cceedc30 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -430,7 +430,6 @@ Prefixed set full path or pfpath: a full path wit prefixes [\"G-some-group\", \"G-some-subgroup\", \"S-some-set\"]. Prefixed set final name or pfname: a final name with prefix \"S-some-set\"." (add-set [_ token-set] "add a set to the library, at the end") - (add-sets [_ token-set] "add a collection of sets to the library, at the end") (update-set [_ set-name f] "modify a set in the library") (delete-set-path [_ set-path] "delete a set in the library") (delete-set [_ set-name] "delete a set at `set-name` in the library and disable the `set-name` in all themes") @@ -875,9 +874,6 @@ Will return a value that matches this schema: themes active-themes))) - (add-sets [this token-sets] - (reduce add-set this token-sets)) - (update-set [this set-name f] (let [prefixed-full-path (set-name->prefixed-full-path set-name) set (get-in sets prefixed-full-path)] @@ -1483,10 +1479,12 @@ Will return a value that matches this schema: prev-sets (->> (fres/read-object! r) (tree-seq d/ordered-map? vals) (filter (partial instance? TokenSet))) - sets (-> (make-tokens-lib) - (add-sets prev-sets) - (deref) - :sets) + + ;; FIXME: wtf we usind deref here? + sets (-> (reduce add-set (make-tokens-lib) prev-sets) + (deref) + (:sets)) + _set-groups (fres/read-object! r) themes (fres/read-object! r) active-themes (fres/read-object! r)] diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index d56824011..ba9cb5f12 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -86,22 +86,22 @@ (t/deftest move-token-set (t/testing "flat" - (let [tokens-lib (-> (ctob/make-tokens-lib) - (ctob/add-set (ctob/make-token-set :name "A")) - (ctob/add-set (ctob/make-token-set :name "B")) - (ctob/add-set (ctob/make-token-set :name "Move"))) - move (fn [from-path to-path before-path before-group?] - (->> (ctob/move-set tokens-lib from-path to-path before-path before-group?) - (ctob/get-ordered-set-names) - (into [])))] - (t/testing "move to top" - (t/is (= ["Move" "A" "B"] (move ["Move"] ["Move"] ["A"] false)))) + (let [tokens-lib (-> (ctob/make-tokens-lib) + (ctob/add-set (ctob/make-token-set :name "A")) + (ctob/add-set (ctob/make-token-set :name "B")) + (ctob/add-set (ctob/make-token-set :name "Move"))) + move (fn [from-path to-path before-path before-group?] + (->> (ctob/move-set tokens-lib from-path to-path before-path before-group?) + (ctob/get-ordered-set-names) + (into [])))] + (t/testing "move to top" + (t/is (= ["Move" "A" "B"] (move ["Move"] ["Move"] ["A"] false)))) - (t/testing "move in-between" - (t/is (= ["A" "Move" "B"] (move ["Move"] ["Move"] ["B"] false)))) + (t/testing "move in-between" + (t/is (= ["A" "Move" "B"] (move ["Move"] ["Move"] ["B"] false)))) - (t/testing "move to bottom" - (t/is (= ["A" "B" "Move"] (move ["Move"] ["Move"] nil false)))))) + (t/testing "move to bottom" + (t/is (= ["A" "B" "Move"] (move ["Move"] ["Move"] nil false)))))) (t/testing "nested" (let [tokens-lib (-> (ctob/make-tokens-lib) @@ -129,7 +129,7 @@ (ctob/add-theme (ctob/make-token-theme :name "Theme" :sets #{"Foo/Bar/Baz"})) (ctob/move-set ["Foo" "Bar" "Baz"] ["Other/Baz"] nil nil))] - (t/is (= #{"Other/Baz"} (:sets (ctob/get-theme tokens-lib "" "Theme"))))))) + (t/is (= #{"Other/Baz"} (:sets (ctob/get-theme tokens-lib "" "Theme"))))))) (t/deftest move-token-set-group (t/testing "reordering" @@ -590,7 +590,7 @@ :type :boolean :value true)) (ctob/add-theme (ctob/make-token-theme :name "test-token-theme")) - (ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set")) + (ctob/toggle-set-in-theme "" "test-token-theme" "test-token-set")) encoded-blob (fres/encode tokens-lib) tokens-lib' (fres/decode encoded-blob)] diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index e272fe193..ff6bd74e9 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -139,7 +139,7 @@ (let [data (dsh/lookup-file-data state) tokens-lib (get data :tokens-lib) set-name (ctob/normalize-set-name set-name)] - (if (ctob/get-set tokens-lib set-name) + (if (and tokens-lib (ctob/get-set tokens-lib set-name)) (rx/of (ntf/show {:content (tr "errors.token-set-already-exists") :type :toast :level :error 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 59eea1915..0a2ba9f19 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -293,11 +293,12 @@ :on-save-form on-save-form :disabled? disabled?}]]]]])) -(defn- make-lib-with-theme [theme sets] - (-> (ctob/make-tokens-lib) - (ctob/add-theme theme) - (ctob/add-sets sets) - (ctob/activate-theme (:group theme) (:name theme)))) +(defn- make-lib-with-theme + [theme sets] + (let [tlib (-> (ctob/make-tokens-lib) + (ctob/add-theme theme)) + tlib (reduce ctob/add-set tlib sets)] + (ctob/activate-theme tlib (:group theme) (:name theme)))) (mf/defc controlled-edit-theme [{:keys [state set-state]}]