✨ Disable update main when it would nest a component in itself

Update main from a copy that holds its own component, or a component whose
main holds it, changes nothing, because the result would nest the component
inside itself. The menus still offered it.

Disable the entry for such a copy, with the same check the update applies,
in the canvas context menu and in the design tab's component menu, which
now renders disabled entries as the context menu does.

The full rebuilt frontend passes 1799 tests / 16286 assertions; backend
passes 1838 / 9293 and exporter 16 / 40. Frontend formatting passes and
lint reports no errors for the changed files.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-10-31 13:18:11 +01:00
parent e94b3c19bf
commit 4ef0174917
4 changed files with 16 additions and 3 deletions

View File

@ -719,6 +719,7 @@
:title (:title entry)
:shortcut (when sc-key (get-tt sc-key))
:shortcut-key sc-key
:disabled (:disabled entry)
:on-click (:action entry)}]))])
(when variant-container?

View File

@ -10,6 +10,7 @@
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.logic.libraries :as cll]
[app.common.path-names :as cpn]
[app.common.thumbnails :as thc]
[app.common.types.component :as ctk]
@ -454,6 +455,10 @@
(not (ctn/has-any-copy-parent? objects shape))
(cfh/component-touched? objects (:id shape))))
;; Updating the main would nest its component inside itself.
update-main-loop? (and can-update-main?
(cll/update-main-nesting-loop? libraries {:objects objects} shape-id))
can-detach? (and (seq copies)
(every? #(not (ctn/has-any-copy-parent? objects %)) copies))
@ -582,7 +587,8 @@
:action do-show-component})
(when can-update-main?
{:title (tr "workspace.shape.menu.update-main")
:action do-update-component})
:action do-update-component
:disabled update-main-loop?})
(when (and (or (not multi) same-variant?) main-instance?)
{:title (tr "workspace.shape.menu.add-variant")
:shortcut :create-component-variant

View File

@ -918,11 +918,12 @@
:on-close on-menu-close}
[:ul {:class (stl/css-case :pill-actions-dropdown true
:extended subtext)}
(for [{:keys [title action]} menu-entries]
(for [{:keys [title action disabled]} menu-entries]
(when (some? title)
[:li {:key title
:class (stl/css :pill-actions-dropdown-item)
:on-click (partial do-action action)}
:disabled disabled
:on-click (when-not disabled (partial do-action action))}
[:span {:class (stl/css :pill-actions-dropdown-item-label)} title]]))]]])]))
(mf/defc component-menu*

View File

@ -646,6 +646,11 @@
}
}
.pill-actions-dropdown-item[disabled] {
pointer-events: none;
opacity: 0.6;
}
.pill-actions-dropdown-item-label {
display: block;
max-inline-size: 99%;