Skip to content

Commit

Permalink
#2113 - Added remove struct action
Browse files Browse the repository at this point in the history
  • Loading branch information
VandaEPAM committed May 1, 2023
1 parent 64dcb2d commit 5fe7b3b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
14 changes: 0 additions & 14 deletions packages/ketcher-react/src/script/ui/action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions packages/ketcher-react/src/script/ui/state/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
}
}

Expand Down
17 changes: 12 additions & 5 deletions packages/ketcher-react/src/script/ui/state/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>
} {
const savedSelectedTool = SettingsManager.selectionTool

return onAction(savedSelectedTool || tools['select-rectangle'].action)
}

export function load(struct: Struct, options?) {
return async (dispatch, getState) => {
const state = getState()
Expand Down Expand Up @@ -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 }))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 5fe7b3b

Please sign in to comment.