Skip to content

Commit

Permalink
#5696-Adding Attachment point to microstructure already connected to …
Browse files Browse the repository at this point in the history
…monomer - causes problems
  • Loading branch information
KristinaKasyanovskaya authored Jan 22, 2025
1 parent b393f7d commit d81d27e
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const AtomMenuItems: FC<MenuItemsProps<AtomContextMenuProps>> = (props) => {
attachmentPoint.attachmentPointNumber,
),
);

const highlightAtomWithColor = (color: string) => {
const atomIds = props.propsFromTrigger?.atomIds || [];
editor.highlights.create({
Expand All @@ -182,6 +181,22 @@ const AtomMenuItems: FC<MenuItemsProps<AtomContextMenuProps>> = (props) => {
});
};

const isAddAttachmentPointDisabled =
!onlyOneAtomSelected ||
(() => {
if (!isNumber(selectedAtomId)) return true;

const connectedComponents = struct.findConnectedComponent(selectedAtomId);
for (const connectedAtomId of connectedComponents) {
const connectedGroup = struct.getGroupFromAtomId(connectedAtomId);
if (connectedGroup?.isMonomer) {
return true;
}
}

return false;
})();

if (isAtomSuperatomLeavingGroup && onlyOneAtomSelected) {
return (
<>
Expand Down Expand Up @@ -231,7 +246,11 @@ const AtomMenuItems: FC<MenuItemsProps<AtomContextMenuProps>> = (props) => {
!atomInSgroupWithLabel &&
!maxAttachmentPointsAmount &&
!isAtomSuperatomLeavingGroup && (
<Item {...props} onClick={handleAddAttachmentPoint}>
<Item
{...props}
onClick={handleAddAttachmentPoint}
disabled={isAddAttachmentPointDisabled}
>
Add attachment point
</Item>
)}
Expand Down

0 comments on commit d81d27e

Please sign in to comment.