@@ -17,8 +17,7 @@ import React, { Component } from 'react';
1717// import ReactDOM from 'react-dom';
1818import { Provider , connect } from 'react-redux' ;
1919import { PropTypes } from 'prop-types' ;
20- import { HotKeys } from 'react-hotkeys' ;
21- import { pick , mapValues , get } from 'lodash' ;
20+ import { mapValues , get } from 'lodash' ;
2221import cx from 'classnames' ;
2322import url from 'url' ;
2423import Menu from '@stackstorm/module-menu' ;
@@ -34,18 +33,6 @@ import globalStore from '@stackstorm/module-store';
3433import store from './store' ;
3534import style from './style.css' ;
3635
37- function guardKeyHandlers ( obj , names ) {
38- const filteredObj = pick ( obj , names ) ;
39- return mapValues ( filteredObj , fn => {
40- return e => {
41- if ( e . target === document . body ) {
42- e . preventDefault ( ) ;
43- fn . call ( obj ) ;
44- }
45- } ;
46- } ) ;
47- }
48-
4936const POLL_INTERVAL = 5000 ;
5037
5138@connect (
@@ -285,7 +272,7 @@ export default class Workflows extends Component {
285272 // don't need to return anything to the store. the handler will change dirty.
286273 return { } ;
287274 } ) ( ) ;
288-
275+
289276 store . dispatch ( {
290277 type : 'SAVE_WORKFLOW' ,
291278 promise,
@@ -295,10 +282,37 @@ export default class Workflows extends Component {
295282
296283 style = style
297284
298- keyMap = {
299- undo : [ 'ctrl+z' , 'meta+z' ] ,
300- redo : [ 'ctrl+shift+z' , 'meta+shift+z' ] ,
301- handleTaskDelete : [ 'del' , 'backspace' ] ,
285+ keyHandlers = {
286+ undo : ( ) => {
287+ store . dispatch ( { type : 'FLOW_UNDO' } ) ;
288+ } ,
289+ redo : ( ) => {
290+ store . dispatch ( { type : 'FLOW_REDO' } ) ;
291+ } ,
292+ save : async ( x ) => {
293+ if ( x ) {
294+ x . preventDefault ( ) ;
295+ x . stopPropagation ( ) ;
296+ }
297+
298+ try {
299+ await this . save ( ) ;
300+ store . dispatch ( { type : 'PUSH_SUCCESS' , source : 'icon-save' , message : 'Workflow saved.' } ) ;
301+ }
302+ catch ( e ) {
303+ const faultString = get ( e , 'response.data.faultstring' ) ;
304+ store . dispatch ( { type : 'PUSH_ERROR' , source : 'icon-save' , error : `Error saving workflow: ${ faultString } ` } ) ;
305+ }
306+ } ,
307+ copy : ( ) => {
308+ store . dispatch ( { type : 'PUSH_WARNING' , source : 'icon-save' , message : 'Select a task to copy' } ) ;
309+ } ,
310+ cut : ( ) => {
311+ store . dispatch ( { type : 'PUSH_WARNING' , source : 'icon-save' , message : 'Nothing to cut' } ) ;
312+ } ,
313+ paste : ( ) => {
314+ store . dispatch ( { type : 'PUSH_WARNING' , source : 'icon-save' , message : 'Nothing to paste' } ) ;
315+ } ,
302316 }
303317
304318 render ( ) {
@@ -323,13 +337,10 @@ export default class Workflows extends Component {
323337 < Menu location = { location } routes = { this . props . routes } />
324338 < div className = "component-row-content" >
325339 { ! isCollapsed . palette && < Palette className = "palette" actions = { actions } /> }
326- < HotKeys
340+ < div
327341 style = { { flex : 1 } }
328- keyMap = { this . keyMap }
329- attach = { document . body }
330- handlers = { guardKeyHandlers ( this . props , [ 'undo' , 'redo' ] ) }
331342 >
332- < Canvas className = "canvas" location = { location } match = { match } fetchActionscalled = { e => this . props . fetchActions ( ) } saveData = { e => this . save ( ) } dirtyflag = { this . props . dirty } >
343+ < Canvas className = "canvas" location = { location } match = { match } fetchActionscalled = { e => this . props . fetchActions ( ) } save = { this . keyHandlers . save } dirtyflag = { this . props . dirty } undo = { this . keyHandlers . undo } redo = { this . keyHandlers . redo } >
333344 < Toolbar >
334345 < ToolbarButton key = "undo" icon = "icon-redirect" title = "Undo" errorMessage = "Could not undo." onClick = { ( ) => undo ( ) } />
335346 < ToolbarButton key = "redo" icon = "icon-redirect2" title = "Redo" errorMessage = "Could not redo." onClick = { ( ) => redo ( ) } />
@@ -379,7 +390,7 @@ export default class Workflows extends Component {
379390 </ ToolbarDropdown >
380391 </ Toolbar >
381392 </ Canvas >
382- </ HotKeys >
393+ </ div >
383394 { ! isCollapsed . details && < Details className = "details" actions = { actions } /> }
384395 </ div >
385396 </ div >
0 commit comments