0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 06:02:32 -05:00

Merge pull request #318 from tokens-studio/fix-delete-set

🐛 When deleting set remove it from theme
This commit is contained in:
Florian Schrödl 2024-10-29 16:27:25 +01:00 committed by GitHub
commit 62b859b84e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -368,7 +368,8 @@ When `before-set-name` is nil, move set to bottom")
(defprotocol ITokenTheme
(set-sets [_ set-names] "set the active token sets")
(toggle-set [_ set-name] "togle a set used / not used in the theme")
(disable-set [_ set-name] "disable set in theme")
(toggle-set [_ set-name] "toggle a set enabled / disabled in the theme")
(theme-path [_] "get `token-theme-path` from theme")
(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"))
@ -383,6 +384,9 @@ When `before-set-name` is nil, move set to bottom")
(dt/now)
set-names))
(disable-set [this set-name]
(set-sets this (disj sets set-name)))
(toggle-set [this set-name]
(set-sets this (if (sets set-name)
(disj sets set-name)
@ -580,7 +584,12 @@ When `before-set-name` is nil, move set to bottom")
(let [path (split-token-set-path set-name)]
(TokensLib. (d/dissoc-in sets path)
set-groups ;; TODO remove set-group if needed
themes
(walk/postwalk
(fn [form]
(if (instance? TokenTheme form)
(disable-set form set-name)
form))
themes)
active-themes)))
;; TODO Handle groups and nesting

View file

@ -235,15 +235,18 @@
(t/deftest delete-token-set
(let [tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "test-token-set")))
(ctob/add-set (ctob/make-token-set :name "test-token-set"))
(ctob/add-theme (ctob/make-token-theme :name "test-token-theme" :sets #{"test-token-set"})))
tokens-lib' (-> tokens-lib
(ctob/delete-set "test-token-set")
(ctob/delete-set "not-existing-set"))
token-set' (ctob/get-set tokens-lib' "updated-name")]
token-set' (ctob/get-set tokens-lib' "updated-name")
token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")]
(t/is (= (ctob/set-count tokens-lib') 0))
(t/is (= (:sets token-theme') #{}))
(t/is (nil? token-set'))))
(t/deftest active-themes-set-names