mirror of
https://github.com/penpot/penpot.git
synced 2025-01-20 13:42:59 -05:00
Fix token set deletion
This commit is contained in:
parent
44105c2be2
commit
5cbcdb77c9
5 changed files with 19 additions and 20 deletions
|
@ -215,20 +215,20 @@
|
|||
(defn split-token-set-path [path]
|
||||
(split-path path set-separator))
|
||||
|
||||
(defn set-full-name->prefixed-full-path [set-full-name]
|
||||
(-> (split-token-set-path set-full-name)
|
||||
(defn set-full-name->prefixed-full-path [set-full-name-string]
|
||||
(-> (split-token-set-path set-full-name-string)
|
||||
(set-full-path->set-prefixed-full-path)))
|
||||
|
||||
(defn get-token-set-prefixed-path [token-set]
|
||||
(let [path (get-path token-set set-separator)]
|
||||
(set-full-path->set-prefixed-full-path path)))
|
||||
|
||||
(defn set-name->prefixed-set-name [set-name]
|
||||
(-> (set-full-name->prefixed-full-path set-name)
|
||||
(defn set-name-string->prefixed-set-path-string [set-name-string]
|
||||
(-> (set-full-name->prefixed-full-path set-name-string)
|
||||
(join-set-path)))
|
||||
|
||||
(defn prefixed-set-full-path->set-name-name [set-path]
|
||||
(->> (split-token-set-path set-path)
|
||||
(defn prefixed-set-path-string->set-name-string [set-path-string]
|
||||
(->> (split-token-set-path set-path-string)
|
||||
(map (fn [path-part]
|
||||
(or (-> (split-set-str-path-prefix path-part)
|
||||
(second))
|
||||
|
@ -318,7 +318,7 @@
|
|||
(vals tokens))
|
||||
|
||||
(get-set-prefixed-path-string [_]
|
||||
(set-name->prefixed-set-name name))
|
||||
(set-name-string->prefixed-set-path-string name))
|
||||
|
||||
(get-tokens-tree [_]
|
||||
(tokens-tree tokens))
|
||||
|
@ -668,18 +668,19 @@ When `before-set-name` is nil, move set to bottom")
|
|||
active-themes)))
|
||||
this)))
|
||||
|
||||
(delete-set-path [_ set-path]
|
||||
(let [path (split-token-set-path set-path)
|
||||
set-node (get-in sets path)
|
||||
set-group? (not (instance? TokenSet set-node))]
|
||||
(TokensLib. (d/dissoc-in sets path)
|
||||
(delete-set-path [_ prefixed-set-name]
|
||||
(let [prefixed-set-path (split-token-set-path prefixed-set-name)
|
||||
set-node (get-in sets prefixed-set-path)
|
||||
set-group? (not (instance? TokenSet set-node))
|
||||
set-name-string (prefixed-set-path-string->set-name-string prefixed-set-name)]
|
||||
(TokensLib. (d/dissoc-in sets prefixed-set-path)
|
||||
;; TODO: When deleting a set-group, also deactivate the child sets
|
||||
(if set-group?
|
||||
themes
|
||||
(walk/postwalk
|
||||
(fn [form]
|
||||
(if (instance? TokenTheme form)
|
||||
(disable-set form set-path)
|
||||
(disable-set form set-name-string)
|
||||
form))
|
||||
themes))
|
||||
active-themes)))
|
||||
|
|
|
@ -100,7 +100,6 @@
|
|||
(->> (ctob/move-set-before tokens-lib set-name before-set-name)
|
||||
(ctob/get-ordered-set-names)
|
||||
(into [])))]
|
||||
;; TODO Nested moving doesn't work as expected
|
||||
(t/testing "regular moving"
|
||||
(t/is (= ["A" "Move" "B"] (move "Move" "B")))
|
||||
(t/is (= ["B" "A" "Move"] (move "A" "Move"))))
|
||||
|
@ -241,11 +240,10 @@
|
|||
(ctob/delete-set-path "S-not-existing-set"))
|
||||
|
||||
token-set' (ctob/get-set tokens-lib' "updated-name")
|
||||
;;token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")
|
||||
]
|
||||
token-theme' (ctob/get-theme tokens-lib' "" "test-token-theme")]
|
||||
|
||||
(t/is (= (ctob/set-count tokens-lib') 0))
|
||||
;; (t/is (= (:sets token-theme') #{})) TODO: fix this
|
||||
(t/is (= (:sets token-theme') #{}))
|
||||
(t/is (nil? token-set'))))
|
||||
|
||||
(t/deftest active-themes-set-names
|
||||
|
|
|
@ -100,7 +100,7 @@
|
|||
(ptk/reify ::set-selected-token-set-path-from-name
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(->> (ctob/set-name->prefixed-set-name token-set-name)
|
||||
(->> (ctob/set-name-string->prefixed-set-path-string token-set-name)
|
||||
(wtts/assoc-selected-token-set-path state)))))
|
||||
|
||||
(defn create-token-theme [token-theme]
|
||||
|
|
|
@ -207,7 +207,7 @@
|
|||
(defn default-actions [{:keys [token selected-token-set-path]}]
|
||||
(let [{:keys [modal]} (wtty/get-token-properties token)]
|
||||
[{:title "Delete Token"
|
||||
:action #(st/emit! (dt/delete-token (ctob/prefixed-set-full-path->set-name-name selected-token-set-path) (:name token)))}
|
||||
:action #(st/emit! (dt/delete-token (ctob/prefixed-set-path-string->set-name-string selected-token-set-path) (:name token)))}
|
||||
{:title "Duplicate Token"
|
||||
:action #(st/emit! (dt/duplicate-token (:name token)))}
|
||||
{:title "Edit Token"
|
||||
|
|
|
@ -352,7 +352,7 @@ Token names should only contain letters and digits separated by . characters.")}
|
|||
(fn [e]
|
||||
(dom/prevent-default e)
|
||||
(modal/hide!)
|
||||
(st/emit! (dt/delete-token (ctob/prefixed-set-full-path->set-name-name selected-token-set-path) (:name token)))))
|
||||
(st/emit! (dt/delete-token (ctob/prefixed-set-path-string->set-name-string selected-token-set-path) (:name token)))))
|
||||
|
||||
on-cancel
|
||||
(mf/use-fn
|
||||
|
|
Loading…
Add table
Reference in a new issue