3
3
*/
4
4
import React , { useEffect , memo , useState , useCallback } from 'react' ;
5
5
import { useDispatch , useSelector } from 'react-redux' ;
6
- import { clearDatasetSettings , initializeDatasetFilter } from './redux/dispatchActions' ;
6
+ import { clearDatasetSettings , getInspirationsForMol , initializeDatasetFilter } from './redux/dispatchActions' ;
7
7
import { setExpandCompoundSets , setDataset , setSelectedDatasetIndex , setUpdatedDatasets } from './redux/actions' ;
8
8
import DatasetMoleculeList from './datasetMoleculeList' ;
9
9
import { makeStyles , Table , TableBody , TableCell , TableHead , TableRow , Tooltip } from '@material-ui/core' ;
@@ -13,6 +13,7 @@ import CloudDownloadOutlinedIcon from '@mui/icons-material/CloudDownloadOutlined
13
13
import SearchField from '../common/Components/SearchField' ;
14
14
import { base_url } from '../routes/constants' ;
15
15
import { METHOD , api } from '../../utils/api' ;
16
+ import { compoundsColors } from '../preview/compounds/redux/constants' ;
16
17
17
18
const useStyles = makeStyles ( theme => ( {
18
19
table : {
@@ -63,6 +64,23 @@ export const CompoundSetList = () => {
63
64
const scoreDatasetMap = useSelector ( state => state . datasetsReducers . scoreDatasetMap ) ;
64
65
const moleculeLists = useSelector ( state => state . datasetsReducers . moleculeLists ) ;
65
66
67
+ const allInspirations = useSelector ( state => state . datasetsReducers . allInspirations ) ;
68
+ const compoundColors = useSelector ( state => state . datasetsReducers . compoundColorByDataset ) ;
69
+
70
+ const blueInput = useSelector ( state => state . previewReducers . compounds [ compoundsColors . blue . key ] ) ;
71
+ const redInput = useSelector ( state => state . previewReducers . compounds [ compoundsColors . red . key ] ) ;
72
+ const greenInput = useSelector ( state => state . previewReducers . compounds [ compoundsColors . green . key ] ) ;
73
+ const purpleInput = useSelector ( state => state . previewReducers . compounds [ compoundsColors . purple . key ] ) ;
74
+ const apricotInput = useSelector ( state => state . previewReducers . compounds [ compoundsColors . apricot . key ] ) ;
75
+
76
+ const inputs = {
77
+ [ compoundsColors . blue . key ] : blueInput ,
78
+ [ compoundsColors . red . key ] : redInput ,
79
+ [ compoundsColors . green . key ] : greenInput ,
80
+ [ compoundsColors . purple . key ] : purpleInput ,
81
+ [ compoundsColors . apricot . key ] : apricotInput
82
+ } ;
83
+
66
84
const [ isExpanded , setIsExpanded ] = useState ( false ) ;
67
85
const [ searchString , setSearchString ] = useState ( null ) ;
68
86
const [ defaultSelectedValue , setDefaultSelectedValue ] = useState ( ) ;
@@ -74,13 +92,20 @@ export const CompoundSetList = () => {
74
92
* @param {* } scoreName
75
93
* @returns {string }
76
94
*/
77
- const getCommonScore = useCallback ( ( datasetID , scoreName ) => {
78
- let value = '' ;
79
- if ( datasetID && scoreDatasetMap . hasOwnProperty ( datasetID ) && scoreDatasetMap [ datasetID ] . hasOwnProperty ( scoreName ) ) {
80
- value = scoreDatasetMap [ datasetID ] [ scoreName ] . description ;
81
- }
82
- return value ;
83
- } , [ scoreDatasetMap ] ) ;
95
+ const getCommonScore = useCallback (
96
+ ( datasetID , scoreName ) => {
97
+ let value = '' ;
98
+ if (
99
+ datasetID &&
100
+ scoreDatasetMap . hasOwnProperty ( datasetID ) &&
101
+ scoreDatasetMap [ datasetID ] . hasOwnProperty ( scoreName )
102
+ ) {
103
+ value = scoreDatasetMap [ datasetID ] [ scoreName ] . description ;
104
+ }
105
+ return value ;
106
+ } ,
107
+ [ scoreDatasetMap ]
108
+ ) ;
84
109
85
110
/**
86
111
* Download molecule list of given dataset as CSV file
@@ -91,12 +116,81 @@ export const CompoundSetList = () => {
91
116
const listOfMols = [ ] ;
92
117
const moleculeList = moleculeLists [ datasetID ] || [ ] ;
93
118
119
+ let maxNumOfInspirations = 0 ;
120
+ moleculeList . forEach ( cmp => {
121
+ const inspirations = getInspirationsForMol ( allInspirations , datasetID , cmp . id ) ;
122
+ if ( inspirations ?. length > maxNumOfInspirations ) {
123
+ maxNumOfInspirations = inspirations . length ;
124
+ }
125
+ } ) ;
126
+
127
+ let colorsTemplate = { } ;
128
+ moleculeList . forEach ( compound => {
129
+ let shoppingCartColors = [ ] ;
130
+ const cmpColorsForDataset = compoundColors [ datasetID ] ;
131
+ if ( cmpColorsForDataset ) {
132
+ shoppingCartColors = cmpColorsForDataset [ compound . id ] ;
133
+ shoppingCartColors . forEach ( color => {
134
+ if ( ! colorsTemplate . hasOwnProperty ( color ) ) {
135
+ colorsTemplate [ color ] = '' ;
136
+ if ( inputs . hasOwnProperty ( color ) && inputs [ color ] ) {
137
+ colorsTemplate [ `${ color } -text` ] = inputs [ color ] ;
138
+ }
139
+ }
140
+ } ) ;
141
+ }
142
+ } ) ;
143
+
94
144
moleculeList . forEach ( molecule => {
95
145
let molObj = { } ;
96
146
97
147
molObj [ 'smiles' ] = molecule . smiles ;
98
148
molObj [ 'name' ] = molecule . name ;
99
149
150
+ if ( molecule . hasOwnProperty ( 'numerical_scores' ) ) {
151
+ Object . keys ( molecule . numerical_scores ) . forEach ( key => {
152
+ molObj [ key ] = molecule . numerical_scores [ key ] ;
153
+ } ) ;
154
+ }
155
+ if ( molecule . hasOwnProperty ( 'text_scores' ) ) {
156
+ Object . keys ( molecule . text_scores ) . forEach ( key => {
157
+ molObj [ key ] = molecule . text_scores [ key ] ;
158
+ } ) ;
159
+ }
160
+
161
+ if ( maxNumOfInspirations ) {
162
+ const inspirations = getInspirationsForMol ( allInspirations , datasetID , molecule . id ) ;
163
+ for ( let i = 0 ; i < maxNumOfInspirations ; i ++ ) {
164
+ if ( inspirations ?. [ i ] ) {
165
+ molObj [ `inspiration_${ i + 1 } ` ] = inspirations [ i ] . code ;
166
+ } else {
167
+ molObj [ `inspiration_${ i + 1 } ` ] = '' ;
168
+ }
169
+ }
170
+ }
171
+
172
+ let shoppingCartColors = [ ] ;
173
+
174
+ const cmpColorsForDataset = compoundColors [ datasetID ] ;
175
+ if ( cmpColorsForDataset ) {
176
+ shoppingCartColors = cmpColorsForDataset [ molecule . id ] ;
177
+ let colorsTemplateCopy = { ...colorsTemplate } ;
178
+ shoppingCartColors . forEach ( color => {
179
+ colorsTemplateCopy [ color ] = true ;
180
+ } ) ;
181
+
182
+ Object . keys ( colorsTemplateCopy )
183
+ . filter ( key => key . includes ( '-text' ) )
184
+ . forEach ( key => {
185
+ const color = key . split ( '-' ) [ 0 ] ;
186
+ if ( colorsTemplateCopy . hasOwnProperty ( color ) && ! colorsTemplateCopy [ color ] ) {
187
+ colorsTemplateCopy [ key ] = '' ;
188
+ }
189
+ } ) ;
190
+
191
+ molObj = { ...molObj , ...colorsTemplateCopy } ;
192
+ }
193
+
100
194
listOfMols . push ( molObj ) ;
101
195
} ) ;
102
196
@@ -118,7 +212,9 @@ export const CompoundSetList = () => {
118
212
119
213
useEffect ( ( ) => {
120
214
if ( selectedDatasetIndex === 0 ) {
121
- const filteredDataset = searchString ? customDatasets . filter ( dataset => dataset . title . toLowerCase ( ) . includes ( searchString . toLowerCase ( ) ) ) : customDatasets ;
215
+ const filteredDataset = searchString
216
+ ? customDatasets . filter ( dataset => dataset . title . toLowerCase ( ) . includes ( searchString . toLowerCase ( ) ) )
217
+ : customDatasets ;
122
218
const newDataset = filteredDataset . map ( ( dataSet , index ) =>
123
219
index === 0 ? { ...dataSet , visibility : true } : { ...dataSet , visibility : false }
124
220
) ;
@@ -138,7 +234,9 @@ export const CompoundSetList = () => {
138
234
} ;
139
235
140
236
const handleChangeVisibility = index => {
141
- const filteredDataset = searchString ? customDatasets . filter ( dataset => dataset . title . toLowerCase ( ) . includes ( searchString . toLowerCase ( ) ) ) : customDatasets ;
237
+ const filteredDataset = searchString
238
+ ? customDatasets . filter ( dataset => dataset . title . toLowerCase ( ) . includes ( searchString . toLowerCase ( ) ) )
239
+ : customDatasets ;
142
240
const newDataset = filteredDataset . map ( ( dataSetValue , i ) =>
143
241
i === index ? { ...dataSetValue , visibility : true } : { ...dataSetValue , visibility : false }
144
242
) ;
@@ -171,30 +269,14 @@ export const CompoundSetList = () => {
171
269
< Table className = { classes . table } >
172
270
< TableHead >
173
271
< TableRow style = { { padding : 0 } } >
174
- < TableCell style = { { width : 25 , padding : 0 } } >
175
- { /* Select */ }
176
- </ TableCell >
177
- < TableCell style = { { width : 60 , padding : 0 } } >
178
- Name
179
- </ TableCell >
180
- < TableCell style = { { width : 15 , padding : 0 } } >
181
- #
182
- </ TableCell >
183
- < TableCell style = { { width : 70 , padding : 0 } } >
184
- Submitter
185
- </ TableCell >
186
- < TableCell style = { { width : 55 , padding : 0 } } >
187
- Institution
188
- </ TableCell >
189
- < TableCell style = { { width : 60 , padding : 0 } } >
190
- Date
191
- </ TableCell >
192
- < TableCell style = { { width : 70 , padding : 0 } } >
193
- Method
194
- </ TableCell >
195
- < TableCell style = { { width : 30 , padding : 0 } } >
196
- CSV
197
- </ TableCell >
272
+ < TableCell style = { { width : 25 , padding : 0 } } > { /* Select */ } </ TableCell >
273
+ < TableCell style = { { width : 60 , padding : 0 } } > Name</ TableCell >
274
+ < TableCell style = { { width : 15 , padding : 0 } } > #</ TableCell >
275
+ < TableCell style = { { width : 70 , padding : 0 } } > Submitter</ TableCell >
276
+ < TableCell style = { { width : 55 , padding : 0 } } > Institution</ TableCell >
277
+ < TableCell style = { { width : 60 , padding : 0 } } > Date</ TableCell >
278
+ < TableCell style = { { width : 70 , padding : 0 } } > Method</ TableCell >
279
+ < TableCell style = { { width : 30 , padding : 0 } } > CSV</ TableCell >
198
280
</ TableRow >
199
281
</ TableHead >
200
282
< TableBody >
@@ -220,23 +302,36 @@ export const CompoundSetList = () => {
220
302
</ TableCell >
221
303
</ Tooltip >
222
304
< Tooltip title = "Number of compounds" >
223
- < TableCell className = { classes . tableCell } style = { { maxWidth : 15 } } > { moleculeList . length } </ TableCell >
305
+ < TableCell className = { classes . tableCell } style = { { maxWidth : 15 } } >
306
+ { moleculeList . length }
307
+ </ TableCell >
224
308
</ Tooltip >
225
309
< Tooltip title = { getCommonScore ( dataset . id , 'submitter_name' ) } >
226
- < TableCell className = { classes . tableCell } style = { { maxWidth : 100 } } > { getCommonScore ( dataset . id , 'submitter_name' ) } </ TableCell >
310
+ < TableCell className = { classes . tableCell } style = { { maxWidth : 100 } } >
311
+ { getCommonScore ( dataset . id , 'submitter_name' ) }
312
+ </ TableCell >
227
313
</ Tooltip >
228
314
< Tooltip title = { getCommonScore ( dataset . id , 'submitter_institution' ) } >
229
- < TableCell className = { classes . tableCell } style = { { maxWidth : 70 } } > { getCommonScore ( dataset . id , 'submitter_institution' ) } </ TableCell >
315
+ < TableCell className = { classes . tableCell } style = { { maxWidth : 70 } } >
316
+ { getCommonScore ( dataset . id , 'submitter_institution' ) }
317
+ </ TableCell >
230
318
</ Tooltip >
231
319
< Tooltip title = { getCommonScore ( dataset . id , 'generation_date' ) } >
232
- < TableCell className = { classes . tableCell } style = { { maxWidth : 60 } } > { getCommonScore ( dataset . id , 'generation_date' ) } </ TableCell >
320
+ < TableCell className = { classes . tableCell } style = { { maxWidth : 60 } } >
321
+ { getCommonScore ( dataset . id , 'generation_date' ) }
322
+ </ TableCell >
233
323
</ Tooltip >
234
324
< Tooltip title = { getCommonScore ( dataset . id , 'method' ) } >
235
- < TableCell className = { classes . tableCell } style = { { maxWidth : 150 } } > { getCommonScore ( dataset . id , 'method' ) } </ TableCell >
325
+ < TableCell className = { classes . tableCell } style = { { maxWidth : 150 } } >
326
+ { getCommonScore ( dataset . id , 'method' ) }
327
+ </ TableCell >
236
328
</ Tooltip >
237
329
< TableCell style = { { padding : 0 } } >
238
330
< Tooltip title = "Download as CSV" >
239
- < CloudDownloadOutlinedIcon className = { classes . downloadIcon } onClick = { ( ) => downloadCSV ( dataset . id ) } />
331
+ < CloudDownloadOutlinedIcon
332
+ className = { classes . downloadIcon }
333
+ onClick = { ( ) => downloadCSV ( dataset . id ) }
334
+ />
240
335
</ Tooltip >
241
336
</ TableCell >
242
337
</ TableRow >
0 commit comments