diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 9e7aa981fb..10e29975bd 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -376,19 +376,19 @@ [:type [:= :set-token]] [:set-id ::sm/uuid] [:token-id ::sm/uuid] - [:token [:maybe ctob/schema:token-attrs]]]] + [:attrs [:maybe ctob/schema:token-attrs]]]] [:set-token-set [:map {:title "SetTokenSetChange"} [:type [:= :set-token-set]] [:id ::sm/uuid] - [:token-set [:maybe ctob/schema:token-set-attrs]]]] + [:attrs [:maybe ctob/schema:token-set-attrs]]]] [:set-token-theme [:map {:title "SetTokenThemeChange"} [:type [:= :set-token-theme]] [:id ::sm/uuid] - [:theme [:maybe ctob/schema:token-theme-attrs]]]] + [:attrs [:maybe ctob/schema:token-theme-attrs]]]] [:set-active-token-themes [:map {:title "SetActiveTokenThemes"} @@ -976,54 +976,54 @@ (assoc data :tokens-lib tokens-lib)) (defmethod process-change :set-token - [data {:keys [set-id token-id token]}] + [data {:keys [set-id token-id attrs]}] (update data :tokens-lib (fn [lib] (let [lib' (ctob/ensure-tokens-lib lib)] (cond - (not token) + (not attrs) (ctob/delete-token lib' set-id token-id) (not (ctob/get-token lib' set-id token-id)) - (ctob/add-token lib' set-id (ctob/make-token token)) + (ctob/add-token lib' set-id (ctob/make-token attrs)) :else (ctob/update-token lib' set-id token-id (fn [prev-token] - (ctob/make-token (merge prev-token token))))))))) + (ctob/make-token (merge prev-token attrs))))))))) (defmethod process-change :set-token-set - [data {:keys [id token-set]}] + [data {:keys [id attrs]}] (update data :tokens-lib (fn [lib] (let [lib' (ctob/ensure-tokens-lib lib)] (cond - (not token-set) + (not attrs) (ctob/delete-set lib' id) (not (ctob/get-set lib' id)) - (ctob/add-set lib' (ctob/make-token-set token-set)) + (ctob/add-set lib' (ctob/make-token-set attrs)) :else - (ctob/update-set lib' id (fn [_] (ctob/make-token-set token-set)))))))) + (ctob/update-set lib' id (fn [_] (ctob/make-token-set attrs)))))))) (defmethod process-change :set-token-theme - [data {:keys [id theme]}] + [data {:keys [id attrs]}] (update data :tokens-lib (fn [lib] (let [lib' (ctob/ensure-tokens-lib lib)] (cond - (not theme) + (not attrs) (ctob/delete-theme lib' id) (not (ctob/get-theme lib' id)) - (ctob/add-theme lib' (ctob/make-token-theme theme)) + (ctob/add-theme lib' (ctob/make-token-theme attrs)) :else (ctob/update-theme lib' id (fn [prev-token-theme] - (ctob/make-token-theme (merge prev-token-theme theme))))))))) + (ctob/make-token-theme (merge prev-token-theme attrs))))))))) (defmethod process-change :set-active-token-themes [data {:keys [theme-paths]}] diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index a1be2b244e..e27940ef1b 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -950,11 +950,11 @@ (update :redo-changes conj {:type :set-token :set-id set-id :token-id token-id - :token token}) + :attrs (datafy token)}) (update :undo-changes conj {:type :set-token :set-id set-id :token-id token-id - :token prev-token}) + :attrs (datafy prev-token)}) (apply-changes-local)))) (defn set-token-set @@ -966,10 +966,10 @@ (-> changes (update :redo-changes conj {:type :set-token-set :id id - :token-set (datafy token-set)}) + :attrs (datafy token-set)}) (update :undo-changes conj {:type :set-token-set :id id - :token-set (datafy prev-token-set)}) + :attrs (datafy prev-token-set)}) (apply-changes-local)))) (defn rename-token-set @@ -981,10 +981,10 @@ (-> changes (update :redo-changes conj {:type :set-token-set :id id - :token-set (datafy (ctob/rename prev-token-set new-name))}) + :attrs (datafy (ctob/rename prev-token-set new-name))}) (update :undo-changes conj {:type :set-token-set :id id - :token-set (datafy prev-token-set)}) + :attrs (datafy prev-token-set)}) (apply-changes-local)))) (defn set-token-theme [changes id theme] @@ -995,10 +995,10 @@ (-> changes (update :redo-changes conj {:type :set-token-theme :id id - :theme theme}) + :attrs (datafy theme)}) (update :undo-changes conj {:type :set-token-theme :id id - :theme prev-theme}) + :attrs (datafy prev-theme)}) (apply-changes-local)))) (defn set-active-token-themes diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 7f63ee88cd..11ea10d9dd 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -165,8 +165,7 @@ (delete-token- [_ id] "delete a token from the list") (get-token- [_ id] "get a token by its id") (get-token-by-name- [_ name] "get a token by its name") - (get-tokens-seq- [_] "return an ordered sequence of all tokens in the set") - (get-tokens-map- [_] "return a map of tokens in the set, indexed by token-name")) + (get-tokens- [_] "return a map of tokens in the set, indexed by token-name")) ;; TODO: this structure is temporary. It's needed to be able to migrate TokensLib ;; from 1.2 to 1.3 when TokenSet datatype was changed to a deftype. This should @@ -275,10 +274,7 @@ (assert (string? name) "expected string for `name`") (get tokens name)) - (get-tokens-seq- [_] - (vals tokens)) - - (get-tokens-map- [_] + (get-tokens- [_] tokens)) (defmethod pp/simple-dispatch TokenSet [^TokenSet obj] @@ -909,8 +905,7 @@ Will return a value that matches this schema: `:partial` Mixed active state of nested sets") (get-tokens-in-active-sets [_] "set of set names that are active in the the active themes") (get-all-tokens [_] "all tokens in the lib") - (get-tokens-seq [_ set-id] "return an ordered sequence of all tokens in a set") - (get-tokens-map [_ set-id] "return a map of tokens in the set, indexed by token-name") + (get-tokens [_ set-id] "return a map of tokens in the set, indexed by token-name") (validate [_])) (declare parse-multi-set-dtcg-json) @@ -1296,7 +1291,7 @@ Will return a value that matches this schema: active-set-names (filter theme-set-names all-set-names) tokens (reduce (fn [tokens set-name] (let [set (get-set-by-name this set-name)] - (merge tokens (get-tokens-map- set)))) + (merge tokens (get-tokens- set)))) (d/ordered-map) active-set-names)] tokens)) @@ -1304,19 +1299,14 @@ Will return a value that matches this schema: (get-all-tokens [this] (reduce (fn [tokens' set] - (into tokens' (map (fn [x] [(:name x) x]) (get-tokens-seq- set)))) + (into tokens' (map (fn [x] [(:name x) x]) (vals (get-tokens- set))))) {} (get-sets this))) - (get-tokens-seq [this set-id] + (get-tokens [this set-id] (some-> this (get-set set-id) - (get-tokens-seq-))) - - (get-tokens-map [this set-id] - (some-> this - (get-set set-id) - (get-tokens-map-))) + (get-tokens-))) (validate [_] (and (valid-token-sets? sets) @@ -1769,7 +1759,7 @@ Will return a value that matches this schema: sets (->> (get-sets tokens-lib) (map (fn [token-set] (let [name (get-name token-set) - tokens (get-tokens-map- token-set)] + tokens (get-tokens- token-set)] [(str name ".json") (tokens-tree tokens :update-token-fn token->dtcg-token)]))) (into {}))] (-> sets @@ -1789,7 +1779,7 @@ Will return a value that matches this schema: (filter (partial instance? TokenSet)) (map (fn [set] [(get-name set) - (tokens-tree (get-tokens-map- set) :update-token-fn token->dtcg-token)]))) + (tokens-tree (get-tokens- set) :update-token-fn token->dtcg-token)]))) ordered-set-names (mapv first name-set-tuples) diff --git a/common/test/common_tests/types/tokens_lib_test.cljc b/common/test/common_tests/types/tokens_lib_test.cljc index 265a8ce22e..8c837658ab 100644 --- a/common/test/common_tests/types/tokens_lib_test.cljc +++ b/common/test/common_tests/types/tokens_lib_test.cljc @@ -83,11 +83,11 @@ (t/is (= (ctob/get-name token-set1) "test-token-set-1")) (t/is (= (ctob/get-description token-set1) "")) (t/is (some? (ctob/get-modified-at token-set1))) - (t/is (empty? (ctob/get-tokens-map- token-set1))) + (t/is (empty? (ctob/get-tokens- token-set1))) (t/is (= (ctob/get-name token-set2) "test-token-set-2")) (t/is (= (ctob/get-description token-set2) "test description")) (t/is (= (ctob/get-modified-at token-set2) now)) - (t/is (empty? (ctob/get-tokens-map- token-set2))))) + (t/is (empty? (ctob/get-tokens- token-set2))))) (t/deftest make-invalid-token-set (let [params {:name 777 :description 999}] @@ -197,7 +197,7 @@ :type :boolean :value true)}))) expected (-> tokens-lib - (ctob/get-tokens-map (thi/id :test-token-set)) + (ctob/get-tokens (thi/id :test-token-set)) (ctob/tokens-tree))] (t/is (= (get-in expected ["foo" "bar" "baz" :name]) "foo.bar.baz")) (t/is (= (get-in expected ["foo" "bar" "bam" :name]) "foo.bar.bam")) @@ -328,7 +328,7 @@ (t/is (some? token-set-copy)) (t/is (= (ctob/get-name token-set-copy) "test-token-set-copy")) - (t/is (= (count (ctob/get-tokens-map- token-set-copy)) 1)) + (t/is (= (count (ctob/get-tokens- token-set-copy)) 1)) (t/is (= (:name token) "test-token")))) (t/deftest duplicate-token-set-twice @@ -348,7 +348,7 @@ (t/is (some? token-set-copy)) (t/is (= (ctob/get-name token-set-copy) "test-token-set-copy-2")) - (t/is (= (count (ctob/get-tokens-map- token-set-copy)) 1)) + (t/is (= (count (ctob/get-tokens- token-set-copy)) 1)) (t/is (= (:name token) "test-token")))) (t/deftest duplicate-empty-token-set @@ -357,11 +357,11 @@ :name "test-token-set"))) token-set-copy (ctob/duplicate-set (thi/id :test-token-set) tokens-lib {:suffix "copy"}) - tokens (ctob/get-tokens-map- token-set-copy)] + tokens (ctob/get-tokens- token-set-copy)] (t/is (some? token-set-copy)) (t/is (= (ctob/get-name token-set-copy) "test-token-set-copy")) - (t/is (= (count (ctob/get-tokens-map- token-set-copy)) 0)) + (t/is (= (count (ctob/get-tokens- token-set-copy)) 0)) (t/is (= (count tokens) 0)))) (t/deftest duplicate-not-existing-token-set @@ -390,7 +390,7 @@ (thi/id :token))] (t/is (= (ctob/set-count tokens-lib') 1)) - (t/is (= (count (ctob/get-tokens-map tokens-lib' (thi/id :test-token-set))) 1)) + (t/is (= (count (ctob/get-tokens tokens-lib' (thi/id :test-token-set))) 1)) (t/is (= (:name token') "test-token")) (t/is (ct/is-after? (ctob/get-modified-at token-set') (ctob/get-modified-at token-set))))) @@ -432,8 +432,8 @@ token' (ctob/get-token tokens-lib' (thi/id :test-token-set) (thi/id :test-token-1)) - tokens' (ctob/get-tokens-map tokens-lib' - (thi/id :test-token-set))] + tokens' (ctob/get-tokens tokens-lib' + (thi/id :test-token-set))] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (count tokens') 2)) @@ -473,8 +473,8 @@ token' (ctob/get-token tokens-lib' (thi/id :test-token-set) (thi/id :test-token-1)) - tokens' (ctob/get-tokens-map tokens-lib' - (thi/id :test-token-set))] + tokens' (ctob/get-tokens tokens-lib' + (thi/id :test-token-set))] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (count tokens') 2)) @@ -504,8 +504,8 @@ token' (ctob/get-token tokens-lib' (thi/id :test-token-set) (thi/id :test-token)) - tokens' (ctob/get-tokens-map tokens-lib' - (thi/id :test-token-set))] + tokens' (ctob/get-tokens tokens-lib' + (thi/id :test-token-set))] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (count tokens') 0)) @@ -914,7 +914,7 @@ :type :boolean :value true))) - tokens-list (ctob/get-tokens-seq tokens-lib (thi/id :test-token-set))] + tokens-list (vals (ctob/get-tokens tokens-lib (thi/id :test-token-set)))] (t/is (= (count tokens-list) 5)) (t/is (= (:name (nth tokens-list 0)) "token1")) @@ -1042,8 +1042,8 @@ token' (ctob/get-token tokens-lib' (thi/id :test-token-set) (thi/id :test-token-2)) - tokens' (ctob/get-tokens-map tokens-lib' - (thi/id :test-token-set))] + tokens' (ctob/get-tokens tokens-lib' + (thi/id :test-token-set))] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (d/index-of (keys tokens') "group2.updated-name") 1)) @@ -1075,8 +1075,8 @@ token' (ctob/get-token tokens-lib' (thi/id :test-token-set) (thi/id :test-token-2)) - tokens' (ctob/get-tokens-map tokens-lib' - (thi/id :test-token-set))] + tokens' (ctob/get-tokens tokens-lib' + (thi/id :test-token-set))] (t/is (= (ctob/set-count tokens-lib') 1)) (t/is (= (count tokens') 1)) diff --git a/frontend/src/app/main/data/workspace/tokens/library_edit.cljs b/frontend/src/app/main/data/workspace/tokens/library_edit.cljs index 4bcae19112..b5e63979c7 100644 --- a/frontend/src/app/main/data/workspace/tokens/library_edit.cljs +++ b/frontend/src/app/main/data/workspace/tokens/library_edit.cljs @@ -410,7 +410,7 @@ (when-let [token (ctob/get-token tokens-lib (ctob/get-id token-set) token-id)] - (let [tokens (ctob/get-tokens-seq tokens-lib (ctob/get-id token-set)) + (let [tokens (vals (ctob/get-tokens tokens-lib (ctob/get-id token-set))) unames (map :name tokens) suffix (tr "workspace.tokens.duplicate-suffix") copy-name (cfh/generate-unique-name (:name token) unames :suffix suffix)] diff --git a/frontend/src/app/main/data/workspace/tokens/selected_set.cljs b/frontend/src/app/main/data/workspace/tokens/selected_set.cljs index 9473b5f89d..c3ca926e8c 100644 --- a/frontend/src/app/main/data/workspace/tokens/selected_set.cljs +++ b/frontend/src/app/main/data/workspace/tokens/selected_set.cljs @@ -35,4 +35,4 @@ (when-let [set-id (get-selected-token-set-id state)] (some-> (dsh/lookup-file-data state) (get :tokens-lib) - (ctob/get-tokens-map set-id)))) + (ctob/get-tokens set-id)))) diff --git a/frontend/src/app/main/ui/workspace/colorpicker.cljs b/frontend/src/app/main/ui/workspace/colorpicker.cljs index a8a645bb69..6964d194c8 100644 --- a/frontend/src/app/main/ui/workspace/colorpicker.cljs +++ b/frontend/src/app/main/ui/workspace/colorpicker.cljs @@ -693,7 +693,7 @@ [sets] (map (fn [s] {:set (ctob/get-name s) - :tokens (ctob/get-tokens-seq- s)}) ;; TODO: this function should be moved to common.logic and refactored + :tokens (vals (ctob/get-tokens- s))}) ;; TODO: this function should be moved to common.logic and refactored sets)) (defn- filter-active-sets diff --git a/frontend/src/app/main/ui/workspace/tokens/management.cljs b/frontend/src/app/main/ui/workspace/tokens/management.cljs index f80f71e029..21412342cd 100644 --- a/frontend/src/app/main/ui/workspace/tokens/management.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/management.cljs @@ -82,7 +82,7 @@ ;; select the first one from the list of sets selected-token-set-tokens (when selected-token-set-id - (some-> tokens-lib (ctob/get-tokens-map selected-token-set-id))) + (some-> tokens-lib (ctob/get-tokens selected-token-set-id))) tokens (mf/with-memo [active-tokens selected-token-set-tokens]