Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#433' into #455
Browse files Browse the repository at this point in the history
# Conflicts:
#	js/components/snapshot/redux/dispatchActions.js
#	js/reducers/tracking/dispatchActions.js
  • Loading branch information
Adriána Kohanová committed Dec 2, 2020
2 parents d3792b8 + d319bf6 commit 560b23d
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 41 deletions.
46 changes: 34 additions & 12 deletions js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
updateVectorCompounds,
updateBondColorMapOfCompounds,
resetBondColorMapOfVectors,
setCurrentVector
setCurrentVector,
setHideAll
} from '../../../../reducers/selection/actions';
import { base_url } from '../../../routes/constants';
import {
Expand Down Expand Up @@ -115,11 +116,11 @@ const handleVector = (json, stage, data) => (dispatch, getState) => {
dispatch(updateBondColorMapOfCompounds(data.smiles, vectorBondColorMap));
};

export const addVector = (stage, data) => async (dispatch, getState) => {
export const addVector = (stage, data, skipTracking = false) => async (dispatch, getState) => {
const currentVector = getState().selectionReducers.currentVector;

dispatch(incrementCountOfPendingVectorLoadRequests());
dispatch(appendVectorOnList(generateMoleculeId(data)));
dispatch(appendVectorOnList(generateMoleculeId(data), skipTracking));
dispatch(selectVectorAndResetCompounds(currentVector));

return api({ url: getViewUrl('graph', data) })
Expand Down Expand Up @@ -226,7 +227,7 @@ export const removeComplex = (stage, data, colourToggle, skipTracking = false) =
dispatch(removeFromComplexList(generateMoleculeId(data), skipTracking));
};

export const addSurface = (stage, data, colourToggle) => dispatch => {
export const addSurface = (stage, data, colourToggle, skipTracking = false) => dispatch => {
dispatch(
loadObject({
target: Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url)),
Expand All @@ -237,17 +238,17 @@ export const addSurface = (stage, data, colourToggle) => dispatch => {
const currentOrientation = stage.viewerControls.getOrientation();
dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
});
dispatch(appendSurfaceList(generateMoleculeId(data)));
dispatch(appendSurfaceList(generateMoleculeId(data), skipTracking));
};

export const removeSurface = (stage, data, colourToggle) => dispatch => {
export const removeSurface = (stage, data, colourToggle, skipTracking = false) => dispatch => {
dispatch(
deleteObject(
Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url)),
stage
)
);
dispatch(removeFromSurfaceList(generateMoleculeId(data)));
dispatch(removeFromSurfaceList(generateMoleculeId(data), skipTracking));
};

export const addDensity = (stage, data, colourToggle) => dispatch => {
Expand Down Expand Up @@ -330,39 +331,51 @@ export const hideAllSelectedMolecules = (stage, currentMolecules) => (dispatch,
const vectorOnList = state.selectionReducers.vectorOnList;
const surfaceList = state.selectionReducers.surfaceList;
const proteinList = state.selectionReducers.proteinList;
const vectorList = state.selectionReducers.vector_list;

let ligandDataList = [];
let complexDataList = [];
let vectorOnDataList = [];
let surfaceDataList = [];
let proteinDataList = [];

fragmentDisplayList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeLigand(stage, data));
ligandDataList.push(data);
dispatch(removeLigand(stage, data, true));
}
});
complexList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeComplex(stage, data, colourList[0]));
complexDataList.push(data);
dispatch(removeComplex(stage, data, colourList[0], true));
}
});
vectorOnList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeVector(stage, data));
vectorOnDataList.push(data);
dispatch(removeVector(stage, data, true));
}
});

// remove Surface
surfaceList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeSurface(stage, data));
surfaceDataList.push(data);
dispatch(removeSurface(stage, data, colourList[0], true));
}
});

// remove Protein
proteinList.forEach(moleculeId => {
const data = currentMolecules.find(molecule => molecule.id === moleculeId);
if (data) {
dispatch(removeHitProtein(stage, data));
proteinDataList.push(data);
dispatch(removeHitProtein(stage, data, colourList[0], true));
}
});

