@@ -14,7 +14,8 @@ import {
14
14
TextField ,
15
15
Checkbox ,
16
16
InputAdornment ,
17
- setRef
17
+ setRef ,
18
+ Box
18
19
} from '@material-ui/core' ;
19
20
import React , { useState , useEffect , memo , useRef , useContext , useCallback , useMemo } from 'react' ;
20
21
import { useDispatch , useSelector , shallowEqual } from 'react-redux' ;
@@ -52,7 +53,11 @@ import {
52
53
setIsOpenLockVisibleCompoundsDialogGlobal ,
53
54
setSearchStringOfCompoundSet ,
54
55
setCompoundToSelectedCompoundsByDataset ,
55
- setSelectAllButtonForDataset
56
+ setSelectAllButtonForDataset ,
57
+ appendCompoundColorOfDataset ,
58
+ appendColorToAllCompoundsOfDataset ,
59
+ removeCompoundColorOfDataset ,
60
+ removeColorFromAllCompoundsOfDataset
56
61
} from './redux/actions' ;
57
62
import { DatasetFilter } from './datasetFilter' ;
58
63
import { FilterList , Link , DeleteForever , ArrowUpward , ArrowDownward , Edit } from '@material-ui/icons' ;
@@ -79,6 +84,7 @@ import {
79
84
onStartEditColorClassName
80
85
} from '../preview/compounds/redux/dispatchActions' ;
81
86
import { LockVisibleCompoundsDialog } from './lockVisibleCompoundsDialog' ;
87
+ import { size } from 'lodash' ;
82
88
83
89
const useStyles = makeStyles ( theme => ( {
84
90
container : {
@@ -163,6 +169,26 @@ const useStyles = makeStyles(theme => ({
163
169
contButtonsMargin : {
164
170
margin : theme . spacing ( 1 ) / 2
165
171
} ,
172
+ paintAllButton : {
173
+ minWidth : 'fit-content' ,
174
+ paddingLeft : theme . spacing ( 1 ) / 4 ,
175
+ paddingRight : theme . spacing ( 1 ) / 4 ,
176
+ paddingBottom : 0 ,
177
+ paddingTop : 0 ,
178
+ fontWeight : 'bold' ,
179
+ fontSize : 9 ,
180
+ borderRadius : 0 ,
181
+ borderColor : theme . palette . primary . main ,
182
+ backgroundColor : 'white' ,
183
+ '&:hover' : {
184
+ backgroundColor : 'white'
185
+ // color: theme.palette.primary.contrastText
186
+ } ,
187
+ '&:disabled' : {
188
+ borderRadius : 0 ,
189
+ borderColor : 'white'
190
+ }
191
+ } ,
166
192
contColButton : {
167
193
minWidth : 'fit-content' ,
168
194
paddingLeft : theme . spacing ( 1 ) / 4 ,
@@ -808,6 +834,39 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
808
834
}
809
835
} ;
810
836
837
+ const isPaintOrUnpaintAll = ( ) => {
838
+ let isPaint = true ;
839
+ const compounds = Object . keys ( compoundColors ) ;
840
+ for ( let i = 0 ; i < compounds . length ; i ++ ) {
841
+ const cmpId = compounds [ i ] ;
842
+ const colors = compoundColors [ cmpId ] ;
843
+ if ( colors . some ( c => c === currentCompoundClass ) ) {
844
+ isPaint = false ;
845
+ break ;
846
+ }
847
+ }
848
+
849
+ return isPaint ;
850
+ } ;
851
+
852
+ const paintAllCompounds = ( ) => {
853
+ const paintAll = isPaintOrUnpaintAll ( ) ;
854
+ const cmpIds = joinedMoleculeLists . map ( mol => mol . id ) ;
855
+ if ( paintAll ) {
856
+ joinedMoleculeLists . forEach ( molecule => {
857
+ const molName = molecule . name ;
858
+ dispatch ( appendCompoundColorOfDataset ( datasetID , molecule . id , currentCompoundClass , molName , true ) ) ;
859
+ } ) ;
860
+ dispatch ( appendColorToAllCompoundsOfDataset ( datasetID , currentCompoundClass , cmpIds ) ) ;
861
+ } else {
862
+ joinedMoleculeLists . forEach ( molecule => {
863
+ const molName = molecule . name ;
864
+ dispatch ( removeCompoundColorOfDataset ( datasetID , molecule . id , currentCompoundClass , molName , true ) ) ;
865
+ } ) ;
866
+ dispatch ( removeColorFromAllCompoundsOfDataset ( datasetID , currentCompoundClass , cmpIds ) ) ;
867
+ }
868
+ } ;
869
+
811
870
return (
812
871
< Panel hasHeader title = { title } withTooltip headerActions = { actions } >
813
872
< AlertModal
@@ -1082,25 +1141,53 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
1082
1141
</ Grid >
1083
1142
</ Grid >
1084
1143
< Grid item >
1085
- {
1086
- < Tooltip title = { selectAllPressed ? 'Unselect all' : 'Select all' } >
1087
- < Grid item style = { { margin : '4px' , marginLeft : '5px' } } >
1088
- < Button
1089
- variant = "outlined"
1090
- className = { classNames ( classes . contColButton , {
1091
- [ classes . contColButtonHalfSelected ] : false
1092
- } ) }
1093
- onClick = { ( ) => {
1094
- dispatch ( setSelectAllButtonForDataset ( ! selectAllPressed ) ) ;
1095
- selectAllDatasetMolecule ( ! selectAllPressed ) ;
1144
+ < Tooltip title = { selectAllPressed ? 'Unselect all' : 'Select all' } >
1145
+ < Grid item style = { { margin : '4px' , marginLeft : '5px' } } >
1146
+ < Button
1147
+ variant = "outlined"
1148
+ className = { classNames ( classes . contColButton , {
1149
+ [ classes . contColButtonHalfSelected ] : false
1150
+ } ) }
1151
+ onClick = { ( ) => {
1152
+ dispatch ( setSelectAllButtonForDataset ( ! selectAllPressed ) ) ;
1153
+ selectAllDatasetMolecule ( ! selectAllPressed ) ;
1154
+ } }
1155
+ disabled = { false }
1156
+ >
1157
+ { selectAllPressed ? 'Unselect all' : 'Select all' }
1158
+ </ Button >
1159
+ </ Grid >
1160
+ </ Tooltip >
1161
+ </ Grid >
1162
+ < Grid item >
1163
+ < Tooltip
1164
+ title = {
1165
+ isPaintOrUnpaintAll ( )
1166
+ ? 'Paint all compounds with selected color'
1167
+ : 'Unpaint all compounds with selected color'
1168
+ }
1169
+ >
1170
+ < Grid item style = { { margin : '4px' , marginLeft : '5px' } } >
1171
+ < Button
1172
+ variant = "outlined"
1173
+ className = { classNames ( classes . paintAllButton ) }
1174
+ disabled = { false }
1175
+ onClick = { ( ) => paintAllCompounds ( ) }
1176
+ >
1177
+ < Box
1178
+ style = { {
1179
+ width : '10px' ,
1180
+ height : '10px' ,
1181
+ backgroundColor : compoundsColors [ currentCompoundClass ]
1182
+ ? compoundsColors [ currentCompoundClass ] . color
1183
+ : '#000000' ,
1184
+ marginRight : '2px'
1096
1185
} }
1097
- disabled = { false }
1098
- >
1099
- { selectAllPressed ? 'Unselect all' : 'Select all' }
1100
- </ Button >
1101
- </ Grid >
1102
- </ Tooltip >
1103
- }
1186
+ />
1187
+ { isPaintOrUnpaintAll ( ) ? 'Paint all' : 'Unpaint all' }
1188
+ </ Button >
1189
+ </ Grid >
1190
+ </ Tooltip >
1104
1191
</ Grid >
1105
1192
</ Grid >
1106
1193
</ Grid >
0 commit comments