@@ -17,8 +17,7 @@ import React, { Component } from 'react';
17
17
// import ReactDOM from 'react-dom';
18
18
import { Provider , connect } from 'react-redux' ;
19
19
import { PropTypes } from 'prop-types' ;
20
- import { HotKeys } from 'react-hotkeys' ;
21
- import { pick , mapValues , get } from 'lodash' ;
20
+ import { mapValues , get } from 'lodash' ;
22
21
import cx from 'classnames' ;
23
22
import url from 'url' ;
24
23
import Menu from '@stackstorm/module-menu' ;
@@ -34,18 +33,6 @@ import globalStore from '@stackstorm/module-store';
34
33
import store from './store' ;
35
34
import style from './style.css' ;
36
35
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
-
49
36
const POLL_INTERVAL = 5000 ;
50
37
51
38
@connect (
@@ -285,7 +272,7 @@ export default class Workflows extends Component {
285
272
// don't need to return anything to the store. the handler will change dirty.
286
273
return { } ;
287
274
} ) ( ) ;
288
-
275
+
289
276
store . dispatch ( {
290
277
type : 'SAVE_WORKFLOW' ,
291
278
promise,
@@ -295,10 +282,37 @@ export default class Workflows extends Component {
295
282
296
283
style = style
297
284
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
+ } ,
302
316
}
303
317
304
318
render ( ) {
@@ -323,13 +337,10 @@ export default class Workflows extends Component {
323
337
< Menu location = { location } routes = { this . props . routes } />
324
338
< div className = "component-row-content" >
325
339
{ ! isCollapsed . palette && < Palette className = "palette" actions = { actions } /> }
326
- < HotKeys
340
+ < div
327
341
style = { { flex : 1 } }
328
- keyMap = { this . keyMap }
329
- attach = { document . body }
330
- handlers = { guardKeyHandlers ( this . props , [ 'undo' , 'redo' ] ) }
331
342
>
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 } >
333
344
< Toolbar >
334
345
< ToolbarButton key = "undo" icon = "icon-redirect" title = "Undo" errorMessage = "Could not undo." onClick = { ( ) => undo ( ) } />
335
346
< ToolbarButton key = "redo" icon = "icon-redirect2" title = "Redo" errorMessage = "Could not redo." onClick = { ( ) => redo ( ) } />
@@ -379,7 +390,7 @@ export default class Workflows extends Component {
379
390
</ ToolbarDropdown >
380
391
</ Toolbar >
381
392
</ Canvas >
382
- </ HotKeys >
393
+ </ div >
383
394
{ ! isCollapsed . details && < Details className = "details" actions = { actions } /> }
384
395
</ div >
385
396
</ div >
0 commit comments