diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index 5574d8f9c8..1df9c698ce 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -215,6 +215,10 @@ (defn split-token-set-path [path] (split-path path set-separator)) +(defn get-token-set-final-name [path] + (-> (split-token-set-path path) + (last))) + (defn set-name->prefixed-full-path [name-str] (-> (split-token-set-path name-str) (set-full-path->set-prefixed-full-path))) @@ -223,6 +227,11 @@ (let [path (get-path token-set set-separator)] (set-full-path->set-prefixed-full-path path))) +(defn get-prefixed-token-set-final-prefix [prefixed-path-str] + (some-> (get-token-set-final-name prefixed-path-str) + (split-set-str-path-prefix) + (first))) + (defn set-name-string->prefixed-set-path-string [name-str] (-> (set-name->prefixed-full-path name-str) (join-set-path))) @@ -235,6 +244,16 @@ path-part))) (join-set-path))) +(defn prefixed-set-path-final-group? + "Predicate if the given prefixed path string ends with a group." + [prefixed-path-str] + (= (get-prefixed-token-set-final-prefix prefixed-path-str) set-group-prefix)) + +(defn prefixed-set-path-final-set? + "Predicate if the given prefixed path string ends with a set." + [prefixed-path-str] + (= (get-prefixed-token-set-final-prefix prefixed-path-str) set-prefix)) + (defn tokens-tree "Convert tokens into a nested tree with their `:name` as the path. Optionally use `update-token-fn` option to transform the token." diff --git a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs index 426232a97c..cf3c1c4128 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.tokens.sets-context-menu (:require-macros [app.main.style :as stl]) (:require + [app.common.types.tokens-lib :as ctob] [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] @@ -40,6 +41,8 @@ edit-name (mf/use-fn #(on-edit prefixed-set-path)) delete-set (mf/use-fn #(st/emit! (wdt/delete-token-set-path prefixed-set-path)))] [:ul {:class (stl/css :context-list)} + (when (ctob/prefixed-set-path-final-group? prefixed-set-path) + [:& menu-entry {:title "Add set to this group" :on-click js/console.log}]) [:& menu-entry {:title (tr "labels.rename") :on-click edit-name}] [:& menu-entry {:title (tr "labels.delete") :on-click delete-set}]]))