mirror of
https://github.com/penpot/penpot.git
synced 2026-02-12 14:42:56 +00:00
🎉 Rename token group - WIP
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
[app.main.ui.ds.foundations.assets.icon :refer [icon*] :as i]
|
[app.main.ui.ds.foundations.assets.icon :refer [icon*] :as i]
|
||||||
[app.main.ui.ds.foundations.typography.text :refer [text*]]
|
[app.main.ui.ds.foundations.typography.text :refer [text*]]
|
||||||
[app.main.ui.workspace.tokens.management.context-menu :refer [token-context-menu]]
|
[app.main.ui.workspace.tokens.management.context-menu :refer [token-context-menu]]
|
||||||
[app.main.ui.workspace.tokens.management.forms.rename-node-modal :refer [rename-node-modal*]]
|
|
||||||
[app.main.ui.workspace.tokens.management.group :refer [token-group*]]
|
[app.main.ui.workspace.tokens.management.group :refer [token-group*]]
|
||||||
[app.main.ui.workspace.tokens.management.node-context-menu :refer [token-node-context-menu*]]
|
[app.main.ui.workspace.tokens.management.node-context-menu :refer [token-node-context-menu*]]
|
||||||
[app.util.array :as array]
|
[app.util.array :as array]
|
||||||
@@ -180,13 +179,32 @@
|
|||||||
(st/emit! (dwtl/toggle-token-path (str (name type) "." path)))
|
(st/emit! (dwtl/toggle-token-path (str (name type) "." path)))
|
||||||
(st/emit! (dwtl/toggle-token-path (name type)))))))
|
(st/emit! (dwtl/toggle-token-path (name type)))))))
|
||||||
|
|
||||||
|
on-rename-node
|
||||||
|
(mf/use-fn
|
||||||
|
(mf/deps selected-token-set-tokens selected-token-set-id)
|
||||||
|
(fn [node type new-name]
|
||||||
|
(prn "Renaming node: " node " with type: " type " to new name: " new-name)
|
||||||
|
;; (let [path (:path node)
|
||||||
|
;; tokens-by-type (ctob/group-by-type selected-token-set-tokens)
|
||||||
|
;; tokens-filtered-by-type (get tokens-by-type type)
|
||||||
|
;; tokens-in-path-ids (filter-tokens-by-path-ids type path)]
|
||||||
|
;; ;; Rename tokens in path
|
||||||
|
;; (st/emit! (dwtl/bulk-rename-tokens selected-token-set-id tokens-in-path-ids new-name))
|
||||||
|
;; ;; Remove from unfolded tree path
|
||||||
|
;; (st/emit! (dwtl/toggle-token-path (str (name type) "." path))))
|
||||||
|
))
|
||||||
|
|
||||||
open-rename-node-modal
|
open-rename-node-modal
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps selected-token-set-tokens)
|
(mf/deps selected-token-set-tokens on-rename-node)
|
||||||
(fn [node type]
|
(fn [node type]
|
||||||
(modal/show! :tokens/rename-node {:node node
|
(let [_ (prn "RENAME")
|
||||||
:type type
|
on-rename-node-handler #(on-rename-node node type %)]
|
||||||
:tokens-in-active-set selected-token-set-tokens})))]
|
|
||||||
|
|
||||||
|
(st/emit! (modal/show :tokens/rename-node {:node node
|
||||||
|
:tokens-in-active-set selected-token-set-tokens
|
||||||
|
:on-rename on-rename-node-handler})))))]
|
||||||
|
|
||||||
(mf/with-effect [tokens-lib selected-token-set-id]
|
(mf/with-effect [tokens-lib selected-token-set-id]
|
||||||
(when (and tokens-lib
|
(when (and tokens-lib
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#(not (cft/token-name-path-exists? % tokens-tree))]]]]))
|
#(not (cft/token-name-path-exists? % tokens-tree))]]]]))
|
||||||
|
|
||||||
(mf/defc rename-node-form*
|
(mf/defc rename-node-form*
|
||||||
[{:keys [node type tokens-tree on-close on-submit]}]
|
[{:keys [node tokens-tree on-close on-submit]}]
|
||||||
(let [schema
|
(let [schema
|
||||||
(mf/with-memo [tokens-tree]
|
(mf/with-memo [tokens-tree]
|
||||||
(make-schema tokens-tree))
|
(make-schema tokens-tree))
|
||||||
@@ -42,12 +42,17 @@
|
|||||||
:initial initial)
|
:initial initial)
|
||||||
|
|
||||||
on-submit (mf/use-fn
|
on-submit (mf/use-fn
|
||||||
(mf/deps form on-submit node type)
|
(mf/deps form on-submit)
|
||||||
(fn []
|
(fn []
|
||||||
(let [name (get-in @form [:clean-data :name])]
|
(let [name (get-in @form [:clean-data :name])]
|
||||||
(when (and (get-in @form [:touched :name]) (not= name (:name node)))
|
(when (and (get-in @form [:touched :name]) (not= name (:name node)))
|
||||||
(on-submit {:new-name name})))))
|
(on-submit {:new-name name})))))
|
||||||
|
|
||||||
|
is-disabled? (or (not (:valid @form))
|
||||||
|
(not (get-in @form [:touched :name]))
|
||||||
|
(= (get-in @form [:clean-data :name]) (:name node)))
|
||||||
|
|
||||||
|
|
||||||
#_(let [{:keys [clean-data valid extra-errors async-errors]} @form]
|
#_(let [{:keys [clean-data valid extra-errors async-errors]} @form]
|
||||||
(when (and valid
|
(when (and valid
|
||||||
(empty? extra-errors)
|
(empty? extra-errors)
|
||||||
@@ -77,15 +82,19 @@
|
|||||||
:name "cancel"
|
:name "cancel"
|
||||||
:on-click on-close} (tr "labels.cancel")]
|
:on-click on-close} (tr "labels.cancel")]
|
||||||
[:> fc/form-submit* {:variant "primary"
|
[:> fc/form-submit* {:variant "primary"
|
||||||
:disabled (not (:valid @form))
|
:disabled is-disabled?
|
||||||
:name "rename"} (tr "labels.rename")]]]]))
|
:name "rename"} (tr "labels.rename")]]]]))
|
||||||
|
|
||||||
(mf/defc rename-node-modal*
|
(mf/defc rename-node-modal*
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
::mf/register-as :tokens/rename-node}
|
::mf/register-as :tokens/rename-node}
|
||||||
[{:keys [node type tokens-in-active-set on-remap on-rename]}]
|
[{:keys [node tokens-in-active-set on-rename]}]
|
||||||
|
|
||||||
(let [tokens-tree-in-selected-set
|
|
||||||
|
|
||||||
|
(let [_ (prn "patata") ;;nil
|
||||||
|
|
||||||
|
tokens-tree-in-selected-set
|
||||||
(mf/with-memo [tokens-in-active-set node]
|
(mf/with-memo [tokens-in-active-set node]
|
||||||
(-> (ctob/tokens-tree tokens-in-active-set)
|
(-> (ctob/tokens-tree tokens-in-active-set)
|
||||||
(d/dissoc-in (:name node))))
|
(d/dissoc-in (:name node))))
|
||||||
@@ -98,15 +107,15 @@
|
|||||||
|
|
||||||
rename
|
rename
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps [node type on-remap on-rename])
|
(mf/deps on-rename)
|
||||||
(fn [new-name]
|
(fn [new-name]
|
||||||
(prn "Renaming " node " to: " new-name " with type: " type)
|
(prn "Emitted remapping confirmation modal")
|
||||||
(modal/hide!)
|
(on-rename {:new-name new-name})
|
||||||
(st/emit! (modal/show :tokens/remapping-confirmation {:old-token-name (:name node)
|
;; (st/emit! (modal/show :tokens/remapping-confirmation {:old-token-name (:name node)
|
||||||
:new-token-name new-name
|
;; :new-token-name new-name
|
||||||
:on-remap on-remap
|
;; :on-remap on-remap
|
||||||
:on-rename on-rename}))
|
;; :on-rename on-rename}))
|
||||||
(prn "Emitted remapping confirmation modal")))
|
))
|
||||||
|
|
||||||
on-key-down
|
on-key-down
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@@ -123,7 +132,6 @@
|
|||||||
:variant "ghost"
|
:variant "ghost"
|
||||||
:icon i/close}]
|
:icon i/close}]
|
||||||
[:> rename-node-form* {:node node
|
[:> rename-node-form* {:node node
|
||||||
:type type
|
|
||||||
:tokens-tree tokens-tree-in-selected-set
|
:tokens-tree tokens-tree-in-selected-set
|
||||||
:on-close close-modal
|
:on-close close-modal
|
||||||
:on-submit rename}]]]))
|
:on-submit rename}]]]))
|
||||||
|
|||||||
Reference in New Issue
Block a user