Skip to content

Commit

Permalink
xchem#41 reset objects from nglView and showedCompoundList
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 10, 2020
1 parent 2e0eb03 commit 9ac052f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
12 changes: 10 additions & 2 deletions js/components/preview/compounds/compoundList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Created by abradley on 15/03/2018.
*/
import React, { memo, useRef } from 'react';
import React, { memo, useContext, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { CompoundView } from './compoundView';
import { Panel } from '../../common/Surfaces/Panel';
Expand All @@ -18,6 +18,8 @@ import { compoundsColors } from './redux/constants';
import { getTotalCountOfMolecules } from '../../../reducers/selection/selectors';
import InfiniteScroll from 'react-infinite-scroller';
import { getCanLoadMoreCompounds, getCompoundListOffset } from './redux/selectors';
import { NglContext } from '../../nglView/nglProvider';
import { VIEWS } from '../../../constants/constants';

const useStyles = makeStyles(theme => ({
textField: {
Expand All @@ -42,6 +44,8 @@ export const CompoundList = memo(({ height }) => {
const panelRef = useRef(null);
const theme = useTheme();
const dispatch = useDispatch();
const { getNglView } = useContext(NglContext);
const majorViewStage = getNglView(VIEWS.MAJOR_VIEW).stage;

const to_query = useSelector(state => state.selectionReducers.to_query);
const compoundClasses = useSelector(state => state.previewReducers.compounds.compoundClasses);
Expand Down Expand Up @@ -115,7 +119,11 @@ export const CompoundList = memo(({ height }) => {
<Button color="primary" onClick={() => dispatch(selectAllCompounds())} startIcon={<SelectAll />}>
Select All
</Button>
<Button color="primary" onClick={() => dispatch(clearAllSelectedCompounds())} startIcon={<Delete />}>
<Button
color="primary"
onClick={() => dispatch(clearAllSelectedCompounds(majorViewStage))}
startIcon={<Delete />}
>
Clear Selection
</Button>
</Box>
Expand Down
4 changes: 0 additions & 4 deletions js/components/preview/compounds/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ export const removeSelectedCompoundClass = compoundID => ({
type: constants.REMOVE_SELECTED_COMPOUND_CLASS,
payload: compoundID
});

export const resetCompoundsToPick = () => ({
type: constants.RESET_COMPOUNDS_TO_PICK
});
3 changes: 1 addition & 2 deletions js/components/preview/compounds/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const constants = {
REMOVE_SHOWED_COMPOUND_LIST: prefix + 'REMOVE_SHOWED_COMPOUND_LIST',

APPEND_SELECTED_COMPOUND_CLASS: prefix + 'APPEND_SELECTED_COMPOUND_CLASS',
REMOVE_SELECTED_COMPOUND_CLASS: prefix + 'REMOVE_SELECTED_COMPOUND_CLASS',
RESET_COMPOUNDS_TO_PICK: prefix + 'RESET_COMPOUNDS_TO_PICK'
REMOVE_SELECTED_COMPOUND_CLASS: prefix + 'REMOVE_SELECTED_COMPOUND_CLASS'
};

const colors = {
Expand Down
25 changes: 18 additions & 7 deletions js/components/preview/compounds/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
addShowedCompoundToList,
removeShowedCompoundFromList,
removeSelectedCompoundClass,
addSelectedCompoundClass,
resetCompoundsToPick
addSelectedCompoundClass
} from './actions';
import { deleteObject, loadObject } from '../../../../reducers/ngl/dispatchActions';
import { VIEWS } from '../../../../constants/constants';
Expand Down Expand Up @@ -41,11 +40,6 @@ export const selectAllCompounds = () => (dispatch, getState) => {
}
};

export const clearAllSelectedCompounds = () => dispatch => {
dispatch(setToBuyList([]));
dispatch(resetCompoundsToPick());
};

export const onChangeCompoundClassValue = event => (dispatch, getState) => {
const state = getState();
const compoundClasses = state.previewReducers.compounds.compoundClasses;
Expand Down Expand Up @@ -115,6 +109,23 @@ const showCompoundNglView = ({ majorViewStage, data, index }) => (dispatch, getS
}
};

export const clearAllSelectedCompounds = majorViewStage => (dispatch, getState) => {
dispatch(setToBuyList([]));
const state = getState();
// reset objects from nglView and showedCompoundList
const currentCompounds = state.previewReducers.compounds.currentCompounds;
const showedCompoundList = state.previewReducers.compounds.showedCompoundList;
showedCompoundList.forEach(index => {
const data = currentCompounds[index];
dispatch(showCompoundNglView({ majorViewStage, data, index }));
});
// TODO reset compoundsClasses
// TODO reset selectedCompoundsClass
// TODO reset highlightedCompoundId
// TODO reset compoundClasses
// TODO reset configuration
};

export const handleClickOnCompound = ({ data, event, majorViewStage, index }) => async (dispatch, getState) => {
const state = getState();
const currentCompoundClass = state.previewReducers.compounds.currentCompoundClass;
Expand Down
3 changes: 0 additions & 3 deletions js/components/preview/compounds/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ export const compounds = (state = INITIAL_STATE, action = {}) => {
selectedCompoundsClass: diminishedSelectedCmpdClass
});

case constants.RESET_COMPOUNDS_TO_PICK:
return Object.assign({}, INITIAL_STATE);

default:
return state;
}
Expand Down

0 comments on commit 9ac052f

Please sign in to comment.