Skip to content

Commit 411921f

Browse files
- implemented #1173 also with save/restore and undo/redo functionality
1 parent d82f46a commit 411921f

File tree

8 files changed

+278
-59
lines changed

8 files changed

+278
-59
lines changed

js/components/datasets/datasetMoleculeList.js

+107-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
TextField,
1515
Checkbox,
1616
InputAdornment,
17-
setRef
17+
setRef,
18+
Box
1819
} from '@material-ui/core';
1920
import React, { useState, useEffect, memo, useRef, useContext, useCallback, useMemo } from 'react';
2021
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
@@ -52,7 +53,11 @@ import {
5253
setIsOpenLockVisibleCompoundsDialogGlobal,
5354
setSearchStringOfCompoundSet,
5455
setCompoundToSelectedCompoundsByDataset,
55-
setSelectAllButtonForDataset
56+
setSelectAllButtonForDataset,
57+
appendCompoundColorOfDataset,
58+
appendColorToAllCompoundsOfDataset,
59+
removeCompoundColorOfDataset,
60+
removeColorFromAllCompoundsOfDataset
5661
} from './redux/actions';
5762
import { DatasetFilter } from './datasetFilter';
5863
import { FilterList, Link, DeleteForever, ArrowUpward, ArrowDownward, Edit } from '@material-ui/icons';
@@ -79,6 +84,7 @@ import {
7984
onStartEditColorClassName
8085
} from '../preview/compounds/redux/dispatchActions';
8186
import { LockVisibleCompoundsDialog } from './lockVisibleCompoundsDialog';
87+
import { size } from 'lodash';
8288

