diff --git a/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaEditor/RnaEditor.tsx b/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaEditor/RnaEditor.tsx index 124eccff2f..d6ee8e4cd8 100644 --- a/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaEditor/RnaEditor.tsx +++ b/packages/ketcher-polymer-editor-react/src/components/monomerLibrary/RnaBuilder/RnaEditor/RnaEditor.tsx @@ -29,6 +29,7 @@ import { RnaBuilderPresetsItem, savePreset, selectActivePreset, + selectActiveRnaBuilderItem, selectIsEditMode, selectPresetFullName, selectPresets, @@ -53,6 +54,9 @@ export const RnaEditor = () => { const presets = useAppSelector(selectPresets); const isEditMode = useAppSelector(selectIsEditMode); const activePresetFullName = selectPresetFullName(activePreset); + const activeMonomerGroup = useAppSelector(selectActiveRnaBuilderItem); + const [, setPresetName] = useState(''); + const [editedPresetName, setEditedPresetName] = useState(false); const dispatch = useAppDispatch(); const hasPresets = presets.length !== 0; @@ -79,8 +83,23 @@ export const RnaEditor = () => { setExpanded(!expanded); }; - const changeName = (event: ChangeEvent) => { - dispatch(setActivePresetName(event.target.value)); + useEffect(() => { + if ( + activeMonomerGroup !== RnaBuilderPresetsItem.Presets && + !editedPresetName + ) { + setPresetName(activePresetFullName); + dispatch(setActivePresetName(activePresetFullName)); + } + }, [activeMonomerGroup, activePresetFullName, editedPresetName]); + + const onChangeName = (event: ChangeEvent) => { + if (isEditMode) { + const newPresetName = event.target.value; + dispatch(setActivePresetName(newPresetName)); + setPresetName(newPresetName); + setEditedPresetName(newPresetName.trim() !== ''); + } }; const saveActivePreset = () => { @@ -106,14 +125,16 @@ export const RnaEditor = () => { }; const cancelEdit = () => { - if (presets.length === 0) { + if (presets.length === 0 || !activePreset.presetInList) { dispatch(createNewPreset()); - return; + } else { + dispatch(setActivePreset(activePreset.presetInList)); } if (!activePreset.presetInList) { dispatch(setActivePreset(presets[0])); } + setIsEditMode(false); }; @@ -142,7 +163,7 @@ export const RnaEditor = () => {