Skip to content

Commit

Permalink
- implemented #1173 also with save/restore and undo/redo functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Oct 13, 2023
1 parent d82f46a commit 411921f
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 59 deletions.
127 changes: 107 additions & 20 deletions js/components/datasets/datasetMoleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
TextField,
Checkbox,
InputAdornment,
setRef
setRef,
Box
} from '@material-ui/core';
import React, { useState, useEffect, memo, useRef, useContext, useCallback, useMemo } from 'react';
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
Expand Down Expand Up @@ -52,7 +53,11 @@ import {
setIsOpenLockVisibleCompoundsDialogGlobal,
setSearchStringOfCompoundSet,
setCompoundToSelectedCompoundsByDataset,
setSelectAllButtonForDataset
setSelectAllButtonForDataset,
appendCompoundColorOfDataset,
appendColorToAllCompoundsOfDataset,
removeCompoundColorOfDataset,
removeColorFromAllCompoundsOfDataset
} from './redux/actions';
import { DatasetFilter } from './datasetFilter';
import { FilterList, Link, DeleteForever, ArrowUpward, ArrowDownward, Edit } from '@material-ui/icons';
Expand All @@ -79,6 +84,7 @@ import {
onStartEditColorClassName
} from '../preview/compounds/redux/dispatchActions';
import { LockVisibleCompoundsDialog } from './lockVisibleCompoundsDialog';
import { size } from 'lodash';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -163,6 +169,26 @@ const useStyles = makeStyles(theme => ({
contButtonsMargin: {
margin: theme.spacing(1) / 2
},
paintAllButton: {
minWidth: 'fit-content',
paddingLeft: theme.spacing(1) / 4,
paddingRight: theme.spacing(1) / 4,
paddingBottom: 0,
paddingTop: 0,
fontWeight: 'bold',
fontSize: 9,
borderRadius: 0,
borderColor: theme.palette.primary.main,
backgroundColor: 'white',
'&:hover': {
backgroundColor: 'white'
// color: theme.palette.primary.contrastText
},
'&:disabled': {
borderRadius: 0,
borderColor: 'white'
}
},
contColButton: {
minWidth: 'fit-content',
paddingLeft: theme.spacing(1) / 4,
Expand Down Expand Up @@ -808,6 +834,39 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
}
};

const isPaintOrUnpaintAll = () => {
let isPaint = true;
const compounds = Object.keys(compoundColors);
for (let i = 0; i < compounds.length; i++) {
const cmpId = compounds[i];
const colors = compoundColors[cmpId];
if (colors.some(c => c === currentCompoundClass)) {
isPaint = false;
break;
}
}

return isPaint;
};

const paintAllCompounds = () => {
const paintAll = isPaintOrUnpaintAll();
const cmpIds = joinedMoleculeLists.map(mol => mol.id);
if (paintAll) {
joinedMoleculeLists.forEach(molecule => {
const molName = molecule.name;
dispatch(appendCompoundColorOfDataset(datasetID, molecule.id, currentCompoundClass, molName, true));
});
dispatch(appendColorToAllCompoundsOfDataset(datasetID, currentCompoundClass, cmpIds));
} else {
joinedMoleculeLists.forEach(molecule => {
const molName = molecule.name;
dispatch(removeCompoundColorOfDataset(datasetID, molecule.id, currentCompoundClass, molName, true));
});
dispatch(removeColorFromAllCompoundsOfDataset(datasetID, currentCompoundClass, cmpIds));
}
};

return (
<Panel hasHeader title={title} withTooltip headerActions={actions}>
<AlertModal
Expand Down Expand Up @@ -1082,25 +1141,53 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
</Grid>
</Grid>
<Grid item>
{
<Tooltip title={selectAllPressed ? 'Unselect all' : 'Select all'}>
<Grid item style={{ margin: '4px', marginLeft: '5px' }}>
<Button
variant="outlined"
className={classNames(classes.contColButton, {
[classes.contColButtonHalfSelected]: false
})}
onClick={() => {
dispatch(setSelectAllButtonForDataset(!selectAllPressed));
selectAllDatasetMolecule(!selectAllPressed);
<Tooltip title={selectAllPressed ? 'Unselect all' : 'Select all'}>
<Grid item style={{ margin: '4px', marginLeft: '5px' }}>
<Button
variant="outlined"
className={classNames(classes.contColButton, {
[classes.contColButtonHalfSelected]: false
})}
onClick={() => {
dispatch(setSelectAllButtonForDataset(!selectAllPressed));
selectAllDatasetMolecule(!selectAllPressed);
}}
disabled={false}
>
{selectAllPressed ? 'Unselect all' : 'Select all'}
</Button>
</Grid>
</Tooltip>
</Grid>
<Grid item>
<Tooltip
title={
isPaintOrUnpaintAll()
? 'Paint all compounds with selected color'
: 'Unpaint all compounds with selected color'
}
>
<Grid item style={{ margin: '4px', marginLeft: '5px' }}>
<Button
variant="outlined"
className={classNames(classes.paintAllButton)}
disabled={false}
onClick={() => paintAllCompounds()}
>
<Box
style={{
width: '10px',
height: '10px',
backgroundColor: compoundsColors[currentCompoundClass]
? compoundsColors[currentCompoundClass].color
: '#000000',
marginRight: '2px'
}}
disabled={false}
>
{selectAllPressed ? 'Unselect all' : 'Select all'}
</Button>
</Grid>
</Tooltip>
}
/>
{isPaintOrUnpaintAll() ? 'Paint all' : 'Unpaint all'}
</Button>
</Grid>
</Tooltip>
</Grid>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import AddShoppingCartIcon from '@mui/icons-material/AddShoppingCart';
import RemoveShoppingCartIcon from '@mui/icons-material/RemoveShoppingCart';
import { compoundsColors } from '../../preview/compounds/redux/constants';
import { LockVisibleCompoundsDialog } from '../lockVisibleCompoundsDialog';
import { fabClasses } from '@mui/material';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -639,26 +640,26 @@ const DatasetMoleculeView = memo(
// if (shoppingCartColors?.length === 1) {
// dispatch(removeMoleculeFromCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
// }
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, true));
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, false));
} else {
// dispatch(appendMoleculeToCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
dispatch(appendCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, true));
dispatch(appendCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, false));
}
};