8389
const useStyles = makeStyles(theme => ({
8490
container: {
@@ -163,6 +169,26 @@ const useStyles = makeStyles(theme => ({
163169
contButtonsMargin: {
164170
margin: theme.spacing(1) / 2
165171
},
172+
paintAllButton: {
173+
minWidth: 'fit-content',
174+
paddingLeft: theme.spacing(1) / 4,
175+
paddingRight: theme.spacing(1) / 4,
176+
paddingBottom: 0,
177+
paddingTop: 0,
178+
fontWeight: 'bold',
179+
fontSize: 9,
180+
borderRadius: 0,
181+
borderColor: theme.palette.primary.main,
182+
backgroundColor: 'white',
183+
'&:hover': {
184+
backgroundColor: 'white'
185+
// color: theme.palette.primary.contrastText
186+
},
187+
'&:disabled': {
188+
borderRadius: 0,
189+
borderColor: 'white'
190+
}
191+
},
166192
contColButton: {
167193
minWidth: 'fit-content',
168194
paddingLeft: theme.spacing(1) / 4,
@@ -808,6 +834,39 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
808834
}
809835
};
810836

837+
const isPaintOrUnpaintAll = () => {
838+
let isPaint = true;
839+
const compounds = Object.keys(compoundColors);
840+
for (let i = 0; i < compounds.length; i++) {
841+
const cmpId = compounds[i];
842+
const colors = compoundColors[cmpId];
843+
if (colors.some(c => c === currentCompoundClass)) {
844+
isPaint = false;
845+
break;
846+
}
847+
}
848+
849+
return isPaint;
850+
};
851+
852+
const paintAllCompounds = () => {
853+
const paintAll = isPaintOrUnpaintAll();
854+
const cmpIds = joinedMoleculeLists.map(mol => mol.id);
855+
if (paintAll) {
856+
joinedMoleculeLists.forEach(molecule => {
857+
const molName = molecule.name;
858+
dispatch(appendCompoundColorOfDataset(datasetID, molecule.id, currentCompoundClass, molName, true));
859+
});
860+
dispatch(appendColorToAllCompoundsOfDataset(datasetID, currentCompoundClass, cmpIds));
861+
} else {
862+
joinedMoleculeLists.forEach(molecule => {
863+
const molName = molecule.name;
864+
dispatch(removeCompoundColorOfDataset(datasetID, molecule.id, currentCompoundClass, molName, true));
865+
});
866+
dispatch(removeColorFromAllCompoundsOfDataset(datasetID, currentCompoundClass, cmpIds));
867+
}
868+
};
869+
811870
return (
812871
<Panel hasHeader title={title} withTooltip headerActions={actions}>
813872
<AlertModal
@@ -1082,25 +1141,53 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
10821141
</Grid>
10831142
</Grid>
10841143
<Grid item>
1085-
{
1086-
<Tooltip title={selectAllPressed ? 'Unselect all' : 'Select all'}>
1087-
<Grid item style={{ margin: '4px', marginLeft: '5px' }}>
1088-
<Button
1089-
variant="outlined"
1090-
className={classNames(classes.contColButton, {
1091-
[classes.contColButtonHalfSelected]: false
1092-
})}
1093-
onClick={() => {
1094-
dispatch(setSelectAllButtonForDataset(!selectAllPressed));
1095-
selectAllDatasetMolecule(!selectAllPressed);
1144+
<Tooltip title={selectAllPressed ? 'Unselect all' : 'Select all'}>
1145+
<Grid item style={{ margin: '4px', marginLeft: '5px' }}>
1146+
<Button
1147+
variant="outlined"
1148+
className={classNames(classes.contColButton, {
1149+
[classes.contColButtonHalfSelected]: false
1150+
})}
1151+
onClick={() => {
1152+
dispatch(setSelectAllButtonForDataset(!selectAllPressed));
1153+
selectAllDatasetMolecule(!selectAllPressed);
1154+
}}
1155+
disabled={false}
1156+
>
1157+
{selectAllPressed ? 'Unselect all' : 'Select all'}
1158+
</Button>
1159+
</Grid>
1160+
</Tooltip>
1161+
</Grid>
1162+
<Grid item>
1163+
<Tooltip
1164+
title={
1165+
isPaintOrUnpaintAll()
1166+
? 'Paint all compounds with selected color'
1167+
: 'Unpaint all compounds with selected color'
1168+
}
1169+
>
1170+
<Grid item style={{ margin: '4px', marginLeft: '5px' }}>
1171+
<Button
1172+
variant="outlined"
1173+
className={classNames(classes.paintAllButton)}
1174+
disabled={false}
1175+
onClick={() => paintAllCompounds()}
1176+
>
1177+
<Box
1178+
style={{
1179+
width: '10px',
1180+
height: '10px',
1181+
backgroundColor: compoundsColors[currentCompoundClass]
1182+
? compoundsColors[currentCompoundClass].color
1183+
: '#000000',
1184+
marginRight: '2px'
10961185
}}
1097-
disabled={false}
1098-
>
1099-
{selectAllPressed ? 'Unselect all' : 'Select all'}
1100-
</Button>
1101-
</Grid>
1102-
</Tooltip>
1103-
}
1186+
/>
1187+
{isPaintOrUnpaintAll() ? 'Paint all' : 'Unpaint all'}
1188+
</Button>
1189+
</Grid>
1190+
</Tooltip>
11041191
</Grid>
11051192
</Grid>
11061193
</Grid>

js/components/datasets/datasetMoleculeView/datasetMoleculeView.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import AddShoppingCartIcon from '@mui/icons-material/AddShoppingCart';
7878
import RemoveShoppingCartIcon from '@mui/icons-material/RemoveShoppingCart';
7979
import { compoundsColors } from '../../preview/compounds/redux/constants';
8080
import { LockVisibleCompoundsDialog } from '../lockVisibleCompoundsDialog';
81+
import { fabClasses } from '@mui/material';
8182

8283
const useStyles = makeStyles(theme => ({
8384
container: {
@@ -639,26 +640,26 @@ const DatasetMoleculeView = memo(
639640
// if (shoppingCartColors?.length === 1) {
640641
// dispatch(removeMoleculeFromCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
641642
// }
642-
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, true));
643+
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, false));
643644
} else {
644645
// dispatch(appendMoleculeToCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
645-
dispatch(appendCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, true));
646+
dispatch(appendCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, false));
646647
}
647648
};
648649

649650
const handleRemoveColorFromCompound = event => {
650651
if (shoppingCartColors?.length === 1) {
651652
dispatch(removeMoleculeFromCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
652653
}
653-
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, true));
654+
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, false));
654655
};
655656

656657
const handleShoppingCartClick = () => {
657658
if (currentCompoundClass) {
658659
// if (!isAddedToShoppingCart) {
659660
// dispatch(appendMoleculeToCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
660661
// }
661-
dispatch(appendCompoundColorOfDataset(datasetID, currentID, currentCompoundClass, moleculeTitle, true));
662+
dispatch(appendCompoundColorOfDataset(datasetID, currentID, currentCompoundClass, moleculeTitle, false));
662663
}
663664
};
664665

js/components/datasets/redux/actions.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ export const appendCompoundColorOfDataset = (
388388
skipTracking = false
389389
) => ({
390390
type: constants.APPEND_COMPOUND_COLOR_OF_DATASET,
391-
payload: { datasetID, compoundID, colorClass, compoundTitle, skipTracking: skipTracking }
391+
payload: { datasetID, compoundID, colorClass, compoundTitle },
392+
skipTracking: skipTracking
392393
});
393394

394395
export const removeCompoundColorOfDataset = (
@@ -399,7 +400,18 @@ export const removeCompoundColorOfDataset = (
399400
skipTracking = false
400401
) => ({
401402
type: constants.REMOVE_COMPOUND_COLOR_OF_DATASET,
402-
payload: { datasetID, compoundID, colorClass, compoundTitle, skipTracking: skipTracking }
403+
payload: { datasetID, compoundID, colorClass, compoundTitle },
404+
skipTracking: skipTracking
405+
});
406+
407+
export const appendColorToAllCompoundsOfDataset = (datasetID, colorClass, cmpIds) => ({
408+
type: constants.APPEND_COLOR_TO_ALL_COMPOUNDS_OF_DATASET,
409+
payload: { datasetID, colorClass, cmpIds }
410+
});
411+
412+
export const removeColorFromAllCompoundsOfDataset = (datasetID, colorClass, cmpIds) => ({
413+
type: constants.REMOVE_COLOR_FROM_ALL_COMPOUNDS_OF_DATASET,
414+
payload: { datasetID, colorClass, cmpIds }
403415
});
404416

405417
export const appendColorToSelectedColorFilter = colorClass => ({

js/components/datasets/redux/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export const constants = {
7474

7575
APPEND_COMPOUND_COLOR_OF_DATASET: prefix + 'APPEND_COMPOUND_COLOR_OF_DATASET',
7676
REMOVE_COMPOUND_COLOR_OF_DATASET: prefix + 'REMOVE_COMPOUND_COLOR_OF_DATASET',
77+
APPEND_COLOR_TO_ALL_COMPOUNDS_OF_DATASET: prefix + 'SET_COLOR_TO_ALL_COMPOUNDS_OF_DATASET',
78+
REMOVE_COLOR_FROM_ALL_COMPOUNDS_OF_DATASET: prefix + 'REMOVE_COLOR_FROM_ALL_COMPOUNDS_OF_DATASET',
7779

7880
APPEND_COLOR_TO_SELECTED_COLOR_FILTERS: prefix + 'APPEND_COLOR_TO_SELECTED_COLOR_FILTERS',
7981
REMOVE_COLOR_FROM_SELECTED_COLOR_FILTERS: prefix + 'REMOVE_COLOR_FROM_SELECTED_COLOR_FILTERS',

js/components/projects/redux/dispatchActions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -552,5 +552,5 @@ const getJobOverrides = async () => {
552552
const resultCall = await api({
553553
url: `${base_url}/api/job_override/`
554554
});
555-
return resultCall.data.results[0].override;
555+
return resultCall.data?.results[0]?.override;
556556
};

js/reducers/tracking/constants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ export const actionType = {
117117
COMPOUND_REMOVED_FROM_COLOR_GROUP: 'COMPOUND_REMOVED_FROM_COLOR_GROUP',
118118
TAG_DETAIL_VIEW: 'TAG_DETAIL_VIEW',
119119
SELECT_ALL_DATASET_COMPOUNDS: 'SELECT_ALL_DATASET_COMPOUNDS',
120-
SELECTED_SELECT_ALL_BUTTON_FOR_DATASET: 'SELECTED_SELECT_ALL_BUTTON_FOR_DATASET'
120+
SELECTED_SELECT_ALL_BUTTON_FOR_DATASET: 'SELECTED_SELECT_ALL_BUTTON_FOR_DATASET',
121+
ALL_COMPOUNDS_ADDED_TO_COLOR_GROUP: 'ALL_COMPOUNDS_ADDED_TO_COLOR_GROUP',
122+
ALL_COMPOUNDS_REMOVED_FROM_COLOR_GROUP: 'ALL_COMPOUNDS_REMOVED_FROM_COLOR_GROUP'
121123
};
122124

123125
export const snapshotSwitchManualActions = [

0 commit comments

Comments
 (0)