Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#462' into #453
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
  • Loading branch information
Adriána Kohanová committed Nov 27, 2020
2 parents eed82dd + e0c3756 commit d7fbad6
Show file tree
Hide file tree
Showing 33 changed files with 1,351 additions and 463 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
50 changes: 31 additions & 19 deletions js/components/datasets/datasetMoleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import {
appendMoleculeToCompoundsOfDatasetToBuy,
removeMoleculeFromCompoundsOfDatasetToBuy,
setCrossReferenceCompoundName,
setIsOpenCrossReferenceDialog
setIsOpenCrossReferenceDialog,
setSelectedAll,
setDeselectedAll
} from './redux/actions';
import { centerOnLigandByMoleculeID } from '../../reducers/ngl/dispatchActions';
import { ArrowDownward, ArrowUpward, MyLocation } from '@material-ui/icons';
Expand Down Expand Up @@ -365,22 +367,22 @@ export const DatasetMoleculeView = memo(
const not_selected_style = {};
const current_style = isLigandOn || isProteinOn || isComplexOn || isSurfaceOn ? selected_style : not_selected_style;

const addNewLigand = () => {
dispatch(addDatasetLigand(stage, data, colourToggle, datasetID));
const addNewLigand = (skipTracking = false) => {
dispatch(addDatasetLigand(stage, data, colourToggle, datasetID, skipTracking));
};

const removeSelectedLigand = () => {
dispatch(removeDatasetLigand(stage, data, colourToggle, datasetID));
const removeSelectedLigand = (skipTracking = false) => {
dispatch(removeDatasetLigand(stage, data, colourToggle, datasetID, skipTracking));
selectedAll.current = false;
};

const onLigand = calledFromSelectAll => {
if (calledFromSelectAll === true && selectedAll.current === true) {
if (isLigandOn === false) {
addNewLigand();
addNewLigand(calledFromSelectAll);
}
} else if (calledFromSelectAll && selectedAll.current === false) {
removeSelectedLigand();
removeSelectedLigand(calledFromSelectAll);
} else if (!calledFromSelectAll) {
if (isLigandOn === false) {
addNewLigand();
Expand All @@ -390,22 +392,22 @@ export const DatasetMoleculeView = memo(
}
};

const removeSelectedProtein = () => {
dispatch(removeDatasetHitProtein(stage, data, colourToggle, datasetID));
const removeSelectedProtein = (skipTracking = false) => {
dispatch(removeDatasetHitProtein(stage, data, colourToggle, datasetID, skipTracking));
selectedAll.current = false;
};

const addNewProtein = () => {
dispatch(addDatasetHitProtein(stage, data, colourToggle, datasetID));
const addNewProtein = (skipTracking = false) => {
dispatch(addDatasetHitProtein(stage, data, colourToggle, datasetID, skipTracking));
};

const onProtein = calledFromSelectAll => {
if (calledFromSelectAll === true && selectedAll.current === true) {
if (isProteinOn === false) {
addNewProtein();
addNewProtein(calledFromSelectAll);
}
} else if (calledFromSelectAll && selectedAll.current === false) {
removeSelectedProtein();
removeSelectedProtein(calledFromSelectAll);
} else if (!calledFromSelectAll) {
if (isProteinOn === false) {
addNewProtein();
Expand All @@ -415,22 +417,22 @@ export const DatasetMoleculeView = memo(
}
};

const removeSelectedComplex = () => {
dispatch(removeDatasetComplex(stage, data, colourToggle, datasetID));
const removeSelectedComplex = (skipTracking = false) => {
dispatch(removeDatasetComplex(stage, data, colourToggle, datasetID, skipTracking));
selectedAll.current = false;
};

const addNewComplex = () => {
dispatch(addDatasetComplex(stage, data, colourToggle, datasetID));
const addNewComplex = (skipTracking = false) => {
dispatch(addDatasetComplex(stage, data, colourToggle, datasetID, skipTracking));
};

const onComplex = calledFromSelectAll => {
if (calledFromSelectAll === true && selectedAll.current === true) {
if (isComplexOn === false) {
addNewComplex();
addNewComplex(calledFromSelectAll);
}
} else if (calledFromSelectAll && selectedAll.current === false) {
removeSelectedComplex();
removeSelectedComplex(calledFromSelectAll);
} else if (!calledFromSelectAll) {
if (isComplexOn === false) {
addNewComplex();
Expand Down Expand Up @@ -465,6 +467,15 @@ export const DatasetMoleculeView = memo(
}
};

const setCalledFromAll = () => {
let isSelected = selectedAll.current === true;
if (isSelected) {
dispatch(setSelectedAll(datasetID, data, true, true, true));
} else {
dispatch(setDeselectedAll(datasetID, data, isLigandOn, isProteinOn, isComplexOn));
}
};

/**
* Check if given molecule is matching current filter
* @param Object item - item.name is attribute name, item.value is its value
Expand Down Expand Up @@ -630,6 +641,7 @@ export const DatasetMoleculeView = memo(
// always deselect all if are selected only some of options
selectedAll.current = hasSomeValuesOn ? false : !selectedAll.current;

setCalledFromAll();
onLigand(true);
onProtein(true);
onComplex(true);
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, 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
Loading

0 comments on commit d7fbad6

Please sign in to comment.