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