Skip to content

Commit

Permalink
#125 fix undefined stage
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 2, 2020
1 parent 7330655 commit 2778785
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
41 changes: 20 additions & 21 deletions js/components/nglView/nglView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,32 @@ const NglView = memo(({ div_id, height, setOrientation, removeAllNglComponents,

const registerStageEvents = useCallback(
(newStage, getNglView) => {
window.addEventListener('resize', handleResize);
newStage.mouseControls.add('clickPick-left', (stage, pickingProxy) => {
if (stage) {
return handleNglViewPick(stage, pickingProxy, getNglView, setError);
}
});
if (newStage) {
window.addEventListener('resize', handleResize);
newStage.mouseControls.add('clickPick-left', (st, pickingProxy) =>
handleNglViewPick(st, pickingProxy, getNglView, setError)
);

newStage.mouseObserver.signals.scrolled.add(handleOrientationChanged);
newStage.mouseObserver.signals.dropped.add(handleOrientationChanged);
newStage.mouseObserver.signals.dragged.add(handleOrientationChanged);
newStage.mouseObserver.signals.scrolled.add(handleOrientationChanged);
newStage.mouseObserver.signals.dropped.add(handleOrientationChanged);
newStage.mouseObserver.signals.dragged.add(handleOrientationChanged);
}
},
[handleResize, handleOrientationChanged, handleNglViewPick, setError]
);

const unregisterStageEvents = useCallback(
(stage, getNglView) => {
window.addEventListener('resize', handleResize);
window.removeEventListener('resize', handleResize);
stage.mouseControls.remove('clickPick-left', (stage, pickingProxy) => {
if (stage) {
return handleNglViewPick(stage, pickingProxy, getNglView, setError);
}
});

stage.mouseObserver.signals.scrolled.remove(handleOrientationChanged);
stage.mouseObserver.signals.dropped.remove(handleOrientationChanged);
stage.mouseObserver.signals.dragged.remove(handleOrientationChanged);
(newStage, getNglView) => {
if (newStage) {
window.addEventListener('resize', handleResize);
window.removeEventListener('resize', handleResize);
newStage.mouseControls.remove('clickPick-left', (st, pickingProxy) =>
handleNglViewPick(st, pickingProxy, getNglView, setError)
);
newStage.mouseObserver.signals.scrolled.remove(handleOrientationChanged);
newStage.mouseObserver.signals.dropped.remove(handleOrientationChanged);
newStage.mouseObserver.signals.dragged.remove(handleOrientationChanged);
}
},
[handleResize, handleOrientationChanged, handleNglViewPick, setError]
);
Expand Down
6 changes: 3 additions & 3 deletions js/components/nglView/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const processInt = pickingProxy => {

export const handleNglViewPick = (stage, pickingProxy, getNglView, setError) => (dispatch, getState) => {
const state = getState();
if (pickingProxy) {
if (pickingProxy && stage) {
// For assigning the ligand interaction
if (pickingProxy.bond) {
const duck_yank_data = state.apiReducers.duck_yank_data;
Expand Down Expand Up @@ -115,9 +115,9 @@ export const handleNglViewPick = (stage, pickingProxy, getNglView, setError) =>
// Ok so now perform logic
const type = name.split('_')[0];
const pk = parseInt(name.split('_')[1], 10);
if (type === OBJECT_TYPE.MOLECULE_GROUP) {
if (type === OBJECT_TYPE.MOLECULE_GROUP && getNglView(VIEWS.MAJOR_VIEW)) {
dispatch(toggleMoleculeGroup(pk, stage, getNglView(VIEWS.MAJOR_VIEW).stage), setError);
} else if (type === OBJECT_TYPE.MOLGROUPS_SELECT) {
} else if (type === OBJECT_TYPE.MOLGROUPS_SELECT && getNglView(VIEWS.MAJOR_VIEW)) {
dispatch(toggleMoleculeGroup(pk, stage, getNglView(VIEWS.MAJOR_VIEW).stage), setError);
} else if (type === listTypes.PANDDA_SITE) {
dispatch(setPanddaSiteOn(pk));
Expand Down
2 changes: 1 addition & 1 deletion js/components/preview/compounds/compoundList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
selectAllCompounds
} from './redux/dispatchActions';
import { compoundsColors } from './redux/constants';
import { getTotalCountOfMolecules } from '../../../reducers/selection/selectors';
// import { getTotalCountOfMolecules } from '../../../reducers/selection/selectors';
import InfiniteScroll from 'react-infinite-scroller';
import { getCanLoadMoreCompounds, getCompoundClasses, getCompoundListOffset } from './redux/selectors';
import { NglContext } from '../../nglView/nglProvider';
Expand Down
8 changes: 6 additions & 2 deletions js/components/preview/compounds/compoundView.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const CompoundView = memo(({ height, width, data, index }) => {
const showedCompoundList = useSelector(state => state.previewReducers.compounds.showedCompoundList);
const selectedCompoundsClass = useSelector(state => state.previewReducers.compounds.selectedCompoundsClass);
const { getNglView } = useContext(NglContext);
const majorViewStage = getNglView(VIEWS.MAJOR_VIEW).stage;
const majorViewStage = getNglView(VIEWS.MAJOR_VIEW) && getNglView(VIEWS.MAJOR_VIEW).stage;
const [image, setImage] = useState(loadingCompoundImage);

const { setError } = useContext(HeaderContext);
Expand Down Expand Up @@ -63,7 +63,11 @@ export const CompoundView = memo(({ height, width, data, index }) => {

return (
<div
onClick={event => dispatch(handleClickOnCompound({ event, data, majorViewStage, index, setError }))}
onClick={event => {
if (majorViewStage) {
dispatch(handleClickOnCompound({ event, data, majorViewStage, index, setError }));
}
}}
style={current_style}
>
<SVGInline svg={image} />
Expand Down

0 comments on commit 2778785

Please sign in to comment.