diff --git a/packages/ketcher-polymer-editor-react/src/components/contextMenu/RNAContextMenu.tsx b/packages/ketcher-polymer-editor-react/src/components/contextMenu/RNAContextMenu.tsx index 755fa5b947..749abc8049 100644 --- a/packages/ketcher-polymer-editor-react/src/components/contextMenu/RNAContextMenu.tsx +++ b/packages/ketcher-polymer-editor-react/src/components/contextMenu/RNAContextMenu.tsx @@ -1,18 +1,13 @@ -import { - Item, - ItemParams, - Menu, - PredicateParams, - Separator, -} from 'react-contexify'; +import { Item, ItemParams, Menu, Separator } from 'react-contexify'; import { openModal } from 'state/modal'; -import { useAppDispatch } from 'hooks'; +import { useAppDispatch, useAppSelector } from 'hooks'; import { ReactElement } from 'react'; import { CONTEXT_MENU_ID } from './types'; -import { setActivePreset } from 'state/rna-builder'; +import { selectActivePreset } from 'state/rna-builder'; export const RNAContextMenu = () => { const dispatch = useAppDispatch(); + const activePreset = useAppSelector(selectActivePreset); const RNAMenus = [ { name: 'duplicateandedit', title: 'Duplicate and Edit' }, { name: 'edit', title: 'Edit', seperator: true }, @@ -20,24 +15,21 @@ export const RNAContextMenu = () => { ]; const isItemDisabled = (name: string) => { - return ({ props }: PredicateParams) => { - if (name === 'deletepreset' && props.preset?.default) { - return true; - } - return false; - }; + if (name === 'deletepreset' && activePreset.default) { + return true; + } + return false; }; const handleMenuChange = ({ id, props }: ItemParams) => { switch (id) { case 'duplicateandedit': - props.duplicatePreset(props.preset); + props.duplicatePreset(); break; case 'edit': props.activateEditMode(); break; case 'deletepreset': - dispatch(setActivePreset(props.preset)); dispatch(openModal('delete')); break; } diff --git a/packages/ketcher-polymer-editor-react/src/components/modal/Delete/Delete.tsx b/packages/ketcher-polymer-editor-react/src/components/modal/Delete/Delete.tsx index 2caf60abe0..5bb84f14f1 100644 --- a/packages/ketcher-polymer-editor-react/src/components/modal/Delete/Delete.tsx +++ b/packages/ketcher-polymer-editor-react/src/components/modal/Delete/Delete.tsx @@ -17,7 +17,13 @@ import { Modal } from 'components/shared/modal'; import { useCallback } from 'react'; import { ActionButton } from 'components/shared/actionButton'; import { useAppDispatch, useAppSelector } from 'hooks'; -import { deletePreset, selectActivePreset } from 'state/rna-builder'; +import { + deletePreset, + selectActivePreset, + selectPresets, + setActivePreset, + setIsEditMode, +} from 'state/rna-builder'; export interface Props { onClose: () => void; @@ -26,6 +32,7 @@ export interface Props { const Delete = ({ isModalOpen, onClose }: Props) => { const dispatch = useAppDispatch(); + const presets = useAppSelector(selectPresets); const activePreset = useAppSelector(selectActivePreset); const onCloseCallback = useCallback(() => { onClose(); @@ -38,6 +45,10 @@ const Delete = ({ isModalOpen, onClose }: Props) => { const deleteHandler = () => { onCloseCallback(); dispatch(deletePreset(activePreset)); + dispatch(setIsEditMode(false)); + if (presets.length !== 0) { + dispatch(setActivePreset(presets[0])); + } }; return ( diff --git a/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaAccordion/RnaAccordion.tsx b/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaAccordion/RnaAccordion.tsx index 481b6b221a..5122aa0258 100644 --- a/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaAccordion/RnaAccordion.tsx +++ b/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaAccordion/RnaAccordion.tsx @@ -98,17 +98,6 @@ export const RnaAccordion = ({ } else setExpandedAccordion(rnaBuilderItem); }; - const handleContextMenu = (preset: IRnaPreset) => (event: TriggerEvent) => { - show({ - event, - props: { - duplicatePreset, - activateEditMode, - preset, - }, - }); - }; - const groupsData: IGroupsDataItem[] = [ { groupName: RnaBuilderPresetsItem.Presets, @@ -152,6 +141,17 @@ export const RnaAccordion = ({ dispatch(setActiveRnaBuilderItem(groupName)); }; + const handleContextMenu = (preset: IRnaPreset) => (event: TriggerEvent) => { + dispatch(setActivePreset(preset)); + show({ + event, + props: { + duplicatePreset, + activateEditMode, + }, + }); + }; + useEffect(() => { setExpandedAccordion(activeRnaBuilderItem); }, [activeRnaBuilderItem]); diff --git a/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaBuilder.tsx b/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaBuilder.tsx index 0551d6464f..f669c933c1 100644 --- a/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaBuilder.tsx +++ b/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaBuilder.tsx @@ -49,22 +49,21 @@ export const RnaBuilder = ({ libraryName }) => { dispatch(setDefaultPresets(defaultPresets)); }, [dispatch]); - const duplicatePreset = (preset?: IRnaPreset) => { - const currentPreset = preset || activePreset; + const duplicatePreset = () => { const duplicatedPreset = { - ...currentPreset, + ...activePreset, presetInList: undefined, - name: `${currentPreset.name}_Copy`, + name: `${activePreset.name}_Copy`, default: false, }; dispatch(setActivePreset(duplicatedPreset)); dispatch(savePreset(duplicatedPreset)); - setIsEditMode(true); + dispatch(setIsEditMode(true)); scrollToSelectedPreset(activePreset.name); }; const activateEditMode = () => { - setIsEditMode(true); + dispatch(setIsEditMode(true)); }; return (