Skip to content

Commit d319bf6

Browse files
author
Adriána Kohanová
committed
Merge remote-tracking branch 'remotes/origin/#455' into #433
# Conflicts: # js/reducers/tracking/dispatchActions.js # package.json
2 parents 2be6880 + 156565d commit d319bf6

File tree

7 files changed

+92
-70
lines changed

7 files changed

+92
-70
lines changed

js/components/preview/moleculeGroups/redux/dispatchActions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { OBJECT_TYPE } from '../../../nglView/constants';
3333
import { setSortDialogOpen } from '../../molecule/redux/actions';
3434
import { resetCurrentCompoundsSettings } from '../../compounds/redux/actions';
3535
import { reloadSession } from '../../../snapshot/redux/dispatchActions';
36-
import { restoreCurrentActionsList } from '../../../../reducers/tracking/dispatchActions';
36+
import { resetRestoringState } from '../../../../reducers/tracking/dispatchActions';
3737

3838
export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup, majorViewStage }) => (
3939
dispatch,
@@ -251,7 +251,7 @@ export const restoreFromCurrentSnapshot = ({ nglViewList }) => (dispatch, getSta
251251
};
252252

253253
export const restoreSnapshotActions = ({ nglViewList }) => (dispatch, getState) => {
254-
dispatch(restoreCurrentActionsList(nglViewList));
254+
dispatch(resetRestoringState(nglViewList));
255255
};
256256

257257
export const onDeselectMoleculeGroup = ({ moleculeGroup, stageSummaryView, majorViewStage }) => (

js/components/projects/projectPreview/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const ProjectPreview = memo(({}) => {
2121
const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
2222
const currentProject = useSelector(state => state.projectReducers.currentProject);
2323
const isActionRestoring = useSelector(state => state.trackingReducers.isActionRestoring);
24+
const isActionRestored = useSelector(state => state.trackingReducers.isActionRestored);
2425

2526
useEffect(() => {
2627
if (!snapshotId && currentSnapshotID === null) {
@@ -58,14 +59,14 @@ export const ProjectPreview = memo(({}) => {
5859
throw new Error(error);
5960
});
6061
} else {
61-
if (isActionRestoring === false) {
62+
if (isActionRestoring === false && isActionRestored === false) {
6263
dispatch(restoreCurrentActionsList(nglViewList));
63-
} else if (nglViewList && nglViewList.length > 0) {
64-
dispatch(restoreAfterTargetActions(nglViewList));
64+
} else if (nglViewList && nglViewList.length > 0 && isActionRestored === false) {
65+
dispatch(restoreAfterTargetActions(nglViewList, projectId));
6566
}
6667
}
6768
}
68-
}, [currentSnapshotID, dispatch, projectId, snapshotId, isActionRestoring, nglViewList, canShow]);
69+
}, [currentSnapshotID, dispatch, projectId, snapshotId, isActionRestoring, isActionRestored, nglViewList, canShow]);
6970

7071
if (canShow === false) {
7172
setSnackBarTitle('Not valid snapshot!');

js/components/target/redux/dispatchActions.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,20 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId })
6868
let promises = [];
6969
if (!isActionRestoring || isActionRestoring === false) {
7070
promises.push(dispatch(setTargetOn(response.data.target.id, true)));
71+
promises.push(
72+
dispatch(
73+
setCurrentProject({
74+
projectID: response.data.id,
75+
authorID: (response.data.author && response.data.author.id) || null,
76+
title: response.data.title,
77+
description: response.data.description,
78+
targetID: response.data.target.id,
79+
tags: JSON.parse(response.data.tags)
80+
})
81+
)
82+
);
7183
}
72-
promises.push(
73-
dispatch(
74-
setCurrentProject({
75-
projectID: response.data.id,
76-
authorID: (response.data.author && response.data.author.id) || null,
77-
title: response.data.title,
78-
description: response.data.description,
79-
targetID: response.data.target.id,
80-
tags: JSON.parse(response.data.tags)
81-
})
82-
)
83-
);
84+
8485
return Promise.all(promises);
8586
})
8687
.finally(() => setIsLoading(false));

js/reducers/tracking/actions.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ export const setIsActionsSaving = function(isActionSaving) {
9191
};
9292
};
9393

