Skip to content

Commit 078a39f

Browse files
Merge remote-tracking branch 'remotes/origin/#455' into allfunctionality
2 parents e9c7bb9 + f9e532e commit 078a39f

File tree

2 files changed

+62
-46
lines changed

2 files changed

+62
-46
lines changed

js/components/snapshot/redux/dispatchActions.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -215,27 +215,27 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
215215
}).then(res => {
216216
// redirect to project with newest created snapshot /:projectID/:snapshotID
217217
if (res.data.id && session_project) {
218-
dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList));
219-
220-
if (disableRedirect === false) {
221-
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
222-
// use react-router !
223-
window.location.replace(
224-
`${URLS.projects}${session_project}/${
225-
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
226-
}`
227-
);
228-
} else {
229-
dispatch(setOpenSnapshotSavingDialog(false));
230-
dispatch(setIsLoadingSnapshotDialog(false));
231-
dispatch(
232-
setSharedSnapshot({
233-
title,
234-
description,
235-
url: `${base_url}${URLS.projects}${session_project}/${res.data.id}`
236-
})
237-
);
238-
}
218+
Promise.resolve(dispatch(saveCurrentActionsList(res.data.id, session_project, nglViewList))).then(() => {
219+
if (disableRedirect === false) {
220+
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
221+
// use react-router !
222+
window.location.replace(
223+
`${URLS.projects}${session_project}/${
224+
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
225+
}`
226+
);
227+
} else {
228+
dispatch(setOpenSnapshotSavingDialog(false));
229+
dispatch(setIsLoadingSnapshotDialog(false));
230+
dispatch(
231+
setSharedSnapshot({
232+
title,
233+
description,
234+
url: `${base_url}${URLS.projects}${session_project}/${res.data.id}`
235+
})
236+
);
237+
}
238+
});
239239
}
240240
});
241241
})

js/reducers/tracking/dispatchActions.js

+41-25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
onDeselectMoleculeGroup,
1515
loadMoleculeGroupsOfTarget
1616
} from '../../components/preview/moleculeGroups/redux/dispatchActions';
17+
import { loadTargetList } from '../../components/target/redux/dispatchActions';
1718
import { resetTargetState, setTargetOn } from '../api/actions';
1819
import {
1920
addComplex,
@@ -81,11 +82,9 @@ import {
8182
setDeselectedAllByType as setDeselectedAllByTypeOfDataset
8283
} from '../../components/datasets/redux/actions';
8384

84-
export const saveCurrentActionsList = (snapshotID, projectID, nglViewList) => (dispatch, getState) => {
85-
Promise.resolve(dispatch(getTrackingActions(projectID))).then(response => {
86-
let actionList = response;
87-
dispatch(saveActionsList(snapshotID, actionList, nglViewList));
88-
});
85+
export const saveCurrentActionsList = (snapshotID, projectID, nglViewList) => async (dispatch, getState) => {
86+
let actionList = await dispatch(getTrackingActions(projectID));
87+
dispatch(saveActionsList(snapshotID, actionList, nglViewList));
8988
};
9089

9190
export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatch, getState) => {
@@ -95,15 +94,15 @@ export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatc
9594
const currentSites = state.selectionReducers.mol_group_selection;
9695
const currentLigands = state.selectionReducers.fragmentDisplayList;
9796
const currentProteins = state.selectionReducers.proteinList;
98-
const currentComplexes = state.selectionReducers.complexLists;
97+
const currentComplexes = state.selectionReducers.complexList;
9998
const currentSurfaces = state.selectionReducers.surfaceList;
10099
const currentVectors = state.selectionReducers.vectorOnList;
101100
const currentBuyList = state.selectionReducers.to_buy_list;
102101
const currentVector = state.selectionReducers.currentVector;
103102
const currentSelectionAll = state.selectionReducers.moleculeAllSelection;
104103

105104
const currentDatasetLigands = state.datasetsReducers.ligandLists;
106-
const currentDatasetProteins = state.datasetsReducers.proteinList;
105+
const currentDatasetProteins = state.datasetsReducers.proteinLists;
107106
const currentDatasetComplexes = state.datasetsReducers.complexLists;
108107
const currentDatasetSurfaces = state.datasetsReducers.surfaceLists;
109108
const currentDatasetSelectionAll = state.datasetsReducers.moleculeAllSelection;
@@ -208,17 +207,19 @@ export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatc
208207
currentActions
209208
);
210209

211-
let nglStateList = nglViewList.map(nglView => {
212-
return { id: nglView.id, orientation: nglView.stage.viewerControls.getOrientation() };
213-
});
210+
if (nglViewList) {
211+
let nglStateList = nglViewList.map(nglView => {
212+
return { id: nglView.id, orientation: nglView.stage.viewerControls.getOrientation() };
213+
});
214214

215-
let trackAction = {
216-
type: actionType.NGL_STATE,
217-
timestamp: Date.now(),
218-
nglStateList: nglStateList
219-
};
215+
let trackAction = {
216+
type: actionType.NGL_STATE,
217+
timestamp: Date.now(),
218+
nglStateList: nglStateList
219+
};
220220

221-
currentActions.push(Object.assign({ ...trackAction }));
221+
currentActions.push(Object.assign({ ...trackAction }));
222+
}
222223

223224
dispatch(setCurrentActionsList(currentActions));
224225
dispatch(saveTrackingActions(currentActions, snapshotID));
@@ -323,6 +324,10 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
323324
};
324325

