mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 00:01:51 -05:00
🐛 Fix 'upate main component' and 'reset overrides' shows in context menu of untouched copies
This commit is contained in:
parent
531d640d38
commit
a89d47b5c5
4 changed files with 47 additions and 21 deletions
|
@ -224,7 +224,6 @@
|
||||||
pos (d/index-of shapes id)]
|
pos (d/index-of shapes id)]
|
||||||
(if (= 0 pos) nil (nth shapes (dec pos)))))
|
(if (= 0 pos) nil (nth shapes (dec pos)))))
|
||||||
|
|
||||||
|
|
||||||
(defn get-immediate-children
|
(defn get-immediate-children
|
||||||
"Retrieve resolved shape objects that are immediate children
|
"Retrieve resolved shape objects that are immediate children
|
||||||
of the specified shape-id"
|
of the specified shape-id"
|
||||||
|
@ -303,6 +302,13 @@
|
||||||
(ctkl/get-component file id))
|
(ctkl/get-component file id))
|
||||||
(assoc :type type)))
|
(assoc :type type)))
|
||||||
|
|
||||||
|
(defn component-touched?
|
||||||
|
"Check if any shape in the component is touched"
|
||||||
|
[objects root-id]
|
||||||
|
(->> (get-children-with-self objects root-id)
|
||||||
|
(filter (comp seq :touched))
|
||||||
|
seq))
|
||||||
|
|
||||||
(defn components-nesting-loop?
|
(defn components-nesting-loop?
|
||||||
"Check if a nesting loop would be created if the given shape is moved below the given parent"
|
"Check if a nesting loop would be created if the given shape is moved below the given parent"
|
||||||
[objects shape-id parent-id]
|
[objects shape-id parent-id]
|
||||||
|
|
|
@ -435,17 +435,20 @@
|
||||||
(mf/defc context-menu-component
|
(mf/defc context-menu-component
|
||||||
[{:keys [shapes]}]
|
[{:keys [shapes]}]
|
||||||
(let [single? (= (count shapes) 1)
|
(let [single? (= (count shapes) 1)
|
||||||
|
components-v2 (features/use-feature :components-v2)
|
||||||
|
|
||||||
has-component? (some true? (map #(contains? % :component-id) shapes))
|
has-component? (some true? (map #(contains? % :component-id) shapes))
|
||||||
is-component? (and single? (-> shapes first :component-id some?))
|
is-component? (and single? (-> shapes first :component-id some?))
|
||||||
is-non-root? (and single? (ctk/in-component-copy-not-root? (first shapes)))
|
is-non-root? (and single? (ctk/in-component-copy-not-root? (first shapes)))
|
||||||
|
objects (deref refs/workspace-page-objects)
|
||||||
|
touched? (and single? (cph/component-touched? objects (:id (first shapes))))
|
||||||
|
can-update-main? (or (not components-v2) touched?)
|
||||||
|
|
||||||
first-shape (first shapes)
|
first-shape (first shapes)
|
||||||
{:keys [id component-id component-file main-instance?]} first-shape
|
{:keys [id component-id component-file main-instance?]} first-shape
|
||||||
lacks-annotation? (nil? (:annotation first-shape))
|
lacks-annotation? (nil? (:annotation first-shape))
|
||||||
component-shapes (filter #(contains? % :component-id) shapes)
|
component-shapes (filter #(contains? % :component-id) shapes)
|
||||||
|
|
||||||
components-v2 (features/use-feature :components-v2)
|
|
||||||
|
|
||||||
current-file-id (mf/use-ctx ctx/current-file-id)
|
current-file-id (mf/use-ctx ctx/current-file-id)
|
||||||
local-component? (= component-file current-file-id)
|
local-component? (= component-file current-file-id)
|
||||||
|
@ -534,8 +537,9 @@
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
||||||
:shortcut (sc/get-tooltip :detach-component)
|
:shortcut (sc/get-tooltip :detach-component)
|
||||||
:on-click do-detach-component}]
|
:on-click do-detach-component}]
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
(when can-update-main?
|
||||||
:on-click do-reset-component}]
|
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
||||||
|
:on-click do-reset-component}])
|
||||||
(when components-v2
|
(when components-v2
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.restore-main")
|
[:& menu-entry {:title (tr "workspace.shape.menu.restore-main")
|
||||||
:on-click do-restore-component}])]
|
:on-click do-restore-component}])]
|
||||||
|
@ -543,10 +547,12 @@
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
||||||
:shortcut (sc/get-tooltip :detach-component)
|
:shortcut (sc/get-tooltip :detach-component)
|
||||||
:on-click do-detach-component}]
|
:on-click do-detach-component}]
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
(when can-update-main?
|
||||||
:on-click do-reset-component}]
|
[:*
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.update-main")
|
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
||||||
:on-click do-update-component}]
|
:on-click do-reset-component}]
|
||||||
|
[:& menu-entry {:title (tr "workspace.shape.menu.update-main")
|
||||||
|
:on-click do-update-component}]])
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.show-main")
|
[:& menu-entry {:title (tr "workspace.shape.menu.show-main")
|
||||||
:on-click do-show-component}]])
|
:on-click do-show-component}]])
|
||||||
(if is-dangling?
|
(if is-dangling?
|
||||||
|
@ -554,8 +560,9 @@
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
||||||
:shortcut (sc/get-tooltip :detach-component)
|
:shortcut (sc/get-tooltip :detach-component)
|
||||||
:on-click do-detach-component}]
|
:on-click do-detach-component}]
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
(when can-update-main?
|
||||||
:on-click do-reset-component}]
|
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
||||||
|
:on-click do-reset-component}])
|
||||||
(when components-v2
|
(when components-v2
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.restore-main")
|
[:& menu-entry {:title (tr "workspace.shape.menu.restore-main")
|
||||||
:on-click do-restore-component}])]
|
:on-click do-restore-component}])]
|
||||||
|
@ -563,10 +570,12 @@
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
[:& menu-entry {:title (tr "workspace.shape.menu.detach-instance")
|
||||||
:shortcut (sc/get-tooltip :detach-component)
|
:shortcut (sc/get-tooltip :detach-component)
|
||||||
:on-click do-detach-component}]
|
:on-click do-detach-component}]
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
(when can-update-main?
|
||||||
:on-click do-reset-component}]
|
[:*
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.update-main")
|
[:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides")
|
||||||
:on-click do-update-remote-component}]
|
:on-click do-reset-component}]
|
||||||
|
[:& menu-entry {:title (tr "workspace.shape.menu.update-main")
|
||||||
|
:on-click do-update-remote-component}]])
|
||||||
[:& menu-entry {:title (tr "workspace.shape.menu.go-main")
|
[:& menu-entry {:title (tr "workspace.shape.menu.go-main")
|
||||||
:on-click do-navigate-component-file}]])))])
|
:on-click do-navigate-component-file}]])))])
|
||||||
[:& menu-separator]]))
|
[:& menu-separator]]))
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns app.main.ui.workspace.sidebar.options.menus.component
|
(ns app.main.ui.workspace.sidebar.options.menus.component
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.types.components-list :as ctkl]
|
[app.common.types.components-list :as ctkl]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
[app.main.data.modal :as modal]
|
[app.main.data.modal :as modal]
|
||||||
|
@ -142,6 +143,10 @@
|
||||||
(let [current-file-id (mf/use-ctx ctx/current-file-id)
|
(let [current-file-id (mf/use-ctx ctx/current-file-id)
|
||||||
components-v2 (mf/use-ctx ctx/components-v2)
|
components-v2 (mf/use-ctx ctx/components-v2)
|
||||||
|
|
||||||
|
objects (deref refs/workspace-page-objects)
|
||||||
|
touched? (cph/component-touched? objects (:id shape))
|
||||||
|
can-update-main? (or (not components-v2) touched?)
|
||||||
|
|
||||||
id (first ids)
|
id (first ids)
|
||||||
local (mf/use-state {:menu-open false})
|
local (mf/use-state {:menu-open false})
|
||||||
|
|
||||||
|
@ -230,23 +235,29 @@
|
||||||
(if local-component?
|
(if local-component?
|
||||||
(if is-dangling?
|
(if is-dangling?
|
||||||
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
||||||
[(tr "workspace.shape.menu.reset-overrides") do-reset-component]
|
(when can-update-main?
|
||||||
|
[(tr "workspace.shape.menu.reset-overrides") do-reset-component])
|
||||||
(when components-v2
|
(when components-v2
|
||||||
[(tr "workspace.shape.menu.restore-main") do-restore-component])]
|
[(tr "workspace.shape.menu.restore-main") do-restore-component])]
|
||||||
|
|
||||||
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
||||||
[(tr "workspace.shape.menu.reset-overrides") do-reset-component]
|
(when can-update-main?
|
||||||
[(tr "workspace.shape.menu.update-main") do-update-component]
|
[:*
|
||||||
|
[(tr "workspace.shape.menu.reset-overrides") do-reset-component]
|
||||||
|
[(tr "workspace.shape.menu.update-main") do-update-component]])
|
||||||
[(tr "workspace.shape.menu.show-main") do-show-component]])
|
[(tr "workspace.shape.menu.show-main") do-show-component]])
|
||||||
|
|
||||||
(if is-dangling?
|
(if is-dangling?
|
||||||
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
||||||
[(tr "workspace.shape.menu.reset-overrides") do-reset-component]
|
(when can-update-main?
|
||||||
|
[(tr "workspace.shape.menu.reset-overrides") do-reset-component])
|
||||||
(when components-v2
|
(when components-v2
|
||||||
[(tr "workspace.shape.menu.restore-main") do-restore-component])]
|
[(tr "workspace.shape.menu.restore-main") do-restore-component])]
|
||||||
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
[[(tr "workspace.shape.menu.detach-instance") do-detach-component]
|
||||||
[(tr "workspace.shape.menu.reset-overrides") do-reset-component]
|
(when can-update-main?
|
||||||
[(tr "workspace.shape.menu.update-main") do-update-remote-component]
|
[:*
|
||||||
|
[(tr "workspace.shape.menu.reset-overrides") do-reset-component]
|
||||||
|
[(tr "workspace.shape.menu.update-main") do-update-remote-component]])
|
||||||
[(tr "workspace.shape.menu.go-main") do-navigate-component-file]])))}]]]
|
[(tr "workspace.shape.menu.go-main") do-navigate-component-file]])))}]]]
|
||||||
|
|
||||||
(when components-v2
|
(when components-v2
|
||||||
|
|
Loading…
Add table
Reference in a new issue