Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#455' into #433
Browse files Browse the repository at this point in the history
# Conflicts:
#	js/reducers/tracking/dispatchActions.js
#	package.json
  • Loading branch information
Adriána Kohanová committed Dec 1, 2020
2 parents 2be6880 + 156565d commit d319bf6
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 70 deletions.
4 changes: 2 additions & 2 deletions js/components/preview/moleculeGroups/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { OBJECT_TYPE } from '../../../nglView/constants';
import { setSortDialogOpen } from '../../molecule/redux/actions';
import { resetCurrentCompoundsSettings } from '../../compounds/redux/actions';
import { reloadSession } from '../../../snapshot/redux/dispatchActions';
import { restoreCurrentActionsList } from '../../../../reducers/tracking/dispatchActions';
import { resetRestoringState } from '../../../../reducers/tracking/dispatchActions';

export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup, majorViewStage }) => (
dispatch,
Expand Down Expand Up @@ -251,7 +251,7 @@ export const restoreFromCurrentSnapshot = ({ nglViewList }) => (dispatch, getSta
};

export const restoreSnapshotActions = ({ nglViewList }) => (dispatch, getState) => {
dispatch(restoreCurrentActionsList(nglViewList));
dispatch(resetRestoringState(nglViewList));
};

export const onDeselectMoleculeGroup = ({ moleculeGroup, stageSummaryView, majorViewStage }) => (
Expand Down
9 changes: 5 additions & 4 deletions js/components/projects/projectPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const ProjectPreview = memo(({}) => {
const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentProject = useSelector(state => state.projectReducers.currentProject);
const isActionRestoring = useSelector(state => state.trackingReducers.isActionRestoring);
const isActionRestored = useSelector(state => state.trackingReducers.isActionRestored);

useEffect(() => {
if (!snapshotId && currentSnapshotID === null) {
Expand Down Expand Up @@ -58,14 +59,14 @@ export const ProjectPreview = memo(({}) => {
throw new Error(error);
});
} else {
if (isActionRestoring === false) {
if (isActionRestoring === false && isActionRestored === false) {
dispatch(restoreCurrentActionsList(nglViewList));
} else if (nglViewList && nglViewList.length > 0) {
dispatch(restoreAfterTargetActions(nglViewList));
} else if (nglViewList && nglViewList.length > 0 && isActionRestored === false) {
dispatch(restoreAfterTargetActions(nglViewList, projectId));
}
}
}
}, [currentSnapshotID, dispatch, projectId, snapshotId, isActionRestoring, nglViewList, canShow]);
}, [currentSnapshotID, dispatch, projectId, snapshotId, isActionRestoring, isActionRestored, nglViewList, canShow]);

if (canShow === false) {
setSnackBarTitle('Not valid snapshot!');
Expand Down
25 changes: 13 additions & 12 deletions js/components/target/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId })
let promises = [];
if (!isActionRestoring || isActionRestoring === false) {
promises.push(dispatch(setTargetOn(response.data.target.id, true)));
promises.push(
dispatch(
setCurrentProject({
projectID: response.data.id,
authorID: (response.data.author && response.data.author.id) || null,
title: response.data.title,
description: response.data.description,
targetID: response.data.target.id,
tags: JSON.parse(response.data.tags)
})
)
);
}
promises.push(
dispatch(
setCurrentProject({
projectID: response.data.id,
authorID: (response.data.author && response.data.author.id) || null,
title: response.data.title,
description: response.data.description,
targetID: response.data.target.id,
tags: JSON.parse(response.data.tags)
})
)
);

return Promise.all(promises);
})
.finally(() => setIsLoading(false));
Expand Down
5 changes: 3 additions & 2 deletions js/reducers/tracking/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ export const setIsActionsSaving = function(isActionSaving) {
};
};

