Skip to content

Commit

Permalink
- #1440 implemented fix
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed May 28, 2024
1 parent 1816b85 commit 9883c04
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
2 changes: 1 addition & 1 deletion js/components/preview/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const shouldLoadProtein = ({
(!routeSnapshotID || routeSnapshotID === currentSnapshotID.toString()) &&
isRestoring === true
) {
dispatch(restoreAfterTargetActions(nglViewList, routeProjectID));
dispatch(restoreAfterTargetActions(nglViewList, routeProjectID, currentSnapshotID));
}

if (targetOnName !== undefined) {
Expand Down
26 changes: 15 additions & 11 deletions js/components/preview/tags/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,25 @@ const getTagsForMol = (molId, tagList) => {
};

export const loadMoleculesAndTagsNew = targetId => async (dispatch, getState) => {
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - before getTags`);
let tags = await getTags(targetId);
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - after getTags`);
tags = tags.results;
if (tags?.length > 0) {
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - no. of tags received: ${tags?.length}`);
dispatch(setNoTagsReceived(false));
}
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - before getTagCategories`);
const tagCategories = await getTagCategories();
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - no. of tag categories received: ${tagCategories?.length}`);
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - after getTagCategories`);
// const canonSitesList = await getCanonSites(targetId);
// const canonConformSitest = await getCanonConformSites(targetId);

// console.log(`snapshotDebug - loadMoleculesAndTagsNew - before getAllDataNew`);
const data = await getAllDataNew(targetId);
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - after getAllDataNew`);
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - no. of molecules received: ${data?.results?.length}`);
let allMolecules = [];
data?.results?.forEach(mol => {
let newObject = { ...mol };
Expand Down Expand Up @@ -226,31 +235,25 @@ export const loadMoleculesAndTagsNew = targetId => async (dispatch, getState) =>
});

