@@ -29,9 +29,10 @@ import { PropTypes } from 'prop-types';
2929import cx from 'classnames' ;
3030import fp from 'lodash/fp' ;
3131import { uniqueId , uniq } from 'lodash' ;
32+ import isEqual from 'lodash/isEqual' ;
3233
3334import Notifications from '@stackstorm/st2flow-notifications' ;
34- import { HotKeys } from 'react-hotkeys' ;
35+ import { HotKeys } from 'react-hotkeys' ;
3536
3637import { BoundingBox } from './routing-graph' ;
3738import Task from './task' ;
@@ -46,6 +47,8 @@ import PoissonRectangleSampler from './poisson-rect';
4647
4748import { origin } from './const' ;
4849
50+ import store from '../../apps/st2-workflows/store' ;
51+
4952import style from './style.css' ;
5053type DOMMatrix = {
5154 m11 : number ,
@@ -257,8 +260,10 @@ export default class Canvas extends Component {
257260 this . handleUpdate ( ) ;
258261 }
259262
260- componentDidUpdate ( ) {
263+ componentDidUpdate ( prevProps ) {
261264 this . handleUpdate ( ) ;
265+
266+ this . handleAutoSaveUpdates ( prevProps ) ;
262267 }
263268
264269 componentWillUnmount ( ) {
@@ -387,11 +392,26 @@ export default class Canvas extends Component {
387392 // finally, place the unplaced tasks. using handleTaskMove will also ensure
388393 // that the placement gets set on the model and the YAML.
389394 needsCoords . forEach ( ( { task, transitionsTo} ) => {
390- this . handleTaskMove ( task , sampler . getNext ( task . name , transitionsTo ) , true ) ;
395+ this . handleTaskMove ( task , sampler . getNext ( task . name , transitionsTo ) ) ;
391396 } ) ;
392397 }
393398 }
394399
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+
395415 handleMouseWheel = ( e : Wheel ) : ?false => {
396416 // considerations on scale factor (BM, 2019-02-07)
397417 // on Chrome Mac and Safari Mac:
@@ -576,16 +596,18 @@ export default class Canvas extends Component {
576596 return false ;
577597 }
578598
579- handleTaskMove = async ( task : TaskRefInterface , points : CanvasPoint , autoSave ) => {
599+ handleTaskMove = async ( task : TaskRefInterface , points : CanvasPoint ) => {
580600 const x = points . x ;
581601 const y = points . y ;
582602 const coords = { x, y} ;
583603 this . props . issueModelCommand ( 'updateTask' , task , { coords } ) ;
604+
605+ const { autosaveEnabled } = store . getState ( ) ;
584606
585- if ( autoSave && ! this . props . dirtyflag ) {
586- await this . props . fetchActionscalled ( ) ;
607+ if ( autosaveEnabled && this . props . dirtyflag ) {
587608 this . props . saveData ( ) ;
588- }
609+ await this . props . fetchActionscalled ( ) ;
610+ }
589611
590612 }
591613
@@ -807,7 +829,7 @@ export default class Canvas extends Component {
807829 task = { task }
808830 selected = { task . name === navigation . task && ! selectedTransitionGroups . length }
809831 scale = { scale }
810- onMove = { ( ...a ) => this . handleTaskMove ( task , ...a , false ) }
832+ onMove = { ( ...a ) => this . handleTaskMove ( task , ...a ) }
811833 onConnect = { ( ...a ) => this . handleTaskConnect ( task , ...a ) }
812834 onClick = { ( ) => this . handleTaskSelect ( task ) }
813835 onDelete = { ( ) => this . handleTaskDelete ( task ) }
0 commit comments