94-
export const setIsActionsRestoring = function(isActionRestoring) {
94+
export const setIsActionsRestoring = function(isActionRestoring, isActionRestored) {
9595
return {
9696
type: constants.SET_IS_ACTIONS_RESTORING,
97-
isActionRestoring: isActionRestoring
97+
isActionRestoring: isActionRestoring,
98+
isActionRestored: isActionRestored
9899
};
99100
};

js/reducers/tracking/dispatchActions.js

+64-47
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { actionType, actionObjectType } from './constants';
88
import { VIEWS } from '../../../js/constants/constants';
99
import { setCurrentVector, appendToBuyList, removeFromToBuyList, setHideAll } from '../selection/actions';
1010
import { unmountPreviewComponent, shouldLoadProtein } from '../../components/preview/redux/dispatchActions';
11+
import { setCurrentProject } from '../../components/projects/redux/actions';
1112
import {
1213
selectMoleculeGroup,
1314
onDeselectMoleculeGroup,
@@ -81,18 +82,10 @@ import {
8182
} from '../../components/datasets/redux/actions';
8283

8384
export const saveCurrentActionsList = (snapshotID, projectID, nglViewList) => (dispatch, getState) => {
84-
const state = getState();
85-
86-
let actionList = state.trackingReducers.track_actions_list;
87-
88-
if (!actionList || actionList.length === 0) {
89-
Promise.resolve(dispatch(getTrackingActions(projectID))).then(response => {
90-
actionList = response;
91-
dispatch(saveActionsList(snapshotID, actionList));
92-
});
93-
} else {
85+
Promise.resolve(dispatch(getTrackingActions(projectID))).then(response => {
86+
let actionList = response;
9487
dispatch(saveActionsList(snapshotID, actionList, nglViewList));
95-
}
88+
});
9689
};
9790

9891
export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatch, getState) => {
@@ -329,8 +322,13 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
329322
return list;
330323
};
331324

325+
export const resetRestoringState = () => (dispatch, getState) => {
326+
dispatch(setTargetOn(undefined));
327+
dispatch(setIsActionsRestoring(false, false));
328+
};
329+
332330
export const restoreCurrentActionsList = (stages = []) => (dispatch, getState) => {
333-
dispatch(setIsActionsRestoring(true));
331+
dispatch(setIsActionsRestoring(true, false));
334332

335333
Promise.resolve(dispatch(restoreTrackingActions())).then(response => {
336334
dispatch(setIsTrackingMoleculesRestoring(true));
@@ -390,7 +388,7 @@ const restoreTargetActions = (orderedActionList, stages) => (dispatch, getState)
390388
}
391389
};
392390

393-
export const restoreAfterTargetActions = stages => (dispatch, getState) => {
391+
export const restoreAfterTargetActions = (stages, projectId) => async (dispatch, getState) => {
394392
const state = getState();
395393

396394
const currentActionList = state.trackingReducers.current_actions_list;
@@ -401,9 +399,11 @@ export const restoreAfterTargetActions = stages => (dispatch, getState) => {
401399
const majorView = stages.find(view => view.id === VIEWS.MAJOR_VIEW);
402400
const summaryView = stages.find(view => view.id === VIEWS.SUMMARY_VIEW);
403401

404-
dispatch(shouldLoadProtein({ nglViewList: stages, currentSnapshotID: null, isLoadingCurrentSnapshot: false }));
402+
await dispatch(
403+
shouldLoadProtein({ nglViewList: stages, currentSnapshotID: null, isLoadingCurrentSnapshot: false })
404+
);
405405

406-
dispatch(
406+
await dispatch(
407407
loadMoleculeGroupsOfTarget({
408408
summaryView: summaryView.stage,
409409
isStateLoaded: false,
@@ -414,16 +414,15 @@ export const restoreAfterTargetActions = stages => (dispatch, getState) => {
414414
.catch(error => {
415415
throw error;
416416
})
417-
.finally(() => {
418-
Promise.resolve(
419-
dispatch(restoreSitesActions(orderedActionList, summaryView)),
420-
dispatch(loadAllMolecules(orderedActionList, targetId, majorView.stage)),
421-
dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage))
422-
).then(() => {
423-
dispatch(restoreNglStateAction(orderedActionList, stages));
424-
dispatch(restoreRepresentationActions(orderedActionList, stages));
425-
});
426-
});
417+
.finally(() => {});
418+
419+
await dispatch(restoreSitesActions(orderedActionList, summaryView));
420+
await dispatch(loadAllMolecules(orderedActionList, targetId, majorView.stage));
421+
await dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage));
422+
await dispatch(restoreRepresentationActions(orderedActionList, stages));
423+
await dispatch(restoreProject(projectId));
424+
dispatch(restoreNglStateAction(orderedActionList, stages));
425+
dispatch(setIsActionsRestoring(false, true));
427426
}
428427
};
429428

@@ -432,20 +431,17 @@ const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState
432431
if (action && action.nglStateList) {
433432
action.nglStateList.forEach(nglView => {
434433
dispatch(setOrientation(nglView.id, nglView.orientation));
435-
436-
if (nglView.id !== VIEWS.SUMMARY_VIEW) {
437-
let viewStage = stages.find(s => s.id === nglView.id);
438-
if (viewStage) {
439-
viewStage.stage.viewerControls.orient(nglView.orientation.elements);
440-
}
434+
let viewStage = stages.find(s => s.id === nglView.id);
435+
if (viewStage) {
436+
viewStage.stage.viewerControls.orient(nglView.orientation.elements);
441437
}
442438
});
443439
}
444440
};
445441

446-
const loadAllDatasets = (orderedActionList, target_on, stage) => (dispatch, getState) => {
442+
const loadAllDatasets = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
447443
dispatch(setMoleculeListIsLoading(true));
448-
dispatch(loadDataSets(target_on))
444+
await dispatch(loadDataSets(target_on))
449445
.then(results => {
450446
return dispatch(loadDatasetCompoundsWithScores());
451447
})
@@ -460,7 +456,7 @@ const loadAllDatasets = (orderedActionList, target_on, stage) => (dispatch, getS
460456
});
461457
};
462458

463-
const loadAllMolecules = (orderedActionList, target_on, stage) => (dispatch, getState) => {
459+
const loadAllMolecules = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
464460
const state = getState();
465461
const list_type = listType.MOLECULE;
466462

@@ -477,17 +473,18 @@ const loadAllMolecules = (orderedActionList, target_on, stage) => (dispatch, get
477473
})
478474
);
479475
});
480-
Promise.all(promises)
481-
.then(results => {
482-
let listToSet = {};
483-
results.forEach(molResult => {
484-
listToSet[molResult.mol_group] = molResult.molecules;
485-
});
486-
dispatch(setAllMolLists(listToSet));
487-
dispatch(restoreMoleculesActions(orderedActionList, stage));
488-
dispatch(setIsTrackingMoleculesRestoring(false));
489-
})
490-
.catch(err => console.log(err));
476+
try {
477+
const results = await Promise.all(promises);
478+
let listToSet = {};
479+
results.forEach(molResult => {
480+
listToSet[molResult.mol_group] = molResult.molecules;
481+
});
482+
dispatch(setAllMolLists(listToSet));
483+
dispatch(restoreMoleculesActions(orderedActionList, stage));
484+
dispatch(setIsTrackingMoleculesRestoring(false));
485+
} catch (err) {
486+
return console.log(err);
487+
}
491488
};
492489

