From 5fe7b3bb5188cfb3876854745c90199ce4dc2c05 Mon Sep 17 00:00:00 2001 From: Vanda_Ponikarova Date: Mon, 1 May 2023 14:33:22 +0400 Subject: [PATCH] #2113 - Added remove struct action --- .../ketcher-react/src/script/ui/action/index.js | 14 -------------- .../src/script/ui/state/hotkeys.ts | 10 ++-------- .../ketcher-react/src/script/ui/state/shared.ts | 17 ++++++++++++----- .../toolbars/TopToolbar/TopToolbar.container.ts | 3 ++- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packages/ketcher-react/src/script/ui/action/index.js b/packages/ketcher-react/src/script/ui/action/index.js index 2e9e9ca655..1875fee753 100644 --- a/packages/ketcher-react/src/script/ui/action/index.js +++ b/packages/ketcher-react/src/script/ui/action/index.js @@ -222,20 +222,6 @@ const config = { }, hidden: (options) => isHidden(options, 'any-atom') }, - // Removing from what should be saved - structure, which was added to paste tool, - // but not yet rendered on canvas - 'remove-not-rendered-struct': { - action: { - thunk: (dispatch) => { - const savedSelectedTool = SettingsManager.selectionTool - - dispatch({ - type: 'ACTION', - action: savedSelectedTool || tools['select-rectangle'].action - }) - } - } - }, ...server, ...debug, ...tools, diff --git a/packages/ketcher-react/src/script/ui/state/hotkeys.ts b/packages/ketcher-react/src/script/ui/state/hotkeys.ts index 1708f8574e..d1bee93790 100644 --- a/packages/ketcher-react/src/script/ui/state/hotkeys.ts +++ b/packages/ketcher-react/src/script/ui/state/hotkeys.ts @@ -23,15 +23,13 @@ import { ChemicalMimeType } from 'ketcher-core' import { debounce, isEqual } from 'lodash/fp' -import { load, onAction } from './shared' +import { load, onAction, removeStructAction } from './shared' import actions from '../action' -import tools from '../action/tools' import keyNorm from '../data/convert/keynorm' import { openDialog } from './modal' import { isIE } from 'react-device-detect' import { handleHotkeyOverItem } from './handleHotkeysOverItem' -import { SettingsManager } from '../utils/settingsManager' export function initKeydownListener(element) { return function (dispatch, getState) { @@ -45,11 +43,7 @@ export function initKeydownListener(element) { function removeNotRenderedStruct(actionTool, group, dispatch) { const affectedTools = ['paste', 'template'] if (affectedTools.includes(actionTool.tool) && group?.includes('save')) { - const savedSelectedTool = SettingsManager.selectionTool - dispatch({ - type: 'ACTION', - action: savedSelectedTool || tools['select-rectangle'].action - }) + dispatch(removeStructAction()) } } diff --git a/packages/ketcher-react/src/script/ui/state/shared.ts b/packages/ketcher-react/src/script/ui/state/shared.ts index 615a515468..bb116fa770 100644 --- a/packages/ketcher-react/src/script/ui/state/shared.ts +++ b/packages/ketcher-react/src/script/ui/state/shared.ts @@ -75,6 +75,17 @@ function parseStruct( } } +// Removing from what should be saved - structure, which was added to paste tool, +// but not yet rendered on canvas +export function removeStructAction(): { + type: string + action?: Record +} { + const savedSelectedTool = SettingsManager.selectionTool + + return onAction(savedSelectedTool || tools['select-rectangle'].action) +} + export function load(struct: Struct, options?) { return async (dispatch, getState) => { const state = getState() @@ -144,11 +155,7 @@ export function load(struct: Struct, options?) { if (fragment) { if (parsedStruct.isBlank()) { - const savedSelectedTool = SettingsManager.selectionTool - dispatch({ - type: 'ACTION', - action: savedSelectedTool || tools['select-rectangle'].action - }) + dispatch(removeStructAction()) } else { dispatch(onAction({ tool: 'paste', opts: parsedStruct })) } diff --git a/packages/ketcher-react/src/script/ui/views/toolbars/TopToolbar/TopToolbar.container.ts b/packages/ketcher-react/src/script/ui/views/toolbars/TopToolbar/TopToolbar.container.ts index 9b24954556..2accc99f17 100644 --- a/packages/ketcher-react/src/script/ui/views/toolbars/TopToolbar/TopToolbar.container.ts +++ b/packages/ketcher-react/src/script/ui/views/toolbars/TopToolbar/TopToolbar.container.ts @@ -21,6 +21,7 @@ import { connect } from 'react-redux' import { onAction } from '../../../state' import action from 'src/script/ui/action/index.js' import { shortcutStr } from '../shortcutStr' +import { removeStructAction } from 'src/script/ui/state/shared' const shortcuts = Object.keys(action).reduce((acc, key) => { if (action[key]?.shortcut) { @@ -82,7 +83,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => { onClear: () => dispatchAction('clear'), onFileOpen: () => dispatchAction('open'), onSave: () => { - dispatchAction('remove-not-rendered-struct') + dispatch(removeStructAction()) dispatchAction('save') }, onUndo: () => dispatchAction('undo'),