dispatch(setAllMolLists([...allMolecules]));
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - no. of molecules stored: ${allMolecules?.length}`);
//need to do this this way because only categories which have at least one tag assigned are sent from backend
tags = tags.sort(compareTagsAsc);
dispatch(setMoleculeTags(tags));
dispatch(setTagSelectorData(tagCategories, tags));
dispatch(setAllDataLoaded(true));

// console.log(`snapshotDebug - loadMoleculesAndTagsNew - before getPoses`);
return getPoses(targetId).then(poses => {
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - after getPoses`);
const modifiedPoses = [];
// let newIdStart = Math.max(...poses?.map(c => c.id)) + 1;
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - no. of poses received: ${poses?.length}`);
poses?.forEach(pose => {
const siteObs = allMolecules.filter(m => pose.site_observations.includes(m.id));
const firstObs = siteObs[0];
// const canonConformSites = siteObs?.map(so => {
// return {
// smiles: so.smiles,
// code: so.code,
// canon_site_conf: so.canon_site_conf,
// canon_site: canonConformSitest.find(ccf => ccf.id === so.canon_site_conf)?.canon_site
// };
// });

let newObject = { ...pose };
newObject['smiles'] = firstObs?.smiles;
newObject['code'] = `${pose.display_name}`;
// newObject['id'] = newIdStart++;
// newObject['origId'] = pose.id;
newObject['canonSiteConf'] = firstObs?.canon_site_conf;
newObject['canonSite'] = pose.canon_site;

Expand All @@ -277,5 +280,6 @@ export const loadMoleculesAndTagsNew = targetId => async (dispatch, getState) =>
return 0;
});
dispatch(setLHSCompoundsLIst(modifiedPoses));
// console.log(`snapshotDebug - loadMoleculesAndTagsNew - end of function`);
});
};
47 changes: 34 additions & 13 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ export const resetRestoringState = () => (dispatch, getState) => {
};

export const restoreCurrentActionsList = snapshotID => async (dispatch, getState) => {
const state = getState();
dispatch(resetTrackingState());
dispatch(resetTargetState());
dispatch(setTargetOn(undefined));
Expand All @@ -904,25 +905,34 @@ export const restoreCurrentActionsList = snapshotID => async (dispatch, getState
};

const restoreTrackingActions = snapshotID => async (dispatch, getState) => {
// console.log(`snapshotDebug - restoreTrackingActions - start`);
if (snapshotID) {
try {
const response = await api({
// console.log(`snapshotDebug - restoreTrackingActions - before getting actions`);
return api({
url: `${base_url}/api/snapshot-actions/?snapshot=${snapshotID}`
});
let results = response.data.results;
let listToSet = [];
results.forEach(r => {
let resultActions = JSON.parse(r.actions);
listToSet.push(...resultActions);
});
}).then(response => {
// console.log(`snapshotDebug - restoreTrackingActions - after getting actions`);
let results = response.data.results;
// console.log(`snapshotDebug - restoreTrackingActions - no. of actions: ${results.length}`);
let listToSet = [];
results.forEach(r => {
let resultActions = JSON.parse(r.actions);
listToSet.push(...resultActions);
});

let snapshotActions = [...listToSet];
dispatch(setCurrentActionsList(snapshotActions));
let snapshotActions = [...listToSet];
dispatch(setCurrentActionsList(snapshotActions));
// console.log(`snapshotDebug - restoreTrackingActions - end - success`);
return Promise.resolve(snapshotActions);
// return Promise.resolve();
});
} catch (error) {
throw new Error(error);
}
} else {
return Promise.resolve();
// console.log(`snapshotDebug - restoreTrackingActions - end - no snapshot`);
return Promise.resolve([]);
}
};

Expand Down Expand Up @@ -958,11 +968,14 @@ const restoreTargetActions = orderedActionList => (dispatch, getState) => {
}
};

export const restoreAfterTargetActions = (stages, projectId) => async (dispatch, getState) => {
export const restoreAfterTargetActions = (stages, projectId, snapshotId) => async (dispatch, getState) => {
const currentActionList = await dispatch(restoreTrackingActions(snapshotId));

const state = getState();

const currentActionList = state.trackingReducers.current_actions_list;
// const currentActionList = state.trackingReducers.current_actions_list;
const orderedActionList = currentActionList.sort((a, b) => a.timestamp - b.timestamp);
// console.log(`snapshotDebug - restoreAfterTargetActions - no. of actions: ${orderedActionList.length}`);
const targetId = state.apiReducers.target_on;

if (targetId && stages && stages.length > 0) {
Expand All @@ -983,8 +996,12 @@ export const restoreAfterTargetActions = (stages, projectId) => async (dispatch,
.finally(() => {});

await dispatch(restoreSitesActions(orderedActionList));
// console.log(`snapshotDebug - restoreAfterTargetActions - before loadData`);
await dispatch(loadData(orderedActionList, targetId, majorView));
// console.log(`snapshotDebug - restoreAfterTargetActions - after loadData`);
// console.log(`snapshotDebug - restoreAfterTargetActions - before restoreTagActions`);
await dispatch(restoreTagActions(orderedActionList));
// console.log(`snapshotDebug - restoreAfterTargetActions - after restoreTagActions`);
await dispatch(restoreMoleculesActions(orderedActionList, majorView.stage));
await dispatch(restoreRepresentationActions(orderedActionList, stages));
await dispatch(restoreProject(projectId));
Expand Down Expand Up @@ -1385,8 +1402,12 @@ export const restoreNglOrientationAnim = (orderedActionList, stages) => async (d
};

const loadData = (orderedActionList, targetId, majorView) => async (dispatch, getState) => {
// console.log(`snapshotDebug - loadData - before loadAllMolecules`);
await dispatch(loadAllMolecules(targetId));
// console.log(`snapshotDebug - loadData - after loadAllMolecules`);
// console.log(`snapshotDebug - loadData - before loadAllDatasets`);
await dispatch(loadAllDatasets(orderedActionList, targetId, majorView.stage));
// console.log(`snapshotDebug - loadData - after loadAllDatasets`);
};

const loadAllDatasets = (orderedActionList, target_on, stage) => async (dispatch, getState) => {
Expand Down

0 comments on commit 9883c04

Please sign in to comment.