Skip to content

Commit 291a3f7

Browse files
author
Adriána Kohanová
committed
#521 Selected compounds - inconsisten toggles behaviour
1 parent e78af5e commit 291a3f7

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

js/components/datasets/redux/selectors.js

+13
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,16 @@ export const getListOfSelectedComplexOfAllDatasets = state => {
377377

378378
return [...resultSet];
379379
};
380+
381+
export const getListOfSelectedSurfaceOfAllDatasets = state => {
382+
let resultSet = new Set();
383+
const complexesDatasetMap = state.datasetsReducers.surfaceLists;
384+
Object.keys(complexesDatasetMap).forEach(datasetID => {
385+
const currentDatasetArray = complexesDatasetMap[datasetID];
386+
if (currentDatasetArray) {
387+
currentDatasetArray.forEach(moleculeID => resultSet.add(moleculeID));
388+
}
389+
});
390+
391+
return [...resultSet];
392+
};

js/components/datasets/selectedCompoundsList.js

+39-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { Panel } from '../common/Surfaces/Panel';
33
import { CircularProgress, Grid, makeStyles, Typography, Button } from '@material-ui/core';
44
import { CloudDownload } from '@material-ui/icons';
55
import { useDispatch, useSelector } from 'react-redux';
6-
import { getMoleculesObjectIDListOfCompoundsToBuy } from './redux/selectors';
6+
import {
7+
getMoleculesObjectIDListOfCompoundsToBuy,
8+
getListOfSelectedComplexOfAllDatasets,
9+
getListOfSelectedLigandOfAllDatasets,
10+
getListOfSelectedProteinOfAllDatasets,
11+
getListOfSelectedSurfaceOfAllDatasets
12+
} from './redux/selectors';
713
import InfiniteScroll from 'react-infinite-scroller';
814
import { colourList, DatasetMoleculeView } from './datasetMoleculeView';
915
import { InspirationDialog } from './inspirationDialog';
@@ -15,11 +21,10 @@ import {
1521
removeDatasetComplex,
1622
removeDatasetHitProtein,
1723
removeDatasetLigand,
18-
removeDatasetSurface
24+
removeDatasetSurface
1925
} from './redux/dispatchActions';
2026
import { NglContext } from '../nglView/nglProvider';
2127
import { VIEWS } from '../../constants/constants';
22-
import { getMoleculeList } from '../preview/molecule/redux/selectors';
2328
import FileSaver from 'file-saver';
2429
import JSZip from 'jszip';
2530

@@ -52,7 +57,8 @@ export const SelectedCompoundList = memo(({ height }) => {
5257
const moleculesPerPage = 5;
5358
const dispatch = useDispatch();
5459
const [currentPage, setCurrentPage] = useState(0);
55-
const moleculesObjectIDListOfCompoundsToBuy = useSelector(getMoleculesObjectIDListOfCompoundsToBuy); const isOpenInspirationDialog = useSelector(state => state.datasetsReducers.isOpenInspirationDialog);
60+
const moleculesObjectIDListOfCompoundsToBuy = useSelector(getMoleculesObjectIDListOfCompoundsToBuy);
61+
const isOpenInspirationDialog = useSelector(state => state.datasetsReducers.isOpenInspirationDialog);
5662
const isOpenCrossReferenceDialog = useSelector(state => state.datasetsReducers.isOpenCrossReferenceDialog);
5763
const [selectedMoleculeRef, setSelectedMoleculeRef] = useState(null);
5864
const inspirationDialogRef = useRef();
@@ -70,6 +76,11 @@ export const SelectedCompoundList = memo(({ height }) => {
7076
const currentMolecules = moleculesObjectIDListOfCompoundsToBuy.slice(0, listItemOffset);
7177
const canLoadMore = listItemOffset < moleculesObjectIDListOfCompoundsToBuy.length;
7278

79+
const ligandList = useSelector(state => getListOfSelectedLigandOfAllDatasets(state));
80+
const proteinList = useSelector(state => getListOfSelectedProteinOfAllDatasets(state));
81+
const complexList = useSelector(state => getListOfSelectedComplexOfAllDatasets(state));
82+
const surfaceList = useSelector(state => getListOfSelectedSurfaceOfAllDatasets(state));
83+
7384
const ligandListAllDatasets = useSelector(state => state.datasetsReducers.ligandLists);
7485
const proteinListAllDatasets = useSelector(state => state.datasetsReducers.proteinLists);
7586
const complexListAllDatasets = useSelector(state => state.datasetsReducers.complexLists);
@@ -142,7 +153,7 @@ export const SelectedCompoundList = memo(({ height }) => {
142153
moleculesObjectIDListOfCompoundsToBuy.forEach(compound => {
143154
data += `\n${compound.molecule.smiles},${compound.datasetID}`;
144155
});
145-
const dataBlob = new Blob([data], {type: 'text/csv;charset=utf-8'});
156+
const dataBlob = new Blob([data], { type: 'text/csv;charset=utf-8' });
146157

147158
FileSaver.saveAs(dataBlob, 'selectedCompounds.csv');
148159
};
@@ -168,25 +179,25 @@ export const SelectedCompoundList = memo(({ height }) => {
168179
};
169180

170181
return (
171-
<Panel hasHeader title="Selected Compounds" withTooltip headerActions={[
172-
<Button
173-
color="inherit"
174-
variant="text"
175-
onClick={downloadAsCsv}
176-
startIcon={<CloudDownload />}
177-
>
178-
Download CSV
179-
</Button>,
180-
<Button
181-
color="inherit"
182-
variant="text"
183-
className={classes.sdfButton}
184-
onClick={downloadAsSdf}
185-
startIcon={<CloudDownload />}
186-
>
187-
Download SDF
188-
</Button>
189-
]}>
182+
<Panel
183+
hasHeader
184+
title="Selected Compounds"
185+
withTooltip
186+
headerActions={[
187+
<Button color="inherit" variant="text" onClick={downloadAsCsv} startIcon={<CloudDownload />}>
188+
Download CSV
189+
</Button>,
190+
<Button
191+
color="inherit"
192+
variant="text"
193+
className={classes.sdfButton}
194+
onClick={downloadAsSdf}
195+
startIcon={<CloudDownload />}
196+
>
197+
Download SDF
198+
</Button>
199+
]}
200+
>
190201
{isOpenInspirationDialog && (
191202
<InspirationDialog
192203
open
@@ -238,10 +249,10 @@ export const SelectedCompoundList = memo(({ height }) => {
238249
previousItemData={index > 0 && array[index - 1]}
239250
nextItemData={index < array?.length && array[index + 1]}
240251
removeOfAllSelectedTypes={removeOfAllSelectedTypes}
241-
L={ligandListAllDatasets[data.datasetID].includes(data.molecule.id)}
242-
P={proteinListAllDatasets[data.datasetID].includes(data.molecule.id)}
243-
C={complexListAllDatasets[data.datasetID].includes(data.molecule.id)}
244-
S={surfaceListAllDatasets[data.datasetID].includes(data.molecule.id)}
252+
L={ligandList.includes(data.molecule.id)}
253+
P={proteinList.includes(data.molecule.id)}
254+
C={complexList.includes(data.molecule.id)}
255+
S={surfaceList.includes(data.molecule.id)}
245256
V={false}
246257
/>
247258
))}

0 commit comments

Comments
 (0)