493490
const restoreSitesActions = (orderedActionList, summaryView) => (dispatch, getState) => {
@@ -597,6 +594,27 @@ const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, get
597594
}
598595
};
599596

597+
const restoreProject = projectId => (dispatch, getState) => {
598+
if (projectId !== undefined) {
599+
return api({ url: `${base_url}/api/session-projects/${projectId}/` }).then(response => {
600+
let promises = [];
601+
promises.push(
602+
dispatch(
603+
setCurrentProject({
604+
projectID: response.data.id,
605+
authorID: (response.data.author && response.data.author.id) || null,
606+
title: response.data.title,
607+
description: response.data.description,
608+
targetID: response.data.target.id,
609+
tags: JSON.parse(response.data.tags)
610+
})
611+
)
612+
);
613+
return Promise.all(promises);
614+
});
615+
}
616+
};
617+
600618
const restoreCompoundsActions = (orderedActionList, stage) => (dispatch, getState) => {
601619
const state = getState();
602620

@@ -1457,11 +1475,10 @@ const copyActionsToProject = (toProject, setActionList = true) => (dispatch, get
14571475
const actionList = state.trackingReducers.project_actions_list;
14581476

14591477
if (toProject) {
1460-
let newProject = { projectID: toProject.projectID, authorID: toProject.authorID };
14611478
let newActionsList = [];
14621479

14631480
actionList.forEach(r => {
1464-
newActionsList.push(Object.assign({ ...r, project: newProject }));
1481+
newActionsList.push(Object.assign({ ...r }));
14651482
});
14661483

14671484
if (setActionList === true) {

js/reducers/tracking/trackingReducers.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const INITIAL_STATE = {
1313
isActionSaving: false,
1414
send_actions_list: [],
1515
project_actions_list: [],
16-
isActionRestoring: false
16+
isActionRestoring: false,
17+
isActionRestored: false
1718
};
1819

1920
export function trackingReducers(state = INITIAL_STATE, action = {}) {
@@ -85,7 +86,8 @@ export function trackingReducers(state = INITIAL_STATE, action = {}) {
8586

8687
case constants.SET_IS_ACTIONS_RESTORING:
8788
return Object.assign({}, state, {
88-
isActionRestoring: action.isActionRestoring
89+
isActionRestoring: action.isActionRestoring,
90+
isActionRestored: action.isActionRestored
8991
});
9092

9193
default:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fragalysis-frontend",
3-
"version": "0.9.29",
3+
"version": "0.9.30",
44
"description": "Frontend for fragalysis",
55
"main": "webpack.config.js",
66
"scripts": {

0 commit comments

Comments
 (0)