diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 54c13a2e6..67012b8ce 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -224,7 +224,6 @@ pos (d/index-of shapes id)] (if (= 0 pos) nil (nth shapes (dec pos))))) - (defn get-immediate-children "Retrieve resolved shape objects that are immediate children of the specified shape-id" @@ -303,6 +302,13 @@ (ctkl/get-component file id)) (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? "Check if a nesting loop would be created if the given shape is moved below the given parent" [objects shape-id parent-id] diff --git a/common/src/app/common/types/component.cljc b/common/src/app/common/types/component.cljc index ec54b5f83..1101e2136 100644 --- a/common/src/app/common/types/component.cljc +++ b/common/src/app/common/types/component.cljc @@ -63,7 +63,7 @@ (if (some? (:main-instance-id component)) (get-in component [:objects (:main-instance-id component)]) (get-in component [:objects (:id component)]))) - + (defn uses-library-components? "Check if the shape uses any component in the given library." [shape library-id] diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 198b87b1d..370bb7578 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -435,17 +435,20 @@ (mf/defc context-menu-component [{:keys [shapes]}] (let [single? (= (count shapes) 1) + components-v2 (features/use-feature :components-v2) has-component? (some true? (map #(contains? % :component-id) shapes)) is-component? (and single? (-> shapes first :component-id some?)) 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) {:keys [id component-id component-file main-instance?]} first-shape lacks-annotation? (nil? (:annotation first-shape)) component-shapes (filter #(contains? % :component-id) shapes) - components-v2 (features/use-feature :components-v2) current-file-id (mf/use-ctx ctx/current-file-id) local-component? (= component-file current-file-id) @@ -534,8 +537,9 @@ [:& menu-entry {:title (tr "workspace.shape.menu.detach-instance") :shortcut (sc/get-tooltip :detach-component) :on-click do-detach-component}] - [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") - :on-click do-reset-component}] + (when can-update-main? + [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") + :on-click do-reset-component}]) (when components-v2 [:& menu-entry {:title (tr "workspace.shape.menu.restore-main") :on-click do-restore-component}])] @@ -543,10 +547,12 @@ [:& menu-entry {:title (tr "workspace.shape.menu.detach-instance") :shortcut (sc/get-tooltip :detach-component) :on-click do-detach-component}] - [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") - :on-click do-reset-component}] - [:& menu-entry {:title (tr "workspace.shape.menu.update-main") - :on-click do-update-component}] + (when can-update-main? + [:* + [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") + :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") :on-click do-show-component}]]) (if is-dangling? @@ -554,8 +560,9 @@ [:& menu-entry {:title (tr "workspace.shape.menu.detach-instance") :shortcut (sc/get-tooltip :detach-component) :on-click do-detach-component}] - [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") - :on-click do-reset-component}] + (when can-update-main? + [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") + :on-click do-reset-component}]) (when components-v2 [:& menu-entry {:title (tr "workspace.shape.menu.restore-main") :on-click do-restore-component}])] @@ -563,10 +570,12 @@ [:& menu-entry {:title (tr "workspace.shape.menu.detach-instance") :shortcut (sc/get-tooltip :detach-component) :on-click do-detach-component}] - [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") - :on-click do-reset-component}] - [:& menu-entry {:title (tr "workspace.shape.menu.update-main") - :on-click do-update-remote-component}] + (when can-update-main? + [:* + [:& menu-entry {:title (tr "workspace.shape.menu.reset-overrides") + :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") :on-click do-navigate-component-file}]])))]) [:& menu-separator]])) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index f4a4968ff..e31d76543 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -6,6 +6,7 @@ (ns app.main.ui.workspace.sidebar.options.menus.component (:require + [app.common.pages.helpers :as cph] [app.common.types.components-list :as ctkl] [app.common.types.file :as ctf] [app.main.data.modal :as modal] @@ -142,6 +143,10 @@ (let [current-file-id (mf/use-ctx ctx/current-file-id) 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) local (mf/use-state {:menu-open false}) @@ -230,23 +235,29 @@ (if local-component? (if is-dangling? [[(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 [(tr "workspace.shape.menu.restore-main") do-restore-component])] [[(tr "workspace.shape.menu.detach-instance") do-detach-component] - [(tr "workspace.shape.menu.reset-overrides") do-reset-component] - [(tr "workspace.shape.menu.update-main") do-update-component] + (when can-update-main? + [:* + [(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]]) (if is-dangling? [[(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 [(tr "workspace.shape.menu.restore-main") do-restore-component])] [[(tr "workspace.shape.menu.detach-instance") do-detach-component] - [(tr "workspace.shape.menu.reset-overrides") do-reset-component] - [(tr "workspace.shape.menu.update-main") do-update-remote-component] + (when can-update-main? + [:* + [(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]])))}]]] (when components-v2