325326
export const resetRestoringState = () => (dispatch, getState) => {
327+
dispatch(setActionsList([]));
328+
dispatch(setProjectActionList([]));
329+
dispatch(setSendActionsList([]));
330+
326331
dispatch(setTargetOn(undefined));
327332
dispatch(setIsActionsRestoring(false, false));
328333
};
@@ -333,8 +338,8 @@ export const restoreCurrentActionsList = (stages = []) => (dispatch, getState) =
333338
Promise.resolve(dispatch(restoreTrackingActions())).then(response => {
334339
dispatch(setIsTrackingMoleculesRestoring(true));
335340
dispatch(setIsTrackingCompoundsRestoring(true));
336-
dispatch(unmountPreviewComponent(stages));
337341
dispatch(resetTargetState());
342+
dispatch(unmountPreviewComponent(stages));
338343
dispatch(restoreStateBySavedActionList(stages));
339344
});
340345
};
@@ -373,7 +378,15 @@ const restoreStateBySavedActionList = stages => (dispatch, getState) => {
373378
const currentActionList = state.trackingReducers.current_actions_list;
374379
const orderedActionList = currentActionList.sort((a, b) => a.timestamp - b.timestamp);
375380

376-
dispatch(restoreTargetActions(orderedActionList, stages));
381+
let onCancel = () => {};
382+
dispatch(loadTargetList(onCancel))
383+
.then(() => dispatch(restoreTargetActions(orderedActionList, stages)))
384+
.catch(error => {
385+
throw new Error(error);
386+
});
387+
return () => {
388+
onCancel();
389+
};
377390
};
378391

379392
const restoreTargetActions = (orderedActionList, stages) => (dispatch, getState) => {
@@ -512,7 +525,7 @@ const restoreMoleculesActions = (orderedActionList, stage) => (dispatch, getStat
512525
dispatch(addNewType(moleculesAction, actionType.SIDECHAINS_TURNED_ON, 'protein', stage, state));
513526
dispatch(addNewType(moleculesAction, actionType.INTERACTIONS_TURNED_ON, 'complex', stage, state));
514527
dispatch(addNewType(moleculesAction, actionType.SURFACE_TURNED_ON, 'surface', stage, state));
515-
dispatch(addNewType(moleculesAction, actionType.VECTOR_SELECTED, 'vector', stage, state));
528+
dispatch(addNewType(moleculesAction, actionType.VECTORS_TURNED_ON, 'vector', stage, state));
516529
}
517530

518531
let vectorAction = orderedActionList.find(action => action.type === actionType.VECTOR_SELECTED);
@@ -1384,7 +1397,7 @@ export const checkSendTrackingActions = (save = false) => (dispatch, getState) =
13841397
}
13851398
};
13861399

1387-
const sendTrackingActions = (sendActions, project) => (dispatch, getState) => {
1400+
const sendTrackingActions = (sendActions, project, clear = true) => (dispatch, getState) => {
13881401
if (project) {
13891402
const projectID = project && project.projectID;
13901403

@@ -1403,7 +1416,9 @@ const sendTrackingActions = (sendActions, project) => (dispatch, getState) => {
14031416
data: JSON.stringify(dataToSend)
14041417
})
14051418
.then(() => {
1406-
dispatch(setSendActionsList([]));
1419+
if (clear === true) {
1420+
dispatch(setSendActionsList([]));
1421+
}
14071422
})
14081423
.catch(error => {
14091424
throw new Error(error);
@@ -1464,13 +1479,14 @@ const getTrackingActions = projectID => (dispatch, getState) => {
14641479
const checkActionsProject = projectID => (dispatch, getState) => {
14651480
const state = getState();
14661481
const currentProject = state.projectReducers.currentProject;
1482+
const currentProjectID = currentProject && currentProject.projectID;
14671483

14681484
Promise.resolve(dispatch(getTrackingActions(projectID))).then(() => {
1469-
dispatch(copyActionsToProject(currentProject));
1485+
dispatch(copyActionsToProject(currentProject, true, currentProjectID && currentProjectID != null ? true : false));
14701486
});
14711487
};
14721488

1473-
const copyActionsToProject = (toProject, setActionList = true) => (dispatch, getState) => {
1489+
const copyActionsToProject = (toProject, setActionList = true, clearSendList = true) => (dispatch, getState) => {
14741490
const state = getState();
14751491
const actionList = state.trackingReducers.project_actions_list;
14761492

@@ -1484,7 +1500,7 @@ const copyActionsToProject = (toProject, setActionList = true) => (dispatch, get
14841500
if (setActionList === true) {
14851501
dispatch(setActionsList(newActionsList));
14861502
}
1487-
dispatch(sendTrackingActions(newActionsList, toProject));
1503+
dispatch(sendTrackingActions(newActionsList, toProject, clearSendList));
14881504
}
14891505
};
14901506

@@ -1496,6 +1512,6 @@ export const sendTrackingActionsByProjectId = (projectID, authorID) => (dispatch
14961512
const project = { projectID, authorID };
14971513

14981514
Promise.resolve(dispatch(getTrackingActions(currentProjectID))).then(() => {
1499-
dispatch(copyActionsToProject(project, false));
1515+
dispatch(copyActionsToProject(project, false, currentProjectID && currentProjectID != null ? true : false));
15001516
});
15011517
};

0 commit comments

Comments
 (0)