@@ -127,14 +127,74 @@ export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatc
127
127
getCurrentActionList ( orderedActionList , actionType . SITE_TURNED_ON , getCollection ( currentSites ) , currentActions ) ;
128
128
getCurrentActionList ( orderedActionList , actionType . LIGAND_TURNED_ON , getCollection ( currentLigands ) , currentActions ) ;
129
129
130
- getCurrentActionList ( orderedActionList , actionType . ALL_TURNED_ON , getCollection ( currentSelectionAll ) , currentActions ) ;
131
- getCurrentActionList (
130
+ getCurrentActionListOfAllSelection (
132
131
orderedActionList ,
133
132
actionType . ALL_TURNED_ON ,
134
- getCollectionOfDataset ( currentDatasetSelectionAll ) ,
133
+ getCollection ( currentSelectionAll ) ,
134
+ currentActions ,
135
+ getCollection ( currentLigands ) ,
136
+ getCollection ( currentProteins ) ,
137
+ getCollection ( currentComplexes )
138
+ ) ;
139
+
140
+ getCurrentActionListOfAllSelectionByType (
141
+ orderedActionList ,
142
+ actionType . ALL_TURNED_ON_BY_TYPE ,
143
+ 'ligand' ,
144
+ getCollection ( currentLigands ) ,
145
+ currentActions
146
+ ) ;
147
+
148
+ getCurrentActionListOfAllSelectionByType (
149
+ orderedActionList ,
150
+ actionType . ALL_TURNED_ON_BY_TYPE ,
151
+ 'protein' ,
152
+ getCollection ( currentProteins ) ,
153
+ currentActions
154
+ ) ;
155
+
156
+ getCurrentActionListOfAllSelectionByType (
157
+ orderedActionList ,
158
+ actionType . ALL_TURNED_ON_BY_TYPE ,
159
+ 'complex' ,
160
+ getCollection ( currentComplexes ) ,
161
+ currentActions
162
+ ) ;
163
+
164
+ getCurrentActionListOfAllSelectionByTypeOfDataset (
165
+ orderedActionList ,
166
+ actionType . ALL_TURNED_ON_BY_TYPE ,
167
+ 'ligand' ,
168
+ getCollectionOfDataset ( currentDatasetLigands ) ,
169
+ currentActions
170
+ ) ;
171
+
172
+ getCurrentActionListOfAllSelectionByTypeOfDataset (
173
+ orderedActionList ,
174
+ actionType . ALL_TURNED_ON_BY_TYPE ,
175
+ 'protein' ,
176
+ getCollectionOfDataset ( currentDatasetProteins ) ,
177
+ currentActions
178
+ ) ;
179
+
180
+ getCurrentActionListOfAllSelectionByTypeOfDataset (
181
+ orderedActionList ,
182
+ actionType . ALL_TURNED_ON_BY_TYPE ,
183
+ 'complex' ,
184
+ getCollectionOfDataset ( currentDatasetComplexes ) ,
135
185
currentActions
136
186
) ;
137
187
188
+ getCurrentActionListOfAllSelection (
189
+ orderedActionList ,
190
+ actionType . ALL_TURNED_ON ,
191
+ getCollectionOfDataset ( currentDatasetSelectionAll ) ,
192
+ currentActions ,
193
+ getCollectionOfDataset ( currentDatasetLigands ) ,
194
+ getCollectionOfDataset ( currentDatasetProteins ) ,
195
+ getCollectionOfDataset ( currentDatasetComplexes )
196
+ ) ;
197
+
138
198
getCurrentActionList (
139
199
orderedActionList ,
140
200
actionType . SIDECHAINS_TURNED_ON ,
@@ -279,6 +339,91 @@ const getCurrentActionList = (orderedActionList, type, collection, currentAction
279
339
}
280
340
} ;
281
341
342
+ const getCurrentActionListOfAllSelection = (
343
+ orderedActionList ,
344
+ type ,
345
+ collection ,
346
+ currentActions ,
347
+ ligandList ,
348
+ proteinList ,
349
+ complexList
350
+ ) => {
351
+ let actionList = orderedActionList . filter ( action => action . type === type ) ;
352
+
353
+ if ( collection ) {
354
+ collection . forEach ( data => {
355
+ let action = actionList . find ( action => action . object_id === data . id && action . dataset_id === data . datasetId ) ;
356
+
357
+ if ( action ) {
358
+ let ligandAction = ligandList . find (
359
+ data => data . id === action . object_id && action . dataset_id === data . datasetId
360
+ ) ;
361
+ let proteinAction = proteinList . find (
362
+ data => data . id === action . object_id && action . dataset_id === data . datasetId
363
+ ) ;
364
+ let complexAction = complexList . find (
365
+ data => data . id === action . object_id && action . dataset_id === data . datasetId
366
+ ) ;
367
+
368
+ let isLigand = ligandAction && ligandAction != null ? true : false ;
369
+ let isProtein = proteinAction && proteinAction != null ? true : false ;
370
+ let isComplex = complexAction && complexAction != null ? true : false ;
371
+ currentActions . push (
372
+ Object . assign ( { ...action , isLigand : isLigand , isProtein : isProtein , isComplex : isComplex } )
373
+ ) ;
374
+ }
375
+ } ) ;
376
+ }
377
+ } ;
378
+
379
+ const getCurrentActionListOfAllSelectionByType = ( orderedActionList , type , controlType , collection , currentActions ) => {
380
+ let action = orderedActionList . find (
381
+ action =>
382
+ action . type === type &&
383
+ action . control_type === controlType &&
384
+ ( action . object_type === actionObjectType . MOLECULE || action . object_type === actionObjectType . INSPIRATION )
385
+ ) ;
386
+ if ( action && collection ) {
387
+ let actionItems = action . items ;
388
+ let items = [ ] ;
389
+ collection . forEach ( data => {
390
+ let item = actionItems . find ( action => action . id === data . id && action . dataset_id === data . datasetId ) ;
391
+ if ( item ) {
392
+ items . push ( item ) ;
393
+ }
394
+ } ) ;
395
+
396
+ currentActions . push ( Object . assign ( { ...action , items : items } ) ) ;
397
+ }
398
+ } ;
399
+
400
+ const getCurrentActionListOfAllSelectionByTypeOfDataset = (
401
+ orderedActionList ,
402
+ type ,
403
+ controlType ,
404
+ collection ,
405
+ currentActions
406
+ ) => {
407
+ let action = orderedActionList . find (
408
+ action =>
409
+ action . type === type &&
410
+ action . control_type === controlType &&
411
+ ( action . object_type === actionObjectType . COMPOUND || action . object_type === actionObjectType . CROSS_REFERENCE )
412
+ ) ;
413
+ if ( action && collection ) {
414
+ let actionItems = action . items ;
415
+ let items = [ ] ;
416
+ collection . forEach ( data => {
417
+ let item = actionItems . find ( item => item . molecule . id === data . id && item . datasetID === data . datasetId ) ;
418
+ if ( item ) {
419
+ items . push ( item ) ;
420
+ }
421
+ } ) ;
422
+
423
+ currentActions . push ( Object . assign ( { ...action , items : items } ) ) ;
424
+ }
425
+ } ;
426
+
282
427
const getCollection = dataList => {
283
428
let list = [ ] ;
284
429
if ( dataList ) {
@@ -429,11 +574,11 @@ export const restoreAfterTargetActions = (stages, projectId) => async (dispatch,
429
574
. finally ( ( ) => { } ) ;
430
575
431
576
await dispatch ( restoreSitesActions ( orderedActionList , summaryView ) ) ;
432
- await dispatch ( loadAllMolecules ( orderedActionList , targetId , majorView . stage ) ) ;
433
- await dispatch ( loadAllDatasets ( orderedActionList , targetId , majorView . stage ) ) ;
577
+ await dispatch ( loadData ( orderedActionList , targetId , majorView ) ) ;
578
+ await dispatch ( restoreActions ( orderedActionList , majorView . stage ) ) ;
434
579
await dispatch ( restoreRepresentationActions ( orderedActionList , stages ) ) ;
435
580
await dispatch ( restoreProject ( projectId ) ) ;
436
- dispatch ( restoreNglStateAction ( orderedActionList , stages ) ) ;
581
+ await dispatch ( restoreNglStateAction ( orderedActionList , stages ) ) ;
437
582
dispatch ( setIsActionsRestoring ( false , true ) ) ;
438
583
}
439
584
} ;
@@ -451,21 +596,23 @@ const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState
451
596
}
452
597
} ;
453
598
599
+ const restoreActions = ( orderedActionList , stage ) => ( dispatch , getState ) => {
600
+ dispatch ( restoreMoleculesActions ( orderedActionList , stage ) ) ;
601
+ } ;
602
+
603
+ const loadData = ( orderedActionList , targetId , majorView ) => async ( dispatch , getState ) => {
604
+ await dispatch ( loadAllMolecules ( orderedActionList , targetId , majorView . stage ) ) ;
605
+ await dispatch ( loadAllDatasets ( orderedActionList , targetId , majorView . stage ) ) ;
606
+ } ;
607
+
454
608
const loadAllDatasets = ( orderedActionList , target_on , stage ) => async ( dispatch , getState ) => {
455
609
dispatch ( setMoleculeListIsLoading ( true ) ) ;
456
- await dispatch ( loadDataSets ( target_on ) )
457
- . then ( results => {
458
- return dispatch ( loadDatasetCompoundsWithScores ( ) ) ;
459
- } )
460
- . catch ( error => {
461
- throw new Error ( error ) ;
462
- } )
463
- . finally ( ( ) => {
464
- dispatch ( restoreCompoundsActions ( orderedActionList , stage ) ) ;
465
- dispatch ( setMoleculeListIsLoading ( false ) ) ;
466
- dispatch ( restoreAllSelectionActions ( orderedActionList , stage , false ) ) ;
467
- dispatch ( setIsTrackingCompoundsRestoring ( false ) ) ;
468
- } ) ;
610
+
611
+ await dispatch ( loadDataSets ( target_on ) ) ;
612
+ await dispatch ( loadDatasetCompoundsWithScores ( ) ) ;
613
+ dispatch ( setMoleculeListIsLoading ( false ) ) ;
614
+
615
+ dispatch ( restoreCompoundsActions ( orderedActionList , stage ) ) ;
469
616
} ;
470
617
471
618
const loadAllMolecules = ( orderedActionList , target_on , stage ) => async ( dispatch , getState ) => {
@@ -492,8 +639,6 @@ const loadAllMolecules = (orderedActionList, target_on, stage) => async (dispatc
492
639
listToSet [ molResult . mol_group ] = molResult . molecules ;
493
640
} ) ;
494
641
dispatch ( setAllMolLists ( listToSet ) ) ;
495
- dispatch ( restoreMoleculesActions ( orderedActionList , stage ) ) ;
496
- dispatch ( setIsTrackingMoleculesRestoring ( false ) ) ;
497
642
} catch ( error ) {
498
643
throw new Error ( error ) ;
499
644
}
@@ -534,6 +679,8 @@ const restoreMoleculesActions = (orderedActionList, stage) => (dispatch, getStat
534
679
535
680
dispatch ( restoreCartActions ( moleculesAction ) ) ;
536
681
dispatch ( restoreAllSelectionActions ( orderedActionList , stage , true ) ) ;
682
+ dispatch ( restoreAllSelectionByTypeActions ( orderedActionList , stage , true ) ) ;
683
+ dispatch ( setIsTrackingMoleculesRestoring ( false ) ) ;
537
684
} ;
538
685
539
686
const restoreCartActions = moleculesAction => ( dispatch , getState ) => {
@@ -570,6 +717,14 @@ const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dis
570
717
if ( actions ) {
571
718
actions . forEach ( action => {
572
719
if ( action ) {
720
+ if ( isSelection ) {
721
+ dispatch ( setSelectedAll ( action . item , action . isLigand , action . isProtein , action . isComplex ) ) ;
722
+ } else {
723
+ dispatch (
724
+ setSelectedAllOfDataset ( action . dataset_id , action . item , action . isLigand , action . isProtein , action . isComplex )
725
+ ) ;
726
+ }
727
+
573
728
if ( action . isLigand ) {
574
729
dispatch ( handleMoleculeAction ( action , 'ligand' , true , stage , state , true ) ) ;
575
730
}
@@ -586,6 +741,70 @@ const restoreAllSelectionActions = (moleculesAction, stage, isSelection) => (dis
586
741
}
587
742
} ;
588
743
744
+ const restoreAllSelectionByTypeActions = ( moleculesAction , stage , isSelection ) => ( dispatch , getState ) => {
745
+ let state = getState ( ) ;
746
+
747
+ let actions =
748
+ isSelection === true
749
+ ? moleculesAction . filter (
750
+ action =>
751
+ action . type === actionType . ALL_TURNED_ON_BY_TYPE &&
752
+ ( action . object_type === actionObjectType . INSPIRATION || action . object_type === actionObjectType . MOLECULE )
753
+ )
754
+ : moleculesAction . filter (
755
+ action =>
756
+ action . type === actionType . ALL_TURNED_ON_BY_TYPE &&
757
+ ( action . object_type === actionObjectType . CROSS_REFERENCE ||
758
+ action . object_type === actionObjectType . COMPOUND )
759
+ ) ;
760
+
761
+ if ( actions ) {
762
+ actions . forEach ( action => {
763
+ if ( action ) {
764
+ let actionItems = action . items ;
765
+ let type = action . control_type ;
766
+
767
+ if ( isSelection ) {
768
+ dispatch ( setSelectedAllByType ( type , actionItems , action . object_type === actionObjectType . INSPIRATION ) ) ;
769
+
770
+ actionItems . forEach ( data => {
771
+ if ( data ) {
772
+ if ( type === 'ligand' ) {
773
+ dispatch ( addType [ type ] ( stage , data , colourList [ data . id % colourList . length ] , true , true ) ) ;
774
+ } else {
775
+ dispatch ( addType [ type ] ( stage , data , colourList [ data . id % colourList . length ] , true ) ) ;
776
+ }
777
+ }
778
+ } ) ;
779
+ } else {
780
+ dispatch (
781
+ setSelectedAllByTypeOfDataset (
782
+ type ,
783
+ action . dataset_id ,
784
+ actionItems ,
785
+ action . object_type === actionObjectType . CROSS_REFERENCE
786
+ )
787
+ ) ;
788
+
789
+ actionItems . forEach ( data => {
790
+ if ( data && data . molecule ) {
791
+ dispatch (
792
+ addTypeCompound [ type ] (
793
+ stage ,
794
+ data . molecule ,
795
+ colourList [ data . molecule . id % colourList . length ] ,
796
+ data . datasetID ,
797
+ true
798
+ )
799
+ ) ;
800
+ }
801
+ } ) ;
802
+ }
803
+ }
804
+ } ) ;
805
+ }
806
+ } ;
807
+
589
808
const restoreRepresentationActions = ( moleculesAction , stages ) => ( dispatch , getState ) => {
590
809
const nglView = stages . find ( view => view . id === VIEWS . MAJOR_VIEW ) ;
591
810
@@ -650,6 +869,10 @@ const restoreCompoundsActions = (orderedActionList, stage) => (dispatch, getStat
650
869
dispatch ( appendMoleculeToCompoundsOfDatasetToBuy ( action . dataset_id , data . id , data . name ) ) ;
651
870
}
652
871
} ) ;
872
+
873
+ dispatch ( restoreAllSelectionActions ( orderedActionList , stage , false ) ) ;
874
+ dispatch ( restoreAllSelectionByTypeActions ( orderedActionList , stage , false ) ) ;
875
+ dispatch ( setIsTrackingCompoundsRestoring ( false ) ) ;
653
876
} ;
654
877
655
878
const addType = {
@@ -758,7 +981,9 @@ const getCompound = (action, state) => {
758
981
759
982
if ( moleculeList ) {
760
983
let moleculeListOfDataset = moleculeList [ datasetID ] ;
761
- molecule = moleculeListOfDataset . find ( m => m . name === name ) ;
984
+ if ( moleculeListOfDataset ) {
985
+ molecule = moleculeListOfDataset . find ( m => m . name === name ) ;
986
+ }
762
987
}
763
988
return molecule ;
764
989
} ;
@@ -1042,7 +1267,13 @@ const handleAllActionByType = (action, isAdd, stage) => (dispatch, getState) =>
1042
1267
actionItems . forEach ( data => {
1043
1268
if ( data && data . molecule ) {
1044
1269
dispatch (
1045
- addTypeCompound [ type ] ( stage , data . molecule , colourList [ data . id % colourList . length ] , data . datasetID , true )
1270
+ addTypeCompound [ type ] (
1271
+ stage ,
1272
+ data . molecule ,
1273
+ colourList [ data . molecule . id % colourList . length ] ,
1274
+ data . datasetID ,
1275
+ true
1276
+ )
1046
1277
) ;
1047
1278
}
1048
1279
} ) ;
@@ -1062,7 +1293,7 @@ const handleAllActionByType = (action, isAdd, stage) => (dispatch, getState) =>
1062
1293
removeTypeCompound [ type ] (
1063
1294
stage ,
1064
1295
data . molecule ,
1065
- colourList [ data . id % colourList . length ] ,
1296
+ colourList [ data . molecule . id % colourList . length ] ,
1066
1297
data . datasetID ,
1067
1298
true
1068
1299
)
0 commit comments