Skip to content

Commit

Permalink
Rename ci to closestItem
Browse files Browse the repository at this point in the history
  • Loading branch information
yuleicul committed Dec 19, 2022
1 parent 8ae404e commit 800a98c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const ContextMenuTrigger: React.FC = ({ children }) => {
* More details: https://github.com/epam/ketcher/pull/1896
*/
const hasConflictWithFunctionalGroupMenu = useCallback(
(ci: any) => {
(closestItem: any) => {
const editor = getKetcherInstance().editor as Editor
const struct = editor.struct()

const functionalGroupId = FunctionalGroup.findFunctionalGroupByBond(
struct,
struct.functionalGroups,
ci.id
closestItem.id
)
const hasRelatedSGroup = struct.functionalGroups.some(
(item) => item.relatedSGroupId === functionalGroupId
Expand Down Expand Up @@ -89,22 +89,22 @@ const ContextMenuTrigger: React.FC = ({ children }) => {
const handleDisplay = useCallback<React.MouseEventHandler<HTMLDivElement>>(
(event) => {
const editor = getKetcherInstance().editor as Editor
const ci = editor.findItem(event, ['bonds'])
const closestItem = editor.findItem(event, ['bonds'])

if (!ci) {
if (!closestItem) {
hideAll()
return
}

if (hasConflictWithFunctionalGroupMenu(ci)) {
if (hasConflictWithFunctionalGroupMenu(closestItem)) {
hideAll()
return
}

const selection = editor.selection()
const isRightClickingSelection: number | undefined = selection?.[
ci.map
]?.findIndex((selectedItemId) => selectedItemId === ci.id)
closestItem.map
]?.findIndex((selectedItemId) => selectedItemId === closestItem.id)

if (
isRightClickingSelection !== undefined &&
Expand All @@ -115,17 +115,17 @@ const ContextMenuTrigger: React.FC = ({ children }) => {
event,
props: {
selected: true,
ci
closestItem
}
})
} else if (ci.map === 'bonds') {
} else if (closestItem.map === 'bonds') {
// Show menu items for single update
if (selection) {
editor.render.ctab.setSelection(null)
}
show({
event,
props: { selected: false, ci }
props: { selected: false, closestItem }
})
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type ContextMenuItemProps = {
selected: boolean
ci: any
closestItem: any
}

export type ContextMenuItemData = unknown
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const BondBatchOperations: React.FC = (props) => {
props
}: ItemParams<ContextMenuItemProps, ContextMenuItemData>) => {
const editor = getKetcherInstance().editor as Editor
const bondId = props?.ci.id
const bondId = props?.closestItem.id
const bond = editor.render.ctab.bonds.get(bondId)?.b

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const BondSingleOperations: React.FC = (props) => {
props
}: ItemParams<ContextMenuItemProps, ContextMenuItemData>) => {
const editor = getKetcherInstance().editor as Editor
const bondId = props?.ci.id
const bondId = props?.closestItem.id
const bond = editor.render.ctab.bonds.get(bondId)?.b

try {
Expand All @@ -58,7 +58,7 @@ const BondSingleOperations: React.FC = (props) => {
props
}: ItemParams<ContextMenuItemProps, ContextMenuItemData>) => {
const editor = getKetcherInstance().editor as Editor
const bondId = props?.ci.id
const bondId = props?.closestItem.id

editor.update(fromOneBondDeletion(editor.render.ctab, bondId))
},
Expand All @@ -68,7 +68,7 @@ const BondSingleOperations: React.FC = (props) => {
const handleTypeChange = useCallback(
({ id, props }: ItemParams<ContextMenuItemProps, ContextMenuItemData>) => {
const editor = getKetcherInstance().editor as Editor
const bondId = props?.ci.id
const bondId = props?.closestItem.id
const bondProps = tools[id].action.opts

editor.update(fromBondsAttrs(editor.render.ctab, bondId, bondProps))
Expand Down

0 comments on commit 800a98c

Please sign in to comment.