export const setIsActionsRestoring = function(isActionRestoring) {
export const setIsActionsRestoring = function(isActionRestoring, isActionRestored) {
return {
type: constants.SET_IS_ACTIONS_RESTORING,
isActionRestoring: isActionRestoring
isActionRestoring: isActionRestoring,
isActionRestored: isActionRestored
};
};
111 changes: 64 additions & 47 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { actionType, actionObjectType } from './constants';
import { VIEWS } from '../../../js/constants/constants';
import { setCurrentVector, appendToBuyList, removeFromToBuyList, setHideAll } from '../selection/actions';
import { unmountPreviewComponent, shouldLoadProtein } from '../../components/preview/redux/dispatchActions';
import { setCurrentProject } from '../../components/projects/redux/actions';
import {
selectMoleculeGroup,
onDeselectMoleculeGroup,
Expand Down Expand Up @@ -81,18 +82,10 @@ import {
} from '../../components/datasets/redux/actions';

export const saveCurrentActionsList = (snapshotID, projectID, nglViewList) => (dispatch, getState) => {
const state = getState();

let actionList = state.trackingReducers.track_actions_list;

if (!actionList || actionList.length === 0) {
Promise.resolve(dispatch(getTrackingActions(projectID))).then(response => {
actionList = response;
dispatch(saveActionsList(snapshotID, actionList));
});
} else {
Promise.resolve(dispatch(getTrackingActions(projectID))).then(response => {
let actionList = response;
dispatch(saveActionsList(snapshotID, actionList, nglViewList));
}
});
};

export const saveActionsList = (snapshotID, actionList, nglViewList) => (dispatch, getState) => {
Expand Down Expand Up @@ -329,8 +322,13 @@ const getCollectionOfDatasetOfRepresentation = dataList => {
return list;
};

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

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

Promise.resolve(dispatch(restoreTrackingActions())).then(response => {
dispatch(setIsTrackingMoleculesRestoring(true));
Expand Down Expand Up @@ -390,7 +388,7 @@ const restoreTargetActions = (orderedActionList, stages) => (dispatch, getState)
}
};

export const restoreAfterTargetActions = stages => (dispatch, getState) => {
export const restoreAfterTargetActions = (stages, projectId) => async (dispatch, getState) => {
const state = getState();

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

dispatch(shouldLoadProtein({ nglViewList: stages, currentSnapshotID: null, isLoadingCurrentSnapshot: false }));
await dispatch(
shouldLoadProtein({ nglViewList: stages, currentSnapshotID: null, isLoadingCurrentSnapshot: false })
);

dispatch(
await dispatch(
loadMoleculeGroupsOfTarget({
summaryView: summaryView.stage,
isStateLoaded: false,
Expand All @@ -414,16 +414,15 @@ export const restoreAfterTargetActions = stages => (dispatch, getState) => {
.catch(error => {
throw error;
})
.finally(() => {
Promise.resolve(
dispatch(restoreSitesActions(orderedActionList, summaryView)),
dispatch(loadAllMolecules(orderedActionList, targetId, majorView.stage)),
dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage))
).then(() => {
dispatch(restoreNglStateAction(orderedActionList, stages));
dispatch(restoreRepresentationActions(orderedActionList, stages));
});
});
.finally(() => {});

await dispatch(restoreSitesActions(orderedActionList, summaryView));
await dispatch(loadAllMolecules(orderedActionList, targetId, majorView.stage));
await dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage));
await dispatch(restoreRepresentationActions(orderedActionList, stages));
await dispatch(restoreProject(projectId));
dispatch(restoreNglStateAction(orderedActionList, stages));
dispatch(setIsActionsRestoring(false, true));
}
};

Expand All @@ -432,20 +431,17 @@ const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState
if (action && action.nglStateList) {
action.nglStateList.forEach(nglView => {
dispatch(setOrientation(nglView.id, nglView.orientation));

if (nglView.id !== VIEWS.SUMMARY_VIEW) {
let viewStage = stages.find(s => s.id === nglView.id);
if (viewStage) {
viewStage.stage.viewerControls.orient(nglView.orientation.elements);
}
let viewStage = stages.find(s => s.id === nglView.id);
if (viewStage) {
viewStage.stage.viewerControls.orient(nglView.orientation.elements);
}
});
}
};

const loadAllDatasets = (orderedActionList, target_on, stage) => (dispatch, getState) => {
const loadAllDatasets = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
dispatch(setMoleculeListIsLoading(true));
dispatch(loadDataSets(target_on))
await dispatch(loadDataSets(target_on))
.then(results => {
return dispatch(loadDatasetCompoundsWithScores());
})
Expand All @@ -460,7 +456,7 @@ const loadAllDatasets = (orderedActionList, target_on, stage) => (dispatch, getS
});
};

const loadAllMolecules = (orderedActionList, target_on, stage) => (dispatch, getState) => {
const loadAllMolecules = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
const state = getState();
const list_type = listType.MOLECULE;

Expand All @@ -477,17 +473,18 @@ const loadAllMolecules = (orderedActionList, target_on, stage) => (dispatch, get
})
);
});
Promise.all(promises)
.then(results => {
let listToSet = {};
results.forEach(molResult => {
listToSet[molResult.mol_group] = molResult.molecules;
});
dispatch(setAllMolLists(listToSet));
dispatch(restoreMoleculesActions(orderedActionList, stage));
dispatch(setIsTrackingMoleculesRestoring(false));
})
.catch(err => console.log(err));
try {
const results = await Promise.all(promises);
let listToSet = {};
results.forEach(molResult => {
listToSet[molResult.mol_group] = molResult.molecules;
});
dispatch(setAllMolLists(listToSet));
dispatch(restoreMoleculesActions(orderedActionList, stage));
dispatch(setIsTrackingMoleculesRestoring(false));
} catch (err) {
return console.log(err);
}
};

const restoreSitesActions = (orderedActionList, summaryView) => (dispatch, getState) => {
Expand Down Expand Up @@ -597,6 +594,27 @@ const restoreRepresentationActions = (moleculesAction, stages) => (dispatch, get
}
};

const restoreProject = projectId => (dispatch, getState) => {
if (projectId !== undefined) {
return api({ url: `${base_url}/api/session-projects/${projectId}/` }).then(response => {
let promises = [];
promises.push(
dispatch(
setCurrentProject({
projectID: response.data.id,
authorID: (response.data.author && response.data.author.id) || null,
title: response.data.title,
description: response.data.description,
targetID: response.data.target.id,
tags: JSON.parse(response.data.tags)
})
)
);
return Promise.all(promises);
});
}
};

const restoreCompoundsActions = (orderedActionList, stage) => (dispatch, getState) => {
const state = getState();

Expand Down Expand Up @@ -1457,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
6 changes: 4 additions & 2 deletions js/reducers/tracking/trackingReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const INITIAL_STATE = {
isActionSaving: false,
send_actions_list: [],
project_actions_list: [],
isActionRestoring: false
isActionRestoring: false,
isActionRestored: false
};

export function trackingReducers(state = INITIAL_STATE, action = {}) {
Expand Down Expand Up @@ -85,7 +86,8 @@ export function trackingReducers(state = INITIAL_STATE, action = {}) {

case constants.SET_IS_ACTIONS_RESTORING:
return Object.assign({}, state, {
isActionRestoring: action.isActionRestoring
isActionRestoring: action.isActionRestoring,
isActionRestored: action.isActionRestored
});

default:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fragalysis-frontend",
"version": "0.9.29",
"version": "0.9.30",
"description": "Frontend for fragalysis",
"main": "webpack.config.js",
"scripts": {
Expand Down

0 comments on commit d319bf6

Please sign in to comment.