const handleRemoveColorFromCompound = event => {
if (shoppingCartColors?.length === 1) {
dispatch(removeMoleculeFromCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
}
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, true));
dispatch(removeCompoundColorOfDataset(datasetID, currentID, event.target.id, moleculeTitle, false));
};

const handleShoppingCartClick = () => {
if (currentCompoundClass) {
// if (!isAddedToShoppingCart) {
// dispatch(appendMoleculeToCompoundsOfDatasetToBuy(datasetID, currentID, moleculeTitle));
// }
dispatch(appendCompoundColorOfDataset(datasetID, currentID, currentCompoundClass, moleculeTitle, true));
dispatch(appendCompoundColorOfDataset(datasetID, currentID, currentCompoundClass, moleculeTitle, false));
}
};

Expand Down
16 changes: 14 additions & 2 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ export const appendCompoundColorOfDataset = (
skipTracking = false
) => ({
type: constants.APPEND_COMPOUND_COLOR_OF_DATASET,
payload: { datasetID, compoundID, colorClass, compoundTitle, skipTracking: skipTracking }
payload: { datasetID, compoundID, colorClass, compoundTitle },
skipTracking: skipTracking
});

export const removeCompoundColorOfDataset = (
Expand All @@ -399,7 +400,18 @@ export const removeCompoundColorOfDataset = (
skipTracking = false
) => ({
type: constants.REMOVE_COMPOUND_COLOR_OF_DATASET,
payload: { datasetID, compoundID, colorClass, compoundTitle, skipTracking: skipTracking }
payload: { datasetID, compoundID, colorClass, compoundTitle },
skipTracking: skipTracking
});

export const appendColorToAllCompoundsOfDataset = (datasetID, colorClass, cmpIds) => ({
type: constants.APPEND_COLOR_TO_ALL_COMPOUNDS_OF_DATASET,
payload: { datasetID, colorClass, cmpIds }
});

export const removeColorFromAllCompoundsOfDataset = (datasetID, colorClass, cmpIds) => ({
type: constants.REMOVE_COLOR_FROM_ALL_COMPOUNDS_OF_DATASET,
payload: { datasetID, colorClass, cmpIds }
});

export const appendColorToSelectedColorFilter = colorClass => ({
Expand Down
2 changes: 2 additions & 0 deletions js/components/datasets/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export const constants = {

APPEND_COMPOUND_COLOR_OF_DATASET: prefix + 'APPEND_COMPOUND_COLOR_OF_DATASET',
REMOVE_COMPOUND_COLOR_OF_DATASET: prefix + 'REMOVE_COMPOUND_COLOR_OF_DATASET',
APPEND_COLOR_TO_ALL_COMPOUNDS_OF_DATASET: prefix + 'SET_COLOR_TO_ALL_COMPOUNDS_OF_DATASET',
REMOVE_COLOR_FROM_ALL_COMPOUNDS_OF_DATASET: prefix + 'REMOVE_COLOR_FROM_ALL_COMPOUNDS_OF_DATASET',

APPEND_COLOR_TO_SELECTED_COLOR_FILTERS: prefix + 'APPEND_COLOR_TO_SELECTED_COLOR_FILTERS',
REMOVE_COLOR_FROM_SELECTED_COLOR_FILTERS: prefix + 'REMOVE_COLOR_FROM_SELECTED_COLOR_FILTERS',
Expand Down
2 changes: 1 addition & 1 deletion js/components/projects/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,5 +552,5 @@ const getJobOverrides = async () => {
const resultCall = await api({
url: `${base_url}/api/job_override/`
});
return resultCall.data.results[0].override;
return resultCall.data?.results[0]?.override;
};
4 changes: 3 additions & 1 deletion js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export const actionType = {
COMPOUND_REMOVED_FROM_COLOR_GROUP: 'COMPOUND_REMOVED_FROM_COLOR_GROUP',
TAG_DETAIL_VIEW: 'TAG_DETAIL_VIEW',
SELECT_ALL_DATASET_COMPOUNDS: 'SELECT_ALL_DATASET_COMPOUNDS',
SELECTED_SELECT_ALL_BUTTON_FOR_DATASET: 'SELECTED_SELECT_ALL_BUTTON_FOR_DATASET'
SELECTED_SELECT_ALL_BUTTON_FOR_DATASET: 'SELECTED_SELECT_ALL_BUTTON_FOR_DATASET',
ALL_COMPOUNDS_ADDED_TO_COLOR_GROUP: 'ALL_COMPOUNDS_ADDED_TO_COLOR_GROUP',
ALL_COMPOUNDS_REMOVED_FROM_COLOR_GROUP: 'ALL_COMPOUNDS_REMOVED_FROM_COLOR_GROUP'
};

export const snapshotSwitchManualActions = [
Expand Down
Loading

0 comments on commit 411921f

Please sign in to comment.