Skip to content

Commit

Permalink
#462 Mass actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Nov 23, 2020
1 parent 8cfc6a8 commit 0cb5476
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 81 deletions.
54 changes: 45 additions & 9 deletions js/components/datasets/datasetMoleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import {
removeDatasetComplex,
addDatasetSurface,
removeDatasetSurface,
resetCrossReferenceDialog,
autoHideDatasetDialogsOnScroll
} from './redux/dispatchActions';
import { setFilterDialogOpen, setIsOpenInspirationDialog, setSearchStringOfCompoundSet } from './redux/actions';
import { setFilterDialogOpen, setSearchStringOfCompoundSet } from './redux/actions';
import { DatasetFilter } from './datasetFilter';
import { FilterList, Search, Link } from '@material-ui/icons';
import { getFilteredDatasetMoleculeList } from './redux/selectors';
import { debounce } from 'lodash';
import { InspirationDialog } from './inspirationDialog';
import { CrossReferenceDialog } from './crossReferenceDialog';
import { AlertModal } from '../common/Modal/AlertModal';
import { setSelectedAllByType, setDeselectedAllByType } from './redux/actions';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -311,15 +311,17 @@ export const DatasetMoleculeList = memo(
// TODO so this could lead to inconsistend behaviour while scrolling
// TODO maybe change "currentMolecules.forEach" to "{type}List.forEach"

const removeSelectedType = type => {
const removeSelectedType = (type, skipTracking) => {
joinedMoleculeLists.forEach(molecule => {
dispatch(removeType[type](stage, molecule, colourList[molecule.id % colourList.length], datasetID));
dispatch(
removeType[type](stage, molecule, colourList[molecule.id % colourList.length], datasetID, skipTracking)
);
});
selectedAll.current = false;
};
const addNewType = type => {
const addNewType = (type, skipTracking) => {
joinedMoleculeLists.forEach(molecule => {
dispatch(addType[type](stage, molecule, colourList[molecule.id % colourList.length], datasetID));
dispatch(addType[type](stage, molecule, colourList[molecule.id % colourList.length], datasetID, skipTracking));
});
};
const ucfirst = string => {
Expand All @@ -335,12 +337,46 @@ export const DatasetMoleculeList = memo(
removeSelectedType(type);
} else if (!calledFromSelectAll) {
if (eval('is' + ucfirst(type) + 'On') === false) {
addNewType(type);
let molecules = getSelectedMoleculesByType(type, true);
dispatch(setSelectedAllByType(type, datasetID, molecules));
addNewType(type, true);
} else {
removeSelectedType(type);
let molecules = getSelectedMoleculesByType(type, false);
dispatch(setDeselectedAllByType(type, datasetID, molecules));
removeSelectedType(type, true);
}
}
};

const getSelectedMoleculesByType = (type, isAdd) => {
switch (type) {
case 'ligand':
return isAdd ? getMoleculesToSelect(ligandList) : getMoleculesToDeselect(ligandList);
case 'protein':
return isAdd ? getMoleculesToSelect(proteinList) : getMoleculesToDeselect(proteinList);
case 'complex':
return isAdd ? getMoleculesToSelect(complexList) : getMoleculesToDeselect(complexList);
default:
return null;
}
};

const getMoleculesToSelect = list => {
let molecules = joinedMoleculeLists.filter(m => !list.includes(m.id));
let data = molecules.map(m => {
return { datasetID, molecule: m };
});
return data;
};

const getMoleculesToDeselect = list => {
let molecules = joinedMoleculeLists.filter(m => list.includes(m.id));
let data = molecules.map(m => {
return { datasetID, molecule: m };
});
return data;
};

let debouncedFn;

const handleSearch = event => {
Expand Down Expand Up @@ -456,7 +492,7 @@ export const DatasetMoleculeList = memo(
<Tooltip
title={`${filterProperties[attr].minValue}-${filterProperties[attr].maxValue} ${
filterProperties[attr].order === 1 ? '\u2191' : '\u2193'
}`}
}`}
placement="top"
>
<Chip size="small" label={attr} className={classes.propertyChip} />
Expand Down
4 changes: 2 additions & 2 deletions js/components/datasets/datasetMoleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,9 @@ export const DatasetMoleculeView = memo(
const setCalledFromAll = () => {
let isSelected = selectedAll.current === true;
if (isSelected) {
dispatch(setSelectedAll(datasetID, data));
dispatch(setSelectedAll(datasetID, data, true, true, true));
} else {
dispatch(setDeselectedAll(datasetID, data));
dispatch(setDeselectedAll(datasetID, data, isLigandOn, isProteinOn, isComplexOn));
}
};

Expand Down
62 changes: 52 additions & 10 deletions js/components/datasets/inspirationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { NglContext } from '../nglView/nglProvider';
import { VIEWS } from '../../constants/constants';
import { Panel } from '../common/Surfaces/Panel';
import { changeButtonClassname } from './helpers';
import { setSelectedAllByType, setDeselectedAllByType } from '../../reducers/selection/actions';

const useStyles = makeStyles(theme => ({
paper: {
Expand Down Expand Up @@ -254,17 +255,30 @@ export const InspirationDialog = memo(
});
};

const removeSelectedType = type => {
moleculeList.forEach(molecule => {
dispatch(removeType[type](stage, molecule, colourList[molecule.id % colourList.length], datasetID));
});
const removeSelectedType = (type, skipTracking = false) => {
if (type === 'ligand') {
moleculeList.forEach(molecule => {
dispatch(removeType[type](stage, molecule, colourList[molecule.id % colourList.length], false, skipTracking));
});
} else {
moleculeList.forEach(molecule => {
dispatch(removeType[type](stage, molecule, colourList[molecule.id % colourList.length], skipTracking));
});
}

selectedAll.current = false;
};

const addNewType = type => {
moleculeList.forEach(molecule => {
dispatch(addType[type](stage, molecule, colourList[molecule.id % colourList.length]));
});
const addNewType = (type, skipTracking = false) => {
if (type === 'ligand') {
moleculeList.forEach(molecule => {
dispatch(addType[type](stage, molecule, colourList[molecule.id % colourList.length], false, skipTracking));
});
} else {
moleculeList.forEach(molecule => {
dispatch(addType[type](stage, molecule, colourList[molecule.id % colourList.length], skipTracking));
});
}
};

const ucfirst = string => {
Expand All @@ -281,12 +295,40 @@ export const InspirationDialog = memo(
removeSelectedType(type);
} else if (!calledFromSelectAll) {
if (eval('is' + ucfirst(type) + 'On') === false) {
addNewType(type);
let molecules = getSelectedMoleculesByType(type, true);
dispatch(setSelectedAllByType(type, molecules, true));
addNewType(type, true);
} else {
removeSelectedType(type);
let molecules = getSelectedMoleculesByType(type, false);
dispatch(setDeselectedAllByType(type, molecules, true));
removeSelectedType(type, true);
}
}
};

const getSelectedMoleculesByType = (type, isAdd) => {
switch (type) {
case 'ligand':
return isAdd ? getMoleculesToSelect(ligandList) : getMoleculesToDeselect(ligandList);
case 'protein':
return isAdd ? getMoleculesToSelect(proteinList) : getMoleculesToDeselect(proteinList);
case 'complex':
return isAdd ? getMoleculesToSelect(complexList) : getMoleculesToDeselect(complexList);
default:
return null;
}
};

const getMoleculesToSelect = list => {
let molecules = moleculeList.filter(m => !list.includes(m.id));
return molecules;
};

const getMoleculesToDeselect = list => {
let molecules = moleculeList.filter(m => list.includes(m.id));
return molecules;
};

// TODO refactor to this line

return (
Expand Down
34 changes: 30 additions & 4 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,44 @@ export const resetDatasetsState = () => {
};
};

export const setSelectedAll = (datsetID, item) => ({
export const setSelectedAll = (datsetID, item, isLigand, isProtein, isComplex) => ({
type: constants.SET_SELECTED_ALL,
payload: {
datasetID: datsetID,
item: item
item: item,
isLigand: isLigand,
isProtein: isProtein,
isComplex: isComplex
}
});

export const setDeselectedAll = (datsetID, item) => ({
export const setDeselectedAll = (datsetID, item, isLigand, isProtein, isComplex) => ({
type: constants.SET_DESELECTED_ALL,
payload: {
datasetID: datsetID,
item: item
item: item,
isLigand: isLigand,
isProtein: isProtein,
isComplex: isComplex
}
});

export const setSelectedAllByType = (type, datsetID, items, isCrossReference) => ({
type: constants.SET_SELECTED_ALL_BY_TYPE,
payload: {
type: type,
datasetID: datsetID,
items: items,
isCrossReference: isCrossReference
}
});

export const setDeselectedAllByType = (type, datsetID, items, isCrossReference) => ({
type: constants.SET_DESELECTED_ALL_BY_TYPE,
payload: {
type: type,
datasetID: datsetID,
items: items,
isCrossReference: isCrossReference
}
});
5 changes: 4 additions & 1 deletion js/components/datasets/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export const constants = {
RESET_DATASETS_STATE: prefix + 'RESET_DATASETS_STATE',

SET_SELECTED_ALL: prefix + 'SET_SELECTED_ALL',
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL'
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL',

SET_SELECTED_ALL_BY_TYPE: prefix + 'SET_SELECTED_ALL_BY_TYPE',
SET_DESELECTED_ALL_BY_TYPE: prefix + 'SET_DESELECTED_ALL_BY_TYPE'
};

export const COUNT_OF_VISIBLE_SCORES = 7;
Expand Down
Loading

0 comments on commit 0cb5476

Please sign in to comment.