@@ -43,7 +43,8 @@ import {
43
43
removeFromMolListToEdit ,
44
44
setOpenObservationsDialog ,
45
45
setObservationsForLHSCmp ,
46
- setIsLHSCmpTagEdit
46
+ setIsLHSCmpTagEdit ,
47
+ setPoseIdForObservationsDialog
47
48
} from '../../../../reducers/selection/actions' ;
48
49
import { moleculeProperty } from '../helperConstants' ;
49
50
import { centerOnLigandByMoleculeID } from '../../../../reducers/ngl/dispatchActions' ;
@@ -387,15 +388,23 @@ const ObservationCmpView = memo(
387
388
const { getNglView } = useContext ( NglContext ) ;
388
389
const stage = getNglView ( VIEWS . MAJOR_VIEW ) && getNglView ( VIEWS . MAJOR_VIEW ) . stage ;
389
390
390
- const getFirstObservation = useCallback ( ( ) => {
391
+ const poseIdForObservationsDialog = useSelector ( state => state . selectionReducers . poseIdForObservationsDialog ) ;
392
+
393
+ useEffect ( ( ) => {
394
+ if ( isObservationDialogOpen && poseIdForObservationsDialog === currentID ) {
395
+ dispatch ( setObservationsForLHSCmp ( observations ) ) ;
396
+ }
397
+ } , [ observations , isObservationDialogOpen , dispatch , poseIdForObservationsDialog , currentID ] ) ;
398
+
399
+ const getMainObservation = useCallback ( ( ) => {
391
400
let result = null ;
392
401
393
- if ( observations && observations . length > 0 ) {
394
- result = observations [ 0 ] ;
402
+ if ( observations && observations . length > 0 && data . main_site_observation ) {
403
+ result = observations . find ( o => o . id === data . main_site_observation ) ;
395
404
}
396
405
397
406
return result ;
398
- } , [ observations ] ) ;
407
+ } , [ data , observations ] ) ;
399
408
400
409
const getAllObservationsSelectedInList = list => {
401
410
let result = [ ] ;
@@ -481,7 +490,7 @@ const ObservationCmpView = memo(
481
490
const disableMoleculeNglControlButtons =
482
491
useSelector ( state => state . previewReducers . molecule . disableNglControlButtons [ currentID ] ) || { } ;
483
492
484
- const colourToggle = getRandomColor ( getFirstObservation ( ) ) ;
493
+ const colourToggle = getRandomColor ( getMainObservation ( ) ) ;
485
494
486
495
const getCalculatedProps = useCallback (
487
496
( ) => [
@@ -808,11 +817,11 @@ const ObservationCmpView = memo(
808
817
809
818
// componentDidMount
810
819
useEffect ( ( ) => {
811
- const obs = getFirstObservation ( ) ;
820
+ const obs = getMainObservation ( ) ;
812
821
dispatch ( getMolImage ( obs . id , MOL_TYPE . HIT , imageWidth , imageHeight ) ) . then ( i => {
813
822
setImg_data ( i ) ;
814
823
} ) ;
815
- } , [ data . id , data . smiles , imageHeight , imageWidth , dispatch , getFirstObservation ] ) ;
824
+ } , [ data . id , data . smiles , imageHeight , imageWidth , dispatch , getMainObservation ] ) ;
816
825
817
826
useEffect ( ( ) => {
818
827
dispatch ( getQualityInformation ( data ) ) ;
@@ -846,7 +855,7 @@ const ObservationCmpView = memo(
846
855
// }
847
856
dispatch (
848
857
withDisabledMoleculeNglControlButton ( currentID , 'ligand' , async ( ) => {
849
- const firstObs = getFirstObservation ( ) ;
858
+ const firstObs = getMainObservation ( ) ;
850
859
if ( firstObs ) {
851
860
const color = getRandomColor ( firstObs ) ;
852
861
await dispatch ( addLigand ( stage , firstObs , color , false , true , skipTracking ) ) ;
@@ -898,7 +907,7 @@ const ObservationCmpView = memo(
898
907
// }
899
908
dispatch (
900
909
withDisabledMoleculeNglControlButton ( currentID , 'protein' , async ( ) => {
901
- const firstObs = getFirstObservation ( ) ;
910
+ const firstObs = getMainObservation ( ) ;
902
911
if ( firstObs ) {
903
912
const color = getRandomColor ( firstObs ) ;
904
913
await dispatch ( addHitProtein ( stage , firstObs , color , true , skipTracking ) ) ;
@@ -938,7 +947,7 @@ const ObservationCmpView = memo(
938
947
const addNewComplex = ( skipTracking = false ) => {
939
948
dispatch (
940
949
withDisabledMoleculeNglControlButton ( currentID , 'complex' , async ( ) => {
941
- const firstObs = getFirstObservation ( ) ;
950
+ const firstObs = getMainObservation ( ) ;
942
951
if ( firstObs ) {
943
952
const color = getRandomColor ( firstObs ) ;
944
953
await dispatch ( addComplex ( stage , firstObs , color , skipTracking ) ) ;
@@ -977,7 +986,7 @@ const ObservationCmpView = memo(
977
986
const addNewSurface = ( ) => {
978
987
dispatch (
979
988
withDisabledMoleculeNglControlButton ( currentID , 'surface' , async ( ) => {
980
- const firstObs = getFirstObservation ( ) ;
989
+ const firstObs = getMainObservation ( ) ;
981
990
if ( firstObs ) {
982
991
const color = getRandomColor ( firstObs ) ;
983
992
await dispatch ( addSurface ( stage , firstObs , color ) ) ;
@@ -1056,7 +1065,7 @@ const ObservationCmpView = memo(
1056
1065
const addNewQuality = ( ) => {
1057
1066
dispatch (
1058
1067
withDisabledMoleculeNglControlButton ( currentID , 'ligand' , async ( ) => {
1059
- const firstObs = getFirstObservation ( ) ;
1068
+ const firstObs = getMainObservation ( ) ;
1060
1069
if ( firstObs ) {
1061
1070
const color = getRandomColor ( firstObs ) ;
1062
1071
await dispatch ( addQuality ( stage , firstObs , color ) ) ;
@@ -1083,7 +1092,7 @@ const ObservationCmpView = memo(
1083
1092
const addNewVector = ( ) => {
1084
1093
dispatch (
1085
1094
withDisabledMoleculeNglControlButton ( currentID , 'vector' , async ( ) => {
1086
- const firstObs = getFirstObservation ( ) ;
1095
+ const firstObs = getMainObservation ( ) ;
1087
1096
if ( firstObs ) {
1088
1097
await dispatch ( addVector ( stage , firstObs ) ) ;
1089
1098
}
@@ -1185,7 +1194,8 @@ const ObservationCmpView = memo(
1185
1194
const result = e . target . checked ;
1186
1195
if ( result ) {
1187
1196
if ( observations ?. length > 0 ) {
1188
- dispatch ( appendToMolListToEdit ( observations [ 0 ] . id ) ) ;
1197
+ const mainObs = getMainObservation ( ) ;
1198
+ mainObs && dispatch ( appendToMolListToEdit ( mainObs . id ) ) ;
1189
1199
}
1190
1200
// dispatch(appendToObsCmpListToEdit(currentID));
1191
1201
} else {
@@ -1233,7 +1243,7 @@ const ObservationCmpView = memo(
1233
1243
variant = "outlined"
1234
1244
className = { classes . myLocationButton }
1235
1245
onClick = { ( ) => {
1236
- dispatch ( centerOnLigandByMoleculeID ( stage , getFirstObservation ( ) ?. id ) ) ;
1246
+ dispatch ( centerOnLigandByMoleculeID ( stage , getMainObservation ( ) ?. id ) ) ;
1237
1247
} }
1238
1248
disabled = { false || ! isLigandOn }
1239
1249
>
@@ -1427,6 +1437,7 @@ const ObservationCmpView = memo(
1427
1437
dispatch ( setObservationsForLHSCmp ( observations ) ) ;
1428
1438
}
1429
1439
dispatch ( setOpenObservationsDialog ( ! isObservationDialogOpen ) ) ;
1440
+ dispatch ( setPoseIdForObservationsDialog ( data . id ) ) ;
1430
1441
1431
1442
if ( setRef ) {
1432
1443
setRef ( ref . current ) ;
0 commit comments