Expand All @@ -371,6 +384,15 @@ export const hideAllSelectedMolecules = (stage, currentMolecules) => (dispatch,
dispatch(resetCompoundsOfVectors());
dispatch(resetBondColorMapOfVectors());
dispatch(setCompoundImage(noCompoundImage));

let data = {
ligandList: ligandDataList,
proteinList: proteinDataList,
complexList: complexDataList,
surfaceList: surfaceDataList,
vectorOnList: vectorOnDataList
};
dispatch(setHideAll(data));
};

export const searchMoleculeGroupByMoleculeID = moleculeID => (dispatch, getState) =>
Expand Down
2 changes: 0 additions & 2 deletions js/components/preview/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export const shouldLoadProtein = ({
const state = getState();
const targetIdList = state.apiReducers.target_id_list;
const targetOnName = state.apiReducers.target_on_name;
const currentSnapshotData = state.projectReducers.currentSnapshot.data;
// const isLoadingCurrentSnapshot = state.projectReducers.isLoadingCurrentSnapshot;
if (
targetIdList &&
targetIdList.length > 0 &&
Expand Down
17 changes: 11 additions & 6 deletions js/components/snapshot/modals/newSnapshotForm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useState } from 'react';
import React, { memo, useState, useContext } from 'react';
import { Grid, makeStyles, Typography } from '@material-ui/core';
import { useDispatch, useSelector } from 'react-redux';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
Expand All @@ -9,6 +9,8 @@ import { TextField } from 'formik-material-ui';
import { Button } from '../../common/Inputs/Button';
import { SnapshotType } from '../../projects/redux/constants';
import { createNewSnapshot } from '../redux/dispatchActions';
import { NglContext } from '../../nglView/nglProvider';

import moment from 'moment';

const useStyles = makeStyles(theme => ({
Expand All @@ -33,6 +35,7 @@ export const NewSnapshotForm = memo(({ handleCloseModal }) => {
const classes = useStyles();
const [state, setState] = useState();
const dispatch = useDispatch();
const { nglViewList } = useContext(NglContext);

const currentSnapshot = useSelector(state => state.projectReducers.currentSnapshot);
const currentProject = useSelector(state => state.projectReducers.currentProject);
Expand Down Expand Up @@ -70,11 +73,13 @@ export const NewSnapshotForm = memo(({ handleCloseModal }) => {
const parent = isForceProjectCreated === false ? currentSnapshot.id : null;
const session_project = currentProject.projectID;

dispatch(createNewSnapshot({ title, description, type, author, parent, session_project })).catch(error => {
setState(() => {
throw error;
});
});
dispatch(createNewSnapshot({ title, description, type, author, parent, session_project, nglViewList })).catch(
error => {
setState(() => {
throw error;
});
}
);
}}
>
{({ submitForm, isSubmitting }) => (
Expand Down
21 changes: 15 additions & 6 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const createInitSnapshotFromCopy = ({
return Promise.reject('ProjectID is missing');
};

export const createNewSnapshot = ({ title, description, type, author, parent, session_project }) => (
export const createNewSnapshot = ({ title, description, type, author, parent, session_project, nglViewList }) => (
dispatch,
getState
) => {
Expand Down Expand Up @@ -215,7 +215,7 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
}).then(res => {
// redirect to project with newest created snapshot /:projectID/:snapshotID
if (res.data.id && session_project) {
Promise.resolve(dispatch(saveCurrentActionsList(res.data.id, session_project))).then(() => {
Promise.resolve(dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList))).then(() => {
if (disableRedirect === false) {
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
// use react-router !
Expand Down Expand Up @@ -284,7 +284,8 @@ export const createNewSnapshotWithoutStateModification = ({
type,
author,
parent,
session_project
session_project,
nglViewList
}) => (dispatch, getState) => {
if (!session_project) {
return Promise.reject('Project ID is missing!');
Expand Down Expand Up @@ -320,13 +321,13 @@ export const createNewSnapshotWithoutStateModification = ({
disableRedirect: true
})
);
dispatch(saveCurrentActionsList(res.data.id, session_project));
dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList));
}
});
});
};

export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState) => {
export const saveAndShareSnapshot = nglViewList => (dispatch, getState) => {
const state = getState();
const targetId = state.apiReducers.target_on;
const loggedInUserID = DJANGO_CONTEXT['pk'];
Expand Down Expand Up @@ -357,7 +358,15 @@ export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState)
dispatch(sendTrackingActionsByProjectId(projectID, author));

return dispatch(
createNewSnapshotWithoutStateModification({ title, description, type, author, parent, session_project })
createNewSnapshotWithoutStateModification({
title,
description,
type,
author,
parent,
session_project,
nglViewList
})
);
})
.catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion js/components/snapshot/withSnapshotManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const withSnapshotManagement = WrappedComponent => {
startIcon={<Share />}
disabled={disableShareButton || disableUserInteraction}
onClick={() => {
dispatch(saveAndShareSnapshot(target));
dispatch(saveAndShareSnapshot(nglViewList));
}}
>
Share
Expand Down
21 changes: 15 additions & 6 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,19 @@ export const setSurfaceList = function(surfaceList) {
};
};

export const appendSurfaceList = function(item) {
export const appendSurfaceList = function(item, skipTracking = false) {
return {
type: constants.APPEND_SURFACE_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};

export const removeFromSurfaceList = function(item) {
export const removeFromSurfaceList = function(item, skipTracking = false) {
return {
type: constants.REMOVE_FROM_SURFACE_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};

Expand Down Expand Up @@ -156,10 +158,11 @@ export const setVectorOnList = function(vectorOnList) {
};
};

export const appendVectorOnList = function(item) {
export const appendVectorOnList = function(item, skipTracking = false) {
return {
type: constants.APPEND_VECTOR_ON_LIST,
item: item
item: item,
skipTracking: skipTracking
};
};

Expand Down Expand Up @@ -253,3 +256,9 @@ export const setDeselectedAllByType = (type, items, isInspiration) => ({
type: constants.SET_DESELECTED_ALL_BY_TYPE,
payload: { type, items, isInspiration }
});

export const setHideAll = (data, isHide = true) => ({
type: constants.SET_HIDE_ALL,
isHide: isHide,
data: data
});
1 change: 1 addition & 0 deletions js/reducers/selection/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const constants = {
SET_DESELECTED_ALL: prefix + 'SET_DESELECTED_ALL',
SET_SELECTED_ALL_BY_TYPE: prefix + 'SET_SELECTED_ALL_BY_TYPE',
SET_DESELECTED_ALL_BY_TYPE: prefix + 'SET_DESELECTED_ALL_BY_TYPE',
SET_HIDE_ALL: prefix + 'SET_HIDE_ALL',

RESET_COMPOUNDS_OF_VECTORS: prefix + 'RESET_COMPOUNDS_OF_VECTORS',
UPDATE_VECTOR_COMPOUNDS: prefix + 'UPDATE_VECTOR_COMPOUNDS',
Expand Down
4 changes: 4 additions & 0 deletions js/reducers/selection/selectionReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {
return Object.assign({}, state, {
moleculeAllTypeSelection: action.payload.type
});

case constants.SET_HIDE_ALL:
return state;

// Cases like: @@redux/INIT
default:
return state;
Expand Down
4 changes: 4 additions & 0 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export const actionType = {
REPRESENTATION_CHANGED: 'REPRESENTATION_CHANGED',
REPRESENTATION_ADDED: 'REPRESENTATION_ADDED',
REPRESENTATION_REMOVED: 'REPRESENTATION_REMOVED',
NGL_STATE: 'NGL_STATE',
UNDO: 'UNDO',
REDO: 'REDO',
ALL_HIDE: 'ALL_HIDE',
ALL_TURNED_ON: 'ALL_TURNED_ON',
ALL_TURNED_OFF: 'ALL_TURNED_OFF',
ALL_TURNED_ON_BY_TYPE: 'ALL_TURNED_ON_BY_TYPE',
Expand All @@ -54,6 +56,8 @@ export const actionDescription = {
TURNED_OFF: 'was turned off',
SELECTED: 'was selected',
DESELECTED: 'was deselected',
HIDDEN: 'hidden',
CANCELED: 'canceled',
ADDED: 'was added',
REMOVED: 'was removed',
CHANGED: 'was changed',
Expand Down
Loading

0 comments on commit 560b23d

Please sign in to comment.