@@ -29,9 +29,10 @@ import { PropTypes } from 'prop-types';
29
29
import cx from 'classnames' ;
30
30
import fp from 'lodash/fp' ;
31
31
import { uniqueId , uniq } from 'lodash' ;
32
+ import isEqual from 'lodash/isEqual' ;
32
33
33
34
import Notifications from '@stackstorm/st2flow-notifications' ;
34
- import { HotKeys } from 'react-hotkeys' ;
35
+ import { HotKeys } from 'react-hotkeys' ;
35
36
36
37
import { BoundingBox } from './routing-graph' ;
37
38
import Task from './task' ;
@@ -46,6 +47,8 @@ import PoissonRectangleSampler from './poisson-rect';
46
47
47
48
import { origin } from './const' ;
48
49
50
+ import store from '../../apps/st2-workflows/store' ;
51
+
49
52
import style from './style.css' ;
50
53
type DOMMatrix = {
51
54
m11 : number ,
@@ -257,8 +260,10 @@ export default class Canvas extends Component {
257
260
this . handleUpdate ( ) ;
258
261
}
259
262
260
- componentDidUpdate ( ) {
263
+ componentDidUpdate ( prevProps ) {
261
264
this . handleUpdate ( ) ;
265
+
266
+ this . handleAutoSaveUpdates ( prevProps ) ;
262
267
}
263
268
264
269
componentWillUnmount ( ) {
@@ -387,11 +392,26 @@ export default class Canvas extends Component {
387
392
// finally, place the unplaced tasks. using handleTaskMove will also ensure
388
393
// that the placement gets set on the model and the YAML.
389
394
needsCoords . forEach ( ( { task, transitionsTo} ) => {
390
- this . handleTaskMove ( task , sampler . getNext ( task . name , transitionsTo ) , true ) ;
395
+ this . handleTaskMove ( task , sampler . getNext ( task . name , transitionsTo ) ) ;
391
396
} ) ;
392
397
}
393
398
}
394
399
400
+ handleAutoSaveUpdates ( prevProps ) {
401
+ const { saveData, transitions, tasks} = this . props ;
402
+ const { autosaveEnabled } = store . getState ( ) ;
403
+
404
+ if ( autosaveEnabled ) {
405
+ if ( ! isEqual ( prevProps . transitions , transitions ) ) {
406
+ saveData ( ) ;
407
+ }
408
+
409
+ if ( ! isEqual ( prevProps . tasks , tasks ) ) {
410
+ this . props . saveData ( ) ;
411
+ }
412
+ }
413
+ }
414
+
395
415
handleMouseWheel = ( e : Wheel ) : ?false => {
396
416
// considerations on scale factor (BM, 2019-02-07)
397
417
// on Chrome Mac and Safari Mac:
@@ -576,16 +596,18 @@ export default class Canvas extends Component {
576
596
return false ;
577
597
}
578
598
579
- handleTaskMove = async ( task : TaskRefInterface , points : CanvasPoint , autoSave ) => {
599
+ handleTaskMove = async ( task : TaskRefInterface , points : CanvasPoint ) => {
580
600
const x = points . x ;
581
601
const y = points . y ;
582
602
const coords = { x, y} ;
583
603
this . props . issueModelCommand ( 'updateTask' , task , { coords } ) ;
604
+
605
+ const { autosaveEnabled } = store . getState ( ) ;
584
606
585
- if ( autoSave && ! this . props . dirtyflag ) {
586
- await this . props . fetchActionscalled ( ) ;
607
+ if ( autosaveEnabled && this . props . dirtyflag ) {
587
608
this . props . saveData ( ) ;
588
- }
609
+ await this . props . fetchActionscalled ( ) ;
610
+ }
589
611
590
612
}
591
613
@@ -807,7 +829,7 @@ export default class Canvas extends Component {
807
829
task = { task }
808
830
selected = { task . name === navigation . task && ! selectedTransitionGroups . length }
809
831
scale = { scale }
810
- onMove = { ( ...a ) => this . handleTaskMove ( task , ...a , false ) }
832
+ onMove = { ( ...a ) => this . handleTaskMove ( task , ...a ) }
811
833
onConnect = { ( ...a ) => this . handleTaskConnect ( task , ...a ) }
812
834
onClick = { ( ) => this . handleTaskSelect ( task ) }
813
835
onDelete = { ( ) => this . handleTaskDelete ( task ) }
0 commit comments