Skip to content

Commit ae4273c

Browse files
Merge branch '#384' into #369
# Conflicts: # js/components/datasets/customDatasetList.js # js/components/datasets/datasetMoleculeView.js # js/components/datasets/redux/dispatchActions.js
2 parents 6701b75 + ec0f607 commit ae4273c

17 files changed

+1231
-645
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { memo } from 'react';
2+
import { DialogTitle, DialogContent, DialogContentText, DialogActions, Button } from '@material-ui/core';
3+
import Modal from '../index';
4+
5+
export const AlertModal = memo(({ open, title, description, handleOnOk, handleOnCancel }) => {
6+
return (
7+
<Modal open={open}>
8+
<DialogTitle>{title}</DialogTitle>
9+
<DialogContent>
10+
<DialogContentText>{description}</DialogContentText>
11+
</DialogContent>
12+
<DialogActions>
13+
<Button onClick={handleOnCancel} color="secondary" variant="contained">
14+
Cancel
15+
</Button>
16+
<Button onClick={handleOnOk} color="primary" autoFocus variant="contained">
17+
OK
18+
</Button>
19+
</DialogActions>
20+
</Modal>
21+
);
22+
});

js/components/datasets/crossReferenceDialog.js

+71-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import {
88
handleAllLigandsOfCrossReferenceDialog,
99
resetCrossReferenceDialog,
1010
removeOrAddAllHitProteinsOfList,
11-
removeOrAddAllComplexesOfList
11+
removeOrAddAllComplexesOfList,
12+
removeDatasetLigand,
13+
removeDatasetHitProtein,
14+
removeDatasetComplex,
15+
removeDatasetSurface
1216
} from './redux/dispatchActions';
1317
import { Button } from '../common/Inputs/Button';
1418
import classNames from 'classnames';
1519
import { useDisableUserInteraction } from '../helpers/useEnableUserInteracion';
16-
import { DatasetMoleculeView } from './datasetMoleculeView';
20+
import { colourList, DatasetMoleculeView } from './datasetMoleculeView';
1721
import { NglContext } from '../nglView/nglProvider';
1822
import { VIEWS } from '../../constants/constants';
1923
import { Panel } from '../common/Surfaces/Panel';
@@ -136,6 +140,66 @@ export const CrossReferenceDialog = memo(
136140
const proteinList = useSelector(state => getListOfSelectedProteinOfAllDatasets(state));
137141
const complexList = useSelector(state => getListOfSelectedComplexOfAllDatasets(state));
138142

143+
const ligandListAllDatasets = useSelector(state => state.datasetsReducers.ligandLists);
144+
const proteinListAllDatasets = useSelector(state => state.datasetsReducers.proteinLists);
145+
const complexListAllDatasets = useSelector(state => state.datasetsReducers.complexLists);
146+
const surfaceListAllDatasets = useSelector(state => state.datasetsReducers.surfaceLists);
147+
148+
const removeOfAllSelectedTypes = () => {
149+
Object.keys(ligandListAllDatasets).forEach(datasetKey => {
150+
ligandListAllDatasets[datasetKey]?.forEach(moleculeID => {
151+
const foundedMolecule = moleculeList?.find(mol => mol?.molecule?.id === moleculeID);
152+
dispatch(
153+
removeDatasetLigand(
154+
stage,
155+
foundedMolecule?.molecule,
156+
colourList[foundedMolecule?.molecule?.id % colourList.length],
157+
datasetKey
158+
)
159+
);
160+
});
161+
});
162+
Object.keys(proteinListAllDatasets).forEach(datasetKey => {
163+
proteinListAllDatasets[datasetKey]?.forEach(moleculeID => {
164+
const foundedMolecule = moleculeList?.find(mol => mol?.molecule?.id === moleculeID);
165+
dispatch(
166+
removeDatasetHitProtein(
167+
stage,
168+
foundedMolecule?.molecule,
169+
colourList[foundedMolecule?.molecule?.id % colourList.length],
170+
datasetKey
171+
)
172+
);
173+
});
174+
});
175+
Object.keys(complexListAllDatasets).forEach(datasetKey => {
176+
complexListAllDatasets[datasetKey]?.forEach(moleculeID => {
177+
const foundedMolecule = moleculeList?.find(mol => mol?.molecule?.id === moleculeID);
178+
dispatch(
179+
removeDatasetComplex(
180+
stage,
181+
foundedMolecule?.molecule,
182+
colourList[foundedMolecule?.molecule?.id % colourList.length],
183+
datasetKey
184+
)
185+
);
186+
});
187+
});
188+
Object.keys(surfaceListAllDatasets).forEach(datasetKey => {
189+
surfaceListAllDatasets[datasetKey]?.forEach(moleculeID => {
190+
const foundedMolecule = moleculeList?.find(mol => mol?.molecule?.id === moleculeID);
191+
dispatch(
192+
removeDatasetSurface(
193+
stage,
194+
foundedMolecule?.molecule,
195+
colourList[foundedMolecule?.molecule?.id % colourList.length],
196+
datasetKey
197+
)
198+
);
199+
});
200+
});
201+
};
202+
139203
useEffect(() => {
140204
if (moleculeList && Array.isArray(moleculeList) && moleculeList.length > 0) {
141205
// moleculeList has following structure:
@@ -253,15 +317,19 @@ export const CrossReferenceDialog = memo(
253317
</Grid>
254318
<div className={classes.content}>
255319
{moleculeList.length > 0 &&
256-
moleculeList.map((data, index) => (
320+
moleculeList.map((data, index, array) => (
257321
<DatasetMoleculeView
258322
key={index}
323+
index={index}
259324
imageHeight={imgHeight}
260325
imageWidth={imgWidth}
261326
data={data.molecule}
262327
datasetID={data.datasetID}
263328
hideFButton
264329
showDatasetName
330+
previousItemData={index > 0 && array[index - 1]}
331+
nextItemData={index < array?.length && array[index + 1]}
332+
removeOfAllSelectedTypes={removeOfAllSelectedTypes}
265333
/>
266334
))}
267335
{!(moleculeList.length > 0) && (

js/components/datasets/datasetMoleculeList.js

+62-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { getFilteredDatasetMoleculeList } from './redux/selectors';
4444
import { debounce } from 'lodash';
4545
import { InspirationDialog } from './inspirationDialog';
4646
import { CrossReferenceDialog } from './crossReferenceDialog';
47+
import { AlertModal } from '../common/Modal/AlertModal';
4748

4849
const useStyles = makeStyles(theme => ({
4950
container: {
@@ -182,6 +183,11 @@ const useStyles = makeStyles(theme => ({
182183
},
183184
loading: {
184185
paddingTop: theme.spacing(2)
186+
},
187+
total: {
188+
...theme.typography.button,
189+
color: theme.palette.primary.main,
190+
fontStyle: 'italic'
185191
}
186192
}));
187193

@@ -255,8 +261,9 @@ export const DatasetMoleculeList = memo(
255261
const ligandList = useSelector(state => state.datasetsReducers.ligandLists[datasetID]);
256262
const proteinList = useSelector(state => state.datasetsReducers.proteinLists[datasetID]);
257263
const complexList = useSelector(state => state.datasetsReducers.complexLists[datasetID]);
258-
const isLigandOn = (ligandList && ligandList.length > 0) || false;
264+
const surfaceList = useSelector(state => state.datasetsReducers.surfaceLists[datasetID]);
259265

266+
const isLigandOn = (ligandList && ligandList.length > 0) || false;
260267
const isProteinOn = (proteinList && proteinList.length > 0) || false;
261268
const isComplexOn = (complexList && complexList.length > 0) || false;
262269
const addType = {
@@ -273,6 +280,33 @@ export const DatasetMoleculeList = memo(
273280
surface: removeDatasetSurface
274281
};
275282

283+
const removeOfAllSelectedTypes = () => {
284+
ligandList?.forEach(moleculeID => {
285+
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
286+
dispatch(
287+
removeDatasetLigand(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], datasetID)
288+
);
289+
});
290+
proteinList?.forEach(moleculeID => {
291+
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
292+
dispatch(
293+
removeDatasetHitProtein(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], datasetID)
294+
);
295+
});
296+
complexList?.forEach(moleculeID => {
297+
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
298+
dispatch(
299+
removeDatasetComplex(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], datasetID)
300+
);
301+
});
302+
surfaceList?.forEach(moleculeID => {
303+
const foundedMolecule = joinedMoleculeLists?.find(mol => mol.id === moleculeID);
304+
dispatch(
305+
removeDatasetSurface(stage, foundedMolecule, colourList[foundedMolecule.id % colourList.length], datasetID)
306+
);
307+
});
308+
};
309+
276310
// TODO "currentMolecules" do not need to correspondent to selections in {type}List
277311
// TODO so this could lead to inconsistend behaviour while scrolling
278312
// TODO maybe change "currentMolecules.forEach" to "{type}List.forEach"
@@ -365,6 +399,8 @@ export const DatasetMoleculeList = memo(
365399
const inspirationDialogRef = useRef();
366400
const scrollBarRef = useRef();
367401

402+
const [isOpenAlert, setIsOpenAlert] = useState(false);
403+
368404
return (
369405
<ComputeSize
370406
componentRef={filterRef.current}
@@ -373,6 +409,18 @@ export const DatasetMoleculeList = memo(
373409
forceCompute={isActiveFilter}
374410
>
375411
<Panel hasHeader title={title} withTooltip headerActions={actions}>
412+
<AlertModal
413+
title="Are you sure?"
414+
description={`Loading of ${joinedMoleculeLists?.length} may take a long time`}
415+
open={isOpenAlert}
416+
handleOnOk={() => {
417+
setNextXMolecules(joinedMoleculeLists?.length || 0);
418+
setIsOpenAlert(false);
419+
}}
420+
handleOnCancel={() => {
421+
setIsOpenAlert(false);
422+
}}
423+
/>
376424
{sortDialogOpen && (
377425
<DatasetFilter
378426
open={sortDialogOpen}
@@ -550,7 +598,7 @@ export const DatasetMoleculeList = memo(
550598
useWindow={false}
551599
>
552600
{datasetID &&
553-
currentMolecules.map((data, index) => (
601+
currentMolecules.map((data, index, array) => (
554602
<DatasetMoleculeView
555603
key={index}
556604
index={index}
@@ -560,12 +608,18 @@ export const DatasetMoleculeList = memo(
560608
datasetID={datasetID}
561609
setRef={setSelectedMoleculeRef}
562610
showCrossReferenceModal
611+
previousItemData={index > 0 && array[index - 1]}
612+
nextItemData={index < array?.length && array[index + 1]}
613+
removeOfAllSelectedTypes={removeOfAllSelectedTypes}
563614
/>
564615
))}
565616
</InfiniteScroll>
566617
</Grid>
567618
<Grid item>
568-
<Grid container justify="flex-end" direction="row">
619+
<Grid container justify="space-between" alignItems="center" direction="row">
620+
<Grid item>
621+
<span className={classes.total}>{`Total ${joinedMoleculeLists?.length}`}</span>
622+
</Grid>
569623
<Grid item>
570624
<ButtonGroup
571625
variant="text"
@@ -589,7 +643,11 @@ export const DatasetMoleculeList = memo(
589643
</Button>
590644
<Button
591645
onClick={() => {
592-
setNextXMolecules(joinedMoleculeLists?.length || 0);
646+
if (joinedMoleculeLists?.length > 300) {
647+
setIsOpenAlert(true);
648+
} else {
649+
setNextXMolecules(joinedMoleculeLists?.length || 0);
650+
}
593651
}}
594652
>
595653
Load full list

0 commit comments

Comments
 (0)