Skip to content

Commit

Permalink
#455 Store and retrieve snapshot actions in/from the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Dec 1, 2020
1 parent 156565d commit d3792b8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
42 changes: 21 additions & 21 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,27 @@ 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));

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 !
window.location.replace(
`${URLS.projects}${session_project}/${
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
}`
);
} else {
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(
setSharedSnapshot({
title,
description,
url: `${base_url}${URLS.projects}${session_project}/${res.data.id}`
})
);
}
Promise.resolve(dispatch(saveCurrentActionsList(res.data.id, session_project))).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 !
window.location.replace(
`${URLS.projects}${session_project}/${
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
}`
);
} else {
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(
setSharedSnapshot({
title,
description,
url: `${base_url}${URLS.projects}${session_project}/${res.data.id}`
})
);
}
});
}
});
})
Expand Down
33 changes: 23 additions & 10 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
onDeselectMoleculeGroup,
loadMoleculeGroupsOfTarget
} from '../../components/preview/moleculeGroups/redux/dispatchActions';
import { loadTargetList } from '../../components/target/redux/dispatchActions';
import { resetTargetState, setTargetOn } from '../api/actions';
import {
addComplex,
Expand Down Expand Up @@ -81,11 +82,9 @@ import {
setDeselectedAllByType as setDeselectedAllByTypeOfDataset
} from '../../components/datasets/redux/actions';

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

export const saveActionsList = (snapshotID, actionList) => (dispatch, getState) => {
Expand Down Expand Up @@ -311,6 +310,10 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
};

export const resetRestoringState = (stages = []) => (dispatch, getState) => {
dispatch(setActionsList([]));
dispatch(setProjectActionList([]));
dispatch(setSendActionsList([]));

dispatch(setTargetOn(undefined));
dispatch(setIsActionsRestoring(false, false));
};
Expand All @@ -320,8 +323,8 @@ export const restoreCurrentActionsList = (stages = []) => (dispatch, getState) =
Promise.resolve(dispatch(restoreTrackingActions())).then(response => {
dispatch(setIsTrackingMoleculesRestoring(true));
dispatch(setIsTrackingCompoundsRestoring(true));
dispatch(unmountPreviewComponent(stages));
dispatch(resetTargetState());
dispatch(unmountPreviewComponent(stages));
dispatch(restoreStateBySavedActionList(stages));
});
};
Expand Down Expand Up @@ -360,7 +363,15 @@ const restoreStateBySavedActionList = stages => (dispatch, getState) => {
const currentActionList = state.trackingReducers.current_actions_list;
const orderedActionList = currentActionList.sort((a, b) => a.timestamp - b.timestamp);

dispatch(restoreTargetActions(orderedActionList, stages));
let onCancel = () => {};
dispatch(loadTargetList(onCancel))
.then(() => dispatch(restoreTargetActions(orderedActionList, stages)))
.catch(error => {
throw new Error(error);
});
return () => {
onCancel();
};
};

const restoreTargetActions = (orderedActionList, stages) => (dispatch, getState) => {
Expand Down Expand Up @@ -1280,7 +1291,7 @@ export const checkSendTrackingActions = (save = false) => (dispatch, getState) =
}
};

const sendTrackingActions = (sendActions, project) => (dispatch, getState) => {
const sendTrackingActions = (sendActions, project, clear = true) => (dispatch, getState) => {
if (project) {
const projectID = project && project.projectID;

Expand All @@ -1299,7 +1310,9 @@ const sendTrackingActions = (sendActions, project) => (dispatch, getState) => {
data: JSON.stringify(dataToSend)
})
.then(() => {
dispatch(setSendActionsList([]));
if (clear === true) {
dispatch(setSendActionsList([]));
}
})
.catch(error => {
throw new Error(error);
Expand Down Expand Up @@ -1381,7 +1394,7 @@ const copyActionsToProject = (toProject, setActionList = true) => (dispatch, get
if (setActionList === true) {
dispatch(setActionsList(newActionsList));
}
dispatch(sendTrackingActions(newActionsList, toProject));
dispatch(sendTrackingActions(newActionsList, toProject, false));
}
};

Expand Down

0 comments on commit d3792b8

Please sign in to comment.