@@ -8,6 +8,7 @@ import { actionType, actionObjectType } from './constants';
8
8
import { VIEWS } from '../../../js/constants/constants' ;
9
9
import { setCurrentVector , appendToBuyList , removeFromToBuyList , setHideAll } from '../selection/actions' ;
10
10
import { unmountPreviewComponent , shouldLoadProtein } from '../../components/preview/redux/dispatchActions' ;
11
+ import { setCurrentProject } from '../../components/projects/redux/actions' ;
11
12
import {
12
13
selectMoleculeGroup ,
13
14
onDeselectMoleculeGroup ,
@@ -81,18 +82,10 @@ import {
81
82
} from '../../components/datasets/redux/actions' ;
82
83
83
84
export const saveCurrentActionsList = ( snapshotID , projectID , nglViewList ) => ( dispatch , getState ) => {
84
- const state = getState ( ) ;
85
-
86
- let actionList = state . trackingReducers . track_actions_list ;
87
-
88
- if ( ! actionList || actionList . length === 0 ) {
89
- Promise . resolve ( dispatch ( getTrackingActions ( projectID ) ) ) . then ( response => {
90
- actionList = response ;
91
- dispatch ( saveActionsList ( snapshotID , actionList ) ) ;
92
- } ) ;
93
- } else {
85
+ Promise . resolve ( dispatch ( getTrackingActions ( projectID ) ) ) . then ( response => {
86
+ let actionList = response ;
94
87
dispatch ( saveActionsList ( snapshotID , actionList , nglViewList ) ) ;
95
- }
88
+ } ) ;
96
89
} ;
97
90
98
91
export const saveActionsList = ( snapshotID , actionList , nglViewList ) => ( dispatch , getState ) => {
@@ -329,8 +322,13 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
329
322
return list ;
330
323
} ;
331
324
325
+ export const resetRestoringState = ( ) => ( dispatch , getState ) => {
326
+ dispatch ( setTargetOn ( undefined ) ) ;
327
+ dispatch ( setIsActionsRestoring ( false , false ) ) ;
328
+ } ;
329
+
332
330
export const restoreCurrentActionsList = ( stages = [ ] ) => ( dispatch , getState ) => {
333
- dispatch ( setIsActionsRestoring ( true ) ) ;
331
+ dispatch ( setIsActionsRestoring ( true , false ) ) ;
334
332
335
333
Promise . resolve ( dispatch ( restoreTrackingActions ( ) ) ) . then ( response => {
336
334
dispatch ( setIsTrackingMoleculesRestoring ( true ) ) ;
@@ -390,7 +388,7 @@ const restoreTargetActions = (orderedActionList, stages) => (dispatch, getState)
390
388
}
391
389
} ;
392
390
393
- export const restoreAfterTargetActions = stages => ( dispatch , getState ) => {
391
+ export const restoreAfterTargetActions = ( stages , projectId ) => async ( dispatch , getState ) => {
394
392
const state = getState ( ) ;
395
393
396
394
const currentActionList = state . trackingReducers . current_actions_list ;
@@ -401,9 +399,11 @@ export const restoreAfterTargetActions = stages => (dispatch, getState) => {
401
399
const majorView = stages . find ( view => view . id === VIEWS . MAJOR_VIEW ) ;
402
400
const summaryView = stages . find ( view => view . id === VIEWS . SUMMARY_VIEW ) ;
403
401
404
- dispatch ( shouldLoadProtein ( { nglViewList : stages , currentSnapshotID : null , isLoadingCurrentSnapshot : false } ) ) ;
402
+ await dispatch (
403
+ shouldLoadProtein ( { nglViewList : stages , currentSnapshotID : null , isLoadingCurrentSnapshot : false } )
404
+ ) ;
405
405
406
- dispatch (
406
+ await dispatch (
407
407
loadMoleculeGroupsOfTarget ( {
408
408
summaryView : summaryView . stage ,
409
409
isStateLoaded : false ,
@@ -414,16 +414,15 @@ export const restoreAfterTargetActions = stages => (dispatch, getState) => {
414
414
. catch ( error => {
415
415
throw error ;
416
416
} )
417
- . finally ( ( ) => {
418
- Promise . resolve (
419
- dispatch ( restoreSitesActions ( orderedActionList , summaryView ) ) ,
420
- dispatch ( loadAllMolecules ( orderedActionList , targetId , majorView . stage ) ) ,
421
- dispatch ( loadAllDatasets ( orderedActionList , targetId , majorView . stage ) )
422
- ) . then ( ( ) => {
423
- dispatch ( restoreNglStateAction ( orderedActionList , stages ) ) ;
424
- dispatch ( restoreRepresentationActions ( orderedActionList , stages ) ) ;
425
- } ) ;
426
- } ) ;
417
+ . finally ( ( ) => { } ) ;
418
+
419
+ await dispatch ( restoreSitesActions ( orderedActionList , summaryView ) ) ;
420
+ await dispatch ( loadAllMolecules ( orderedActionList , targetId , majorView . stage ) ) ;
421
+ await dispatch ( loadAllDatasets ( orderedActionList , targetId , majorView . stage ) ) ;
422
+ await dispatch ( restoreRepresentationActions ( orderedActionList , stages ) ) ;
423
+ await dispatch ( restoreProject ( projectId ) ) ;
424
+ dispatch ( restoreNglStateAction ( orderedActionList , stages ) ) ;
425
+ dispatch ( setIsActionsRestoring ( false , true ) ) ;
427
426
}
428
427
} ;
429
428
@@ -432,20 +431,17 @@ const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState
432
431
if ( action && action . nglStateList ) {
433
432
action . nglStateList . forEach ( nglView => {
434
433
dispatch ( setOrientation ( nglView . id , nglView . orientation ) ) ;
435
-
436
- if ( nglView . id !== VIEWS . SUMMARY_VIEW ) {
437
- let viewStage = stages . find ( s => s . id === nglView . id ) ;
438
- if ( viewStage ) {
439
- viewStage . stage . viewerControls . orient ( nglView . orientation . elements ) ;
440
- }
434
+ let viewStage = stages . find ( s => s . id === nglView . id ) ;
435
+ if ( viewStage ) {
436
+ viewStage . stage . viewerControls . orient ( nglView . orientation . elements ) ;
441
437
}
442
438
} ) ;
443
439
}
444
440
} ;
445
441
446
- const loadAllDatasets = ( orderedActionList , target_on , stage ) => ( dispatch , getState ) => {
442
+ const loadAllDatasets = ( orderedActionList , target_on , stage ) => async ( dispatch , getState ) => {
447
443
dispatch ( setMoleculeListIsLoading ( true ) ) ;
448
- dispatch ( loadDataSets ( target_on ) )
444
+ await dispatch ( loadDataSets ( target_on ) )
449
445
. then ( results => {
450
446
return dispatch ( loadDatasetCompoundsWithScores ( ) ) ;
451
447
} )
@@ -460,7 +456,7 @@ const loadAllDatasets = (orderedActionList, target_on, stage) => (dispatch, getS
460
456
} ) ;
461
457
} ;
462
458
463
- const loadAllMolecules = ( orderedActionList , target_on , stage ) => ( dispatch , getState ) => {
459
+ const loadAllMolecules = ( orderedActionList , target_on , stage ) => async ( dispatch , getState ) => {
464
460
const state = getState ( ) ;
465
461
const list_type = listType . MOLECULE ;
466
462
@@ -477,17 +473,18 @@ const loadAllMolecules = (orderedActionList, target_on, stage) => (dispatch, get
477
473
} )
478
474
) ;
479
475
} ) ;
480
- Promise . all ( promises )
481
- . then ( results => {
482
- let listToSet = { } ;
483
- results . forEach ( molResult => {
484
- listToSet [ molResult . mol_group ] = molResult . molecules ;
485
- } ) ;
486
- dispatch ( setAllMolLists ( listToSet ) ) ;
487
- dispatch ( restoreMoleculesActions ( orderedActionList , stage ) ) ;
488
- dispatch ( setIsTrackingMoleculesRestoring ( false ) ) ;
489
- } )
490
- . catch ( err => console . log ( err ) ) ;
476
+ try {
477
+ const results = await Promise . all ( promises ) ;
478
+ let listToSet = { } ;
479
+ results . forEach ( molResult => {
480
+ listToSet [ molResult . mol_group ] = molResult . molecules ;
481
+ } ) ;
482
+ dispatch ( setAllMolLists ( listToSet ) ) ;
483
+ dispatch ( restoreMoleculesActions ( orderedActionList , stage ) ) ;
484
+ dispatch ( setIsTrackingMoleculesRestoring ( false ) ) ;
485
+ } catch ( err ) {
486
+ return console . log ( err ) ;
487
+ }
491
488
} ;
492
489
493
490
const restoreSitesActions = ( orderedActionList , summaryView ) => ( dispatch , getState ) => {
@@ -597,6 +594,27 @@ const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, get
597
594
}
598
595
} ;
599
596
597
+ const restoreProject = projectId => ( dispatch , getState ) => {
598
+ if ( projectId !== undefined ) {
599
+ return api ( { url : `${ base_url } /api/session-projects/${ projectId } /` } ) . then ( response => {
600
+ let promises = [ ] ;
601
+ promises . push (
602
+ dispatch (
603
+ setCurrentProject ( {
604
+ projectID : response . data . id ,
605
+ authorID : ( response . data . author && response . data . author . id ) || null ,
606
+ title : response . data . title ,
607
+ description : response . data . description ,
608
+ targetID : response . data . target . id ,
609
+ tags : JSON . parse ( response . data . tags )
610
+ } )
611
+ )
612
+ ) ;
613
+ return Promise . all ( promises ) ;
614
+ } ) ;
615
+ }
616
+ } ;
617
+
600
618
const restoreCompoundsActions = ( orderedActionList , stage ) => ( dispatch , getState ) => {
601
619
const state = getState ( ) ;
602
620
@@ -1457,11 +1475,10 @@ const copyActionsToProject = (toProject, setActionList = true) => (dispatch, get
1457
1475
const actionList = state . trackingReducers . project_actions_list ;
1458
1476
1459
1477
if ( toProject ) {
1460
- let newProject = { projectID : toProject . projectID , authorID : toProject . authorID } ;
1461
1478
let newActionsList = [ ] ;
1462
1479
1463
1480
actionList . forEach ( r => {
1464
- newActionsList . push ( Object . assign ( { ...r , project : newProject } ) ) ;
1481
+ newActionsList . push ( Object . assign ( { ...r } ) ) ;
1465
1482
} ) ;
1466
1483
1467
1484
if ( setActionList === true ) {
0 commit comments