Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#433' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Dec 2, 2020
2 parents 9d6f428 + d319bf6 commit e9c7bb9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
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) {
dispatch(saveCurrentActionsList(res.data.id, session_project));
dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList));

if (disableRedirect === false) {
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
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
1 change: 1 addition & 0 deletions js/reducers/tracking/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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',
Expand Down
40 changes: 33 additions & 7 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
} from '../../../js/reducers/ngl/actions';
import * as listType from '../../constants/listTypes';
import { assignRepresentationToComp } from '../../components/nglView/generatingObjects';
import { deleteObject } from '../../../js/reducers/ngl/dispatchActions';
import { deleteObject, setOrientation } from '../../../js/reducers/ngl/dispatchActions';
import { setSendActionsList, setIsActionsSending, setIsActionsLoading, setActionsList } from './actions';
import { api, METHOD } from '../../../js/utils/api';
import { base_url } from '../../components/routes/constants';
Expand All @@ -81,14 +81,14 @@ import {
setDeselectedAllByType as setDeselectedAllByTypeOfDataset
} from '../../components/datasets/redux/actions';

export const saveCurrentActionsList = (snapshotID, projectID) => (dispatch, getState) => {
export const saveCurrentActionsList = (snapshotID, projectID, nglViewList) => (dispatch, getState) => {
Promise.resolve(dispatch(getTrackingActions(projectID))).then(response => {
let actionList = response;
dispatch(saveActionsList(snapshotID, actionList));
dispatch(saveActionsList(snapshotID, actionList, nglViewList));
});
};

export const saveActionsList = (snapshotID, actionList) => (dispatch, getState) => {
export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatch, getState) => {
const state = getState();

const currentTargetOn = state.apiReducers.target_on;
Expand Down Expand Up @@ -208,6 +208,18 @@ export const saveActionsList = (snapshotID, actionList) => (dispatch, getState)
currentActions
);

let nglStateList = nglViewList.map(nglView => {
return { id: nglView.id, orientation: nglView.stage.viewerControls.getOrientation() };
});

let trackAction = {
type: actionType.NGL_STATE,
timestamp: Date.now(),
nglStateList: nglStateList
};

currentActions.push(Object.assign({ ...trackAction }));

dispatch(setCurrentActionsList(currentActions));
dispatch(saveTrackingActions(currentActions, snapshotID));
};
Expand Down Expand Up @@ -310,10 +322,11 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
return list;
};

export const resetRestoringState = (stages = []) => (dispatch, getState) => {
export const resetRestoringState = () => (dispatch, getState) => {
dispatch(setTargetOn(undefined));
dispatch(setIsActionsRestoring(false, false));
};

export const restoreCurrentActionsList = (stages = []) => (dispatch, getState) => {
dispatch(setIsActionsRestoring(true, false));

Expand Down Expand Up @@ -408,10 +421,24 @@ export const restoreAfterTargetActions = (stages, projectId) => async (dispatch,
await dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage));
await dispatch(restoreRepresentationActions(orderedActionList, stages));
await dispatch(restoreProject(projectId));
dispatch(restoreNglStateAction(orderedActionList, stages));
dispatch(setIsActionsRestoring(false, true));
}
};

const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState) => {
let action = orderedActionList.find(action => action.type === actionType.NGL_STATE);
if (action && action.nglStateList) {
action.nglStateList.forEach(nglView => {
dispatch(setOrientation(nglView.id, nglView.orientation));
let viewStage = stages.find(s => s.id === nglView.id);
if (viewStage) {
viewStage.stage.viewerControls.orient(nglView.orientation.elements);
}
});
}
};

const loadAllDatasets = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
dispatch(setMoleculeListIsLoading(true));
await dispatch(loadDataSets(target_on))
Expand Down Expand Up @@ -1448,11 +1475,10 @@ const copyActionsToProject = (toProject, setActionList = true) => (dispatch, get
const actionList = state.trackingReducers.project_actions_list;

if (toProject) {
let newProject = { projectID: toProject.projectID, authorID: toProject.authorID };
let newActionsList = [];

actionList.forEach(r => {
newActionsList.push(Object.assign({ ...r, project: newProject }));
newActionsList.push(Object.assign({ ...r }));
});

if (setActionList === true) {
Expand Down

0 comments on commit e9c7bb9

Please sign in to comment.