mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
✨ Hide move options when no targets
This commit is contained in:
parent
2adc45fc19
commit
161b8cdabb
3 changed files with 47 additions and 36 deletions
|
@ -35,8 +35,7 @@
|
|||
fixed? (gobj/get props "fixed?" false)
|
||||
|
||||
local (mf/use-state {:offset 0
|
||||
:levels [{:parent-option nil
|
||||
:options options}]})
|
||||
:levels nil})
|
||||
|
||||
on-local-close
|
||||
(mf/use-callback
|
||||
|
@ -77,7 +76,12 @@
|
|||
|
||||
props (obj/merge props #js {:on-close on-local-close})]
|
||||
|
||||
(when open?
|
||||
(mf/use-effect
|
||||
(mf/deps options)
|
||||
#(swap! local assoc :levels [{:parent-option nil
|
||||
:options options}]))
|
||||
|
||||
(when (and open? (some? (:levels @local)))
|
||||
[:> dropdown' props
|
||||
[:div.context-menu {:class (classnames :is-open open?
|
||||
:fixed fixed?
|
||||
|
@ -96,18 +100,18 @@
|
|||
parent-option]]
|
||||
[:li.separator]])
|
||||
(for [[option-name option-handler sub-options] (:options level)]
|
||||
(if (= option-name :separator)
|
||||
[:li.separator]
|
||||
[:li.context-menu-item
|
||||
{:class (classnames :is-selected (and selected
|
||||
(= option-name selected)))
|
||||
:key option-name}
|
||||
(if-not sub-options
|
||||
[:a.context-menu-action {:on-click option-handler}
|
||||
option-name]
|
||||
[:a.context-menu-action.submenu
|
||||
{:data-no-close true
|
||||
:on-click (enter-submenu option-name sub-options)}
|
||||
option-name
|
||||
[:span i/arrow-slide]])
|
||||
]))])]])))
|
||||
(when option-name
|
||||
(if (= option-name :separator)
|
||||
[:li.separator]
|
||||
[:li.context-menu-item
|
||||
{:class (classnames :is-selected (and selected
|
||||
(= option-name selected)))
|
||||
:key option-name}
|
||||
(if-not sub-options
|
||||
[:a.context-menu-action {:on-click option-handler}
|
||||
option-name]
|
||||
[:a.context-menu-action.submenu
|
||||
{:data-no-close true
|
||||
:on-click (enter-submenu option-name sub-options)}
|
||||
option-name
|
||||
[:span i/arrow-slide]])])))])]])))
|
||||
|
|
|
@ -31,11 +31,13 @@
|
|||
(let [top (or top 0)
|
||||
left (or left 0)
|
||||
|
||||
current-team-id (mf/use-ctx ctx/current-team-id)
|
||||
teams (mf/use-state nil)
|
||||
current-team (get @teams current-team-id)
|
||||
other-teams (remove #(= (:id %) current-team-id)
|
||||
current-team-id (mf/use-ctx ctx/current-team-id)
|
||||
teams (mf/use-state nil)
|
||||
current-team (get @teams current-team-id)
|
||||
other-teams (remove #(= (:id %) current-team-id)
|
||||
(vals @teams))
|
||||
current-projects (remove #(= (:id %) (:project-id file))
|
||||
(:projects current-team))
|
||||
|
||||
on-new-tab
|
||||
(mf/use-callback
|
||||
|
@ -154,16 +156,18 @@
|
|||
:options [[(tr "dashboard.open-in-new-tab") on-new-tab]
|
||||
[(tr "labels.rename") on-edit]
|
||||
[(tr "dashboard.duplicate") on-duplicate]
|
||||
[(tr "dashboard.move-to") nil
|
||||
(conj (vec (for [project (:projects current-team)]
|
||||
[(:name project) (on-move (:id current-team)
|
||||
(:id project))]))
|
||||
[(tr "dashboard.move-to-other-team") nil
|
||||
(for [team other-teams]
|
||||
[(:name team) nil
|
||||
(for [sub-project (:projects team)]
|
||||
[(:name sub-project) (on-move (:id team)
|
||||
(:id sub-project))])])])]
|
||||
(when (or (seq current-projects) (seq other-teams))
|
||||
[(tr "dashboard.move-to") nil
|
||||
(conj (vec (for [project current-projects]
|
||||
[(:name project) (on-move (:id current-team)
|
||||
(:id project))]))
|
||||
(when (seq other-teams)
|
||||
[(tr "dashboard.move-to-other-team") nil
|
||||
(for [team other-teams]
|
||||
[(:name team) nil
|
||||
(for [sub-project (:projects team)]
|
||||
[(:name sub-project) (on-move (:id team)
|
||||
(:id sub-project))])])]))])
|
||||
(if (:is-shared file)
|
||||
[(tr "dashboard.remove-shared") on-del-shared]
|
||||
[(tr "dashboard.add-shared") on-add-shared])
|
||||
|
|
|
@ -87,10 +87,12 @@
|
|||
(fn []
|
||||
(if show?
|
||||
(->> (rp/query! :teams)
|
||||
(rx/map (fn [teams]
|
||||
(remove #(= (:id %) current-team-id) teams)))
|
||||
(rx/subs #(reset! teams %)))
|
||||
(reset! teams []))))
|
||||
|
||||
(when (seq @teams)
|
||||
(when @teams
|
||||
[:& context-menu {:on-close on-menu-close
|
||||
:show show?
|
||||
:fixed? (or (not= top 0) (not= left 0))
|
||||
|
@ -99,9 +101,10 @@
|
|||
:options [[(tr "labels.rename") on-edit]
|
||||
[(tr "dashboard.duplicate") on-duplicate]
|
||||
[(tr "dashboard.pin-unpin") toggle-pin]
|
||||
[(tr "dashboard.move-to") nil
|
||||
(for [team @teams]
|
||||
[(:name team) (on-move (:id team))])]
|
||||
(when (seq @teams)
|
||||
[(tr "dashboard.move-to") nil
|
||||
(for [team @teams]
|
||||
[(:name team) (on-move (:id team))])])
|
||||
[:separator]
|
||||
[(tr "labels.delete") on-delete]]}])))
|
||||
|
||||
|
|
Loading…
Reference in a new issue