@@ -14,6 +14,7 @@ import {
14
14
onDeselectMoleculeGroup ,
15
15
loadMoleculeGroupsOfTarget
16
16
} from '../../components/preview/moleculeGroups/redux/dispatchActions' ;
17
+ import { loadTargetList } from '../../components/target/redux/dispatchActions' ;
17
18
import { resetTargetState , setTargetOn } from '../api/actions' ;
18
19
import {
19
20
addComplex ,
@@ -81,11 +82,9 @@ import {
81
82
setDeselectedAllByType as setDeselectedAllByTypeOfDataset
82
83
} from '../../components/datasets/redux/actions' ;
83
84
84
- export const saveCurrentActionsList = ( snapshotID , projectID , nglViewList ) => ( dispatch , getState ) => {
85
- Promise . resolve ( dispatch ( getTrackingActions ( projectID ) ) ) . then ( response => {
86
- let actionList = response ;
87
- dispatch ( saveActionsList ( snapshotID , actionList , nglViewList ) ) ;
88
- } ) ;
85
+ export const saveCurrentActionsList = ( snapshotID , projectID , nglViewList ) => async ( dispatch , getState ) => {
86
+ let actionList = await dispatch ( getTrackingActions ( projectID ) ) ;
87
+ dispatch ( saveActionsList ( snapshotID , actionList , nglViewList ) ) ;
89
88
} ;
90
89
91
90
export const saveActionsList = ( snapshotID , actionList , nglViewList ) => ( dispatch , getState ) => {
@@ -95,15 +94,15 @@ export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatc
95
94
const currentSites = state . selectionReducers . mol_group_selection ;
96
95
const currentLigands = state . selectionReducers . fragmentDisplayList ;
97
96
const currentProteins = state . selectionReducers . proteinList ;
98
- const currentComplexes = state . selectionReducers . complexLists ;
97
+ const currentComplexes = state . selectionReducers . complexList ;
99
98
const currentSurfaces = state . selectionReducers . surfaceList ;
100
99
const currentVectors = state . selectionReducers . vectorOnList ;
101
100
const currentBuyList = state . selectionReducers . to_buy_list ;
102
101
const currentVector = state . selectionReducers . currentVector ;
103
102
const currentSelectionAll = state . selectionReducers . moleculeAllSelection ;
104
103
105
104
const currentDatasetLigands = state . datasetsReducers . ligandLists ;
106
- const currentDatasetProteins = state . datasetsReducers . proteinList ;
105
+ const currentDatasetProteins = state . datasetsReducers . proteinLists ;
107
106
const currentDatasetComplexes = state . datasetsReducers . complexLists ;
108
107
const currentDatasetSurfaces = state . datasetsReducers . surfaceLists ;
109
108
const currentDatasetSelectionAll = state . datasetsReducers . moleculeAllSelection ;
@@ -208,17 +207,19 @@ export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatc
208
207
currentActions
209
208
) ;
210
209
211
- let nglStateList = nglViewList . map ( nglView => {
212
- return { id : nglView . id , orientation : nglView . stage . viewerControls . getOrientation ( ) } ;
213
- } ) ;
210
+ if ( nglViewList ) {
211
+ let nglStateList = nglViewList . map ( nglView => {
212
+ return { id : nglView . id , orientation : nglView . stage . viewerControls . getOrientation ( ) } ;
213
+ } ) ;
214
214
215
- let trackAction = {
216
- type : actionType . NGL_STATE ,
217
- timestamp : Date . now ( ) ,
218
- nglStateList : nglStateList
219
- } ;
215
+ let trackAction = {
216
+ type : actionType . NGL_STATE ,
217
+ timestamp : Date . now ( ) ,
218
+ nglStateList : nglStateList
219
+ } ;
220
220
221
- currentActions . push ( Object . assign ( { ...trackAction } ) ) ;
221
+ currentActions . push ( Object . assign ( { ...trackAction } ) ) ;
222
+ }
222
223
223
224
dispatch ( setCurrentActionsList ( currentActions ) ) ;
224
225
dispatch ( saveTrackingActions ( currentActions , snapshotID ) ) ;
@@ -323,6 +324,10 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
323
324
} ;
324
325
325
326
export const resetRestoringState = ( ) => ( dispatch , getState ) => {
327
+ dispatch ( setActionsList ( [ ] ) ) ;
328
+ dispatch ( setProjectActionList ( [ ] ) ) ;
329
+ dispatch ( setSendActionsList ( [ ] ) ) ;
330
+
326
331
dispatch ( setTargetOn ( undefined ) ) ;
327
332
dispatch ( setIsActionsRestoring ( false , false ) ) ;
328
333
} ;
@@ -333,8 +338,8 @@ export const restoreCurrentActionsList = (stages = []) => (dispatch, getState) =
333
338
Promise . resolve ( dispatch ( restoreTrackingActions ( ) ) ) . then ( response => {
334
339
dispatch ( setIsTrackingMoleculesRestoring ( true ) ) ;
335
340
dispatch ( setIsTrackingCompoundsRestoring ( true ) ) ;
336
- dispatch ( unmountPreviewComponent ( stages ) ) ;
337
341
dispatch ( resetTargetState ( ) ) ;
342
+ dispatch ( unmountPreviewComponent ( stages ) ) ;
338
343
dispatch ( restoreStateBySavedActionList ( stages ) ) ;
339
344
} ) ;
340
345
} ;
@@ -373,7 +378,15 @@ const restoreStateBySavedActionList = stages => (dispatch, getState) => {
373
378
const currentActionList = state . trackingReducers . current_actions_list ;
374
379
const orderedActionList = currentActionList . sort ( ( a , b ) => a . timestamp - b . timestamp ) ;
375
380
376
- dispatch ( restoreTargetActions ( orderedActionList , stages ) ) ;
381
+ let onCancel = ( ) => { } ;
382
+ dispatch ( loadTargetList ( onCancel ) )
383
+ . then ( ( ) => dispatch ( restoreTargetActions ( orderedActionList , stages ) ) )
384
+ . catch ( error => {
385
+ throw new Error ( error ) ;
386
+ } ) ;
387
+ return ( ) => {
388
+ onCancel ( ) ;
389
+ } ;
377
390
} ;
378
391
379
392
const restoreTargetActions = ( orderedActionList , stages ) => ( dispatch , getState ) => {
@@ -512,7 +525,7 @@ const restoreMoleculesActions = (orderedActionList, stage) => (dispatch, getStat
512
525
dispatch ( addNewType ( moleculesAction , actionType . SIDECHAINS_TURNED_ON , 'protein' , stage , state ) ) ;
513
526
dispatch ( addNewType ( moleculesAction , actionType . INTERACTIONS_TURNED_ON , 'complex' , stage , state ) ) ;
514
527
dispatch ( addNewType ( moleculesAction , actionType . SURFACE_TURNED_ON , 'surface' , stage , state ) ) ;
515
- dispatch ( addNewType ( moleculesAction , actionType . VECTOR_SELECTED , 'vector' , stage , state ) ) ;
528
+ dispatch ( addNewType ( moleculesAction , actionType . VECTORS_TURNED_ON , 'vector' , stage , state ) ) ;
516
529
}
517
530
518
531
let vectorAction = orderedActionList . find ( action => action . type === actionType . VECTOR_SELECTED ) ;
@@ -1384,7 +1397,7 @@ export const checkSendTrackingActions = (save = false) => (dispatch, getState) =
1384
1397
}
1385
1398
} ;
1386
1399
1387
- const sendTrackingActions = ( sendActions , project ) => ( dispatch , getState ) => {
1400
+ const sendTrackingActions = ( sendActions , project , clear = true ) => ( dispatch , getState ) => {
1388
1401
if ( project ) {
1389
1402
const projectID = project && project . projectID ;
1390
1403
@@ -1403,7 +1416,9 @@ const sendTrackingActions = (sendActions, project) => (dispatch, getState) => {
1403
1416
data : JSON . stringify ( dataToSend )
1404
1417
} )
1405
1418
. then ( ( ) => {
1406
- dispatch ( setSendActionsList ( [ ] ) ) ;
1419
+ if ( clear === true ) {
1420
+ dispatch ( setSendActionsList ( [ ] ) ) ;
1421
+ }
1407
1422
} )
1408
1423
. catch ( error => {
1409
1424
throw new Error ( error ) ;
@@ -1464,13 +1479,14 @@ const getTrackingActions = projectID => (dispatch, getState) => {
1464
1479
const checkActionsProject = projectID => ( dispatch , getState ) => {
1465
1480
const state = getState ( ) ;
1466
1481
const currentProject = state . projectReducers . currentProject ;
1482
+ const currentProjectID = currentProject && currentProject . projectID ;
1467
1483
1468
1484
Promise . resolve ( dispatch ( getTrackingActions ( projectID ) ) ) . then ( ( ) => {
1469
- dispatch ( copyActionsToProject ( currentProject ) ) ;
1485
+ dispatch ( copyActionsToProject ( currentProject , true , currentProjectID && currentProjectID != null ? true : false ) ) ;
1470
1486
} ) ;
1471
1487
} ;
1472
1488
1473
- const copyActionsToProject = ( toProject , setActionList = true ) => ( dispatch , getState ) => {
1489
+ const copyActionsToProject = ( toProject , setActionList = true , clearSendList = true ) => ( dispatch , getState ) => {
1474
1490
const state = getState ( ) ;
1475
1491
const actionList = state . trackingReducers . project_actions_list ;
1476
1492
@@ -1484,7 +1500,7 @@ const copyActionsToProject = (toProject, setActionList = true) => (dispatch, get
1484
1500
if ( setActionList === true ) {
1485
1501
dispatch ( setActionsList ( newActionsList ) ) ;
1486
1502
}
1487
- dispatch ( sendTrackingActions ( newActionsList , toProject ) ) ;
1503
+ dispatch ( sendTrackingActions ( newActionsList , toProject , clearSendList ) ) ;
1488
1504
}
1489
1505
} ;
1490
1506
@@ -1496,6 +1512,6 @@ export const sendTrackingActionsByProjectId = (projectID, authorID) => (dispatch
1496
1512
const project = { projectID, authorID } ;
1497
1513
1498
1514
Promise . resolve ( dispatch ( getTrackingActions ( currentProjectID ) ) ) . then ( ( ) => {
1499
- dispatch ( copyActionsToProject ( project , false ) ) ;
1515
+ dispatch ( copyActionsToProject ( project , false , currentProjectID && currentProjectID != null ? true : false ) ) ;
1500
1516
} ) ;
1501
1517
} ;
0 commit comments