Skip to content

Commit

Permalink
#116 restore preview reducer from session
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 2, 2020
1 parent d511d83 commit 38ff7e6
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion js/components/preview/compounds/compoundList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by abradley on 15/03/2018.
*/
import React, { memo, useContext, useRef } from 'react';
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { CompoundView } from './compoundView';
import { Panel } from '../../common/Surfaces/Panel';
import { Button } from '../../common/Inputs/Button';
Expand Down
6 changes: 6 additions & 0 deletions js/components/preview/compounds/redux/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { constants } from './constants';
import { compounds } from './reducer';

export const setCurrentCompounds = loadedCompounds => ({
type: constants.SET_CURRENT_COMPOUNDS,
Expand Down Expand Up @@ -74,3 +75,8 @@ export const removeSelectedCompoundClass = compoundID => ({
export const resetSelectedCompoundClass = () => ({
type: constants.RESET_SELECTED_COMPOUND_CLASS
});

export const reloadCompoundsReducer = newState => ({
type: constants.RELOAD_REDUCER,
payload: newState
});
4 changes: 3 additions & 1 deletion js/components/preview/compounds/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const constants = {

APPEND_SELECTED_COMPOUND_CLASS: prefix + 'APPEND_SELECTED_COMPOUND_CLASS',
REMOVE_SELECTED_COMPOUND_CLASS: prefix + 'REMOVE_SELECTED_COMPOUND_CLASS',
RESET_SELECTED_COMPOUND_CLASS: prefix + 'RESET_SELECTED_COMPOUND_CLASS'
RESET_SELECTED_COMPOUND_CLASS: prefix + 'RESET_SELECTED_COMPOUND_CLASS',

RELOAD_REDUCER: prefix + 'RELOAD_REDUCER'
};

const colors = {
Expand Down
3 changes: 3 additions & 0 deletions js/components/preview/compounds/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export const compounds = (state = INITIAL_STATE, action = {}) => {
selectedCompoundsClass: defaultSelectedCmpdsClass
});

case constants.RELOAD_REDUCER:
return Object.assign({}, state, { ...action.payload });

default:
return state;
}
Expand Down
7 changes: 1 addition & 6 deletions js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { Grid, Chip, Tooltip, makeStyles, CircularProgress, Divider, Typography } from '@material-ui/core';
import { FilterList } from '@material-ui/icons';
import React, { useState, useEffect, memo, useRef, useContext } from 'react';
import React, { useState, useEffect, memo, useRef } from 'react';
import { connect } from 'react-redux';
import * as apiActions from '../../../reducers/api/actions';
import * as listType from '../../../constants/listTypes';
Expand All @@ -19,8 +19,6 @@ import { Panel } from '../../common/Surfaces/Panel';
import { ComputeSize } from '../../../utils/computeSize';
import { moleculeProperty } from './helperConstants';
import { setSortDialogOpen } from './redux/actions';
import { VIEWS } from '../../../constants/constants';
import { NglContext } from '../../nglView/nglProvider';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -122,9 +120,6 @@ const MoleculeList = memo(
const imgHeight = 34;
const imgWidth = 150;

const { getNglView } = useContext(NglContext);
const stage = getNglView(VIEWS.MAJOR_VIEW) && getNglView(VIEWS.MAJOR_VIEW).stage;

const isActiveFilter = !!(filterSettings || {}).active;

const filterRef = useRef();
Expand Down
5 changes: 5 additions & 0 deletions js/components/preview/molecule/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ export const setSortDialogOpen = isOpen => ({
type: constants.SET_SORT_DIALOG_OPEN,
payload: isOpen
});

export const reloadMoleculeReducer = newState => ({
type: constants.SET_SORT_DIALOG_OPEN,
payload: newState
});
4 changes: 3 additions & 1 deletion js/components/preview/molecule/redux/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const prefix = 'PREVIEW_MOLECULE_';

export const constants = {
SET_SORT_DIALOG_OPEN: prefix + 'SET_SORT_DIALOG_OPEN'
SET_SORT_DIALOG_OPEN: prefix + 'SET_SORT_DIALOG_OPEN',

RELOAD_REDUCER: prefix + 'RELOAD_REDUCER'
};
3 changes: 3 additions & 0 deletions js/components/preview/molecule/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export const molecule = (state = INITIAL_STATE, action = {}) => {
sortDialogOpen: action.payload
});

case constants.RELOAD_REDUCER:
return Object.assign({}, state, { ...action.payload });

default:
return state;
}
Expand Down
9 changes: 9 additions & 0 deletions js/components/preview/redux/dispatchActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { generateProteinObject } from '../../nglView/generatingObjects';
import { SUFFIX, VIEWS } from '../../../constants/constants';
import { loadObject, setProteinsHasLoaded, setOrientation } from '../../../reducers/ngl/dispatchActions';
import { reloadSummaryReducer } from '../summary/redux/actions';
import { reloadCompoundsReducer } from '../compounds/redux/actions';
import { reloadMoleculeReducer } from '../molecule/redux/actions';

const loadProtein = nglView => (dispatch, getState) => {
const state = getState();
Expand Down Expand Up @@ -52,3 +55,9 @@ export const shouldLoadProtein = (nglViewList, isStateLoaded) => (dispatch, getS
}
}
};

export const reloadPreviewReducer = newState => dispatch => {
dispatch(reloadSummaryReducer(newState.summary));
dispatch(reloadCompoundsReducer(newState.compounds));
// dispatch(reloadMoleculeReducer(newState.molecule));
};
2 changes: 2 additions & 0 deletions js/components/preview/summary/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export const setCountOfExploredVectors = count => ({ type: constants.SET_COUNT_O
export const setCountOfExploredSeries = count => ({ type: constants.SET_COUNT_OF_EXPLORED_SERIES, payload: count });
export const setEstimatedCost = count => ({ type: constants.SET_ESTIMATED_COST, payload: count });
export const setSelectedInteraction = count => ({ type: constants.SET_SELECTED_INTERACTION, payload: count });

export const reloadSummaryReducer = newState => ({ type: constants.RELOAD_REDUCER, payload: newState });
4 changes: 3 additions & 1 deletion js/components/preview/summary/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ export const constants = {
SET_COUNT_OF_EXPLORED_VECTORS: prefix + 'SET_COUNT_OF_EXPLORED_VECTORS',
SET_COUNT_OF_EXPLORED_SERIES: prefix + 'SET_COUNT_OF_EXPLORED_SERIES',
SET_ESTIMATED_COST: prefix + 'SET_ESTIMATED_COST',
SET_SELECTED_INTERACTION: prefix + 'SET_SELECTED_INTERACTION'
SET_SELECTED_INTERACTION: prefix + 'SET_SELECTED_INTERACTION',

RELOAD_REDUCER: prefix + 'RELOAD_REDUCER'
};
3 changes: 3 additions & 0 deletions js/components/preview/summary/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const summary = (state = INITIAL_STATE, action = {}) => {
case constants.SET_SELECTED_INTERACTION:
return Object.assign({}, state, { selectedInteraction: action.payload });

case constants.RELOAD_REDUCER:
return Object.assign({}, state, { ...action.payload });

default:
return state;
}
Expand Down
13 changes: 12 additions & 1 deletion js/components/session/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import { savingStateConst, savingTypeConst } from '../constants';
import { setLoadedSession, setNewSessionFlag, setNextUUID, setSaveType } from './actions';
import { getStore } from '../../helpers/globalStore';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import apiReducers from '../../../reducers/api/apiReducers';
import nglReducers from '../../../reducers/ngl/nglReducers';
import selectionReducers from '../../../reducers/selection/selectionReducers';
import { targetReducers } from '../../target/redux/reducer';
import { sessionReducers } from './reducer';
import { previewReducers } from '../../preview/redux';
import { issueReducers } from '../../userFeedback/redux/reducer';
import { reloadPreviewReducer } from '../../preview/redux/dispatchActions';

export const handleVector = json => dispatch => {
let objList = generateObjectList(json['3d']);
Expand Down Expand Up @@ -53,6 +61,8 @@ export const reloadSession = (myJson, nglViewList) => dispatch => {
dispatch(redeployVectorsLocal(url)).catch(error => {
throw new Error(error);
});

dispatch(reloadPreviewReducer(jsonOfView.previewReducers));
}
}
};
Expand Down Expand Up @@ -168,7 +178,8 @@ export const reloadScene = ({ saveType, newSessionFlag, nextUuid, uuid, sessionI
state: JSON.stringify({
apiReducers: newPresentObject,
nglReducers: stateObject.nglReducers,
selectionReducers: stateObject.selectionReducers
selectionReducers: stateObject.selectionReducers,
previewReducers: stateObject.previewReducers
})
};

Expand Down

0 comments on commit 38ff7e6

Please sign in to comment.