Skip to content

Commit

Permalink
- #1483 - before dirty snapshot detection
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Nov 18, 2024
1 parent 4c06a7f commit 34b95ec
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 60 deletions.
5 changes: 1 addition & 4 deletions docker-compose.dev.vector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ services:
OIDC_RP_CLIENT_SECRET: ${OIDC_RP_CLIENT_SECRET}
OIDC_RP_CLIENT_ID: 'fragalysis-local'
OIDC_RENEW_ID_TOKEN_EXPIRY_MINUTES: 210
ISPYB_HOST: ispybdbproxy.diamond.ac.uk
# ISPYB_HOST: ispybdbproxy.diamond.ac.uk
ISPYB_PORT: 4306
ISPYB_USER: ${ISPYB_USER}
ISPYB_PASSWORD: ${ISPYB_PASSWORD}
SECURITY_CONNECTOR: ssh_ispyb
SSH_HOST: ssh.diamond.ac.uk
SSH_USER: ${SSH_USER}
SSH_PASSWORD: ${SSH_PASSWORD}
LOGGING_FRAMEWORK_ROOT_LEVEL: DEBUG
AUTHENTICATE_UPLOAD: 'False'
CELERY_TASK_ALWAYS_EAGER: 'True'
Expand Down
7 changes: 7 additions & 0 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,10 @@ export const updateInToBeDisplayedListForDataset = (datasetID, item) => {
datasetID: datasetID
};
};

export const setToBeDisplayedLists = toBeDisplayedLists => {
return {
type: constants.SET_TO_BE_DISPLAYED_LISTS,
toBeDisplayedLists: toBeDisplayedLists
};
};
3 changes: 2 additions & 1 deletion js/components/datasets/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export const constants = {
SET_TO_BE_DISPLAYED_LIST_DATASET: prefix + 'SET_TO_BE_DISPLAYED_LIST_DATASET',
APPEND_TO_BE_DISPLAYED_LIST_DATASET: prefix + 'APPEND_TO_BE_DISPLAYED_LIST_DATASET',
REMOVE_FROM_TO_BE_DISPLAYED_LIST_DATASET: prefix + 'REMOVE_FROM_TO_BE_DISPLAYED_LIST_DATASET',
UPDATE_IN_TO_BE_DISPLAYED_LIST_DATASET: prefix + 'UPDATE_IN_TO_BE_DISPLAYED_LIST_DATASET'
UPDATE_IN_TO_BE_DISPLAYED_LIST_DATASET: prefix + 'UPDATE_IN_TO_BE_DISPLAYED_LIST_DATASET',
SET_TO_BE_DISPLAYED_LISTS: prefix + 'SET_TO_BE_DISPLAYED_LISTS'
};

export const COUNT_OF_VISIBLE_SCORES = 7;
Expand Down
6 changes: 5 additions & 1 deletion js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ const setList = (state, listsName, datasetId, list) => {
const appendToList = (state, listsName, datasetId, itemId) => {
const newState = Object.assign({}, state);

newState[listsName][datasetId] = [...new Set([...newState[listsName][datasetId], itemId])];
newState[listsName][datasetId]
? (newState[listsName][datasetId] = [...new Set([...newState[listsName][datasetId], itemId])])
: (newState[listsName][datasetId] = [itemId]);

return newState;
};
Expand Down Expand Up @@ -204,6 +206,8 @@ const removeDatasetFromState = (state, datasetId) => {

export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
switch (action.type) {
case constants.SET_TO_BE_DISPLAYED_LISTS:
return { ...state, toBeDisplayedList: action.toBeDisplayedLists };
case constants.SET_TO_BE_DISPLAYED_LIST_DATASET: {
return setList(state, 'toBeDisplayedList', action.datasetID, action.list);
}
Expand Down
4 changes: 2 additions & 2 deletions js/components/preview/projectHistoryPanel/ProjectHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ export const ProjectHistory = memo(({ showFullHistory, graphKey, expanded, onExp
dispatch(setSelectedSnapshotToSwitch(transitionToSnapshot.hash));
dispatch(setIsOpenModalBeforeExit(true));
setTryToOpen(false);
dispatch(changeSnapshot(sessionProjectID, transitionToSnapshot.hash));
dispatch(changeSnapshot(sessionProjectID, transitionToSnapshot.hash, stage));
} else if (!isSnapshotDirty && tryToOpen && transitionToSnapshot) {
dispatch(changeSnapshot(sessionProjectID, transitionToSnapshot.hash));
dispatch(changeSnapshot(sessionProjectID, transitionToSnapshot.hash, stage));
setTryToOpen(false);
}
}, [dispatch, isSnapshotDirty, nglViewList, sessionProjectID, stage, transitionToSnapshot, tryToOpen]);
Expand Down
90 changes: 82 additions & 8 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
setSessionTitle,
setSnapshotLoadingInProgress
} from '../../../reducers/api/actions';
import { reloadSelectionReducer } from '../../../reducers/selection/actions';
import {
reloadSelectionReducer,
setToBeDisplayedList,
updateInToBeDisplayedList
} from '../../../reducers/selection/actions';
import { api, METHOD } from '../../../utils/api';
import {
setDisableRedirect,
Expand Down Expand Up @@ -36,16 +40,29 @@ import {
setForceProjectCreated
} from '../../projects/redux/actions';
import { selectFirstMolGroup } from '../../preview/moleculeGroups/redux/dispatchActions';
import { reloadDatasetsReducer } from '../../datasets/redux/actions';
import {
reloadDatasetsReducer,
setToBeDisplayedListForDataset,
setToBeDisplayedLists,
updateInToBeDisplayedListForDataset
} from '../../datasets/redux/actions';
import { captureScreenOfSnapshot } from '../../userFeedback/browserApi';
import { setCurrentProject } from '../../projects/redux/actions';
import { createProjectPost } from '../../../utils/discourse';
import { deepClone, deepMergeWithPriority, deepMergeWithPriorityAndWhiteList } from '../../../utils/objectUtils';
import {
deepClone,
deepMergeWithPriority,
deepMergeWithPriorityAndBlackList,
deepMergeWithPriorityAndWhiteList
} from '../../../utils/objectUtils';
import {
SNAPSHOT_VALUES_NOT_TO_BE_DELETED_SWITCHING_TARGETS,
SNAPSHOT_VALUES_TO_BE_DELETED,
SNAPSHOT_VALUES_TO_BE_DELETED_SWITCHING_SNAPSHOTS
} from './utilitySnapshotShapes';
import { setEntireState } from '../../../reducers/actions';
import { VIEWS } from '../../../constants/constants';
// import { display } from 'html2canvas/dist/types/css/property-descriptors/display';

export const getListOfSnapshots = () => (dispatch, getState) => {
const userID = DJANGO_CONTEXT['pk'] || null;
Expand Down Expand Up @@ -595,14 +612,23 @@ export const getCleanStateForSnapshot = () => (dispatch, getState) => {
//this is inefficient and it might cause problems with huge targets so
//having a custom deepClone function that only clones the necessary data would be better
//for now I'm skipping this to implement complete end to end functionality and then I'll optimize
let snapshotData = deepClone(state);
// let snapshotData = deepClone(state);
// snapshotData = deepMergeWithPriority({ ...snapshotData }, SNAPSHOT_VALUES_TO_BE_DELETED);
// snapshotData.nglReducers.snapshotNglOrientation = { ...snapshotData.nglReducers.nglOrientations };

let snapshotData = {};

snapshotData = deepMergeWithPriorityAndBlackList({}, state, SNAPSHOT_VALUES_NOT_TO_BE_DELETED_SWITCHING_TARGETS);
snapshotData = deepClone(snapshotData);
snapshotData = deepMergeWithPriority({ ...snapshotData }, SNAPSHOT_VALUES_NOT_TO_BE_DELETED_SWITCHING_TARGETS);
// snapshotData = deepClone(snapshotData);
snapshotData = deepMergeWithPriority({ ...snapshotData }, SNAPSHOT_VALUES_TO_BE_DELETED);
snapshotData.nglReducers.snapshotNglOrientation = { ...snapshotData.nglReducers.nglOrientations };

return snapshotData;
};

export const changeSnapshot = (projectID, snapshotID) => async (dispatch, getState) => {
export const changeSnapshot = (projectID, snapshotID, stage) => async (dispatch, getState) => {
dispatch(setSnapshotLoadingInProgress(true));
dispatch(setIsSnapshot(true));
// A hacky way of changing the URL without triggering react-router
Expand All @@ -627,12 +653,60 @@ export const changeSnapshot = (projectID, snapshotID) => async (dispatch, getSta
})
);

const currentState = getState();
const newState = deepMergeWithPriorityAndWhiteList(
//orientation animation
const newOrientation = snapshotState.nglReducers.nglOrientations[VIEWS.MAJOR_VIEW];
await stage.animationControls.orient(newOrientation.elements, 2000); //.then(() => {
let currentState = getState();
const toBeDisplayedLHSCurrent = currentState.selectionReducers.toBeDisplayedList;
const toBeDisplayedRHSCurrent = currentState.datasetsReducers.toBeDisplayedList;
const toBeDisplayedLHSNew = snapshotState.selectionReducers.toBeDisplayedList;
const toBeDisplayedRHSNew = snapshotState.datasetsReducers.toBeDisplayedList;

//remove LHS stuff that is not in the new snapshot
const toBeNoLongerDisplayedLHS = toBeDisplayedLHSCurrent.filter(
currentStruct =>
!toBeDisplayedLHSNew.find(newStruct => newStruct.id === currentStruct.id && newStruct.type === currentStruct.type)
);
toBeNoLongerDisplayedLHS.forEach(notToBeDisplayed =>
toBeDisplayedLHSNew.push({ ...notToBeDisplayed, display: false })
);

//remove RHS stuff that is not in the new snapshot
const toBeNoLongerDisplayedRHS = [];
Object.keys(toBeDisplayedRHSCurrent).forEach(datasetID => {
const currentDataset = toBeDisplayedRHSCurrent[datasetID];
const newDataset = toBeDisplayedRHSNew[datasetID];
if (newDataset) {
const toBeNoLongerDisplayed = currentDataset.filter(
currentStruct =>
!newDataset.find(newStruct => newStruct.id === currentStruct.id && newStruct.type === currentStruct.type)
);
toBeNoLongerDisplayedRHS.push(...toBeNoLongerDisplayed);
}
});
toBeNoLongerDisplayedRHS.forEach(notToBeDisplayed =>
toBeDisplayedRHSNew[notToBeDisplayed.datasetID]
? toBeDisplayedRHSNew[notToBeDisplayed.datasetID].push({ ...notToBeDisplayed, display: false })
: (toBeDisplayedRHSNew[notToBeDisplayed.datasetID] = [{ ...notToBeDisplayed, display: false }])
);

const toBeDisplayedLHSNewDeepCopy = deepClone(toBeDisplayedLHSNew);
const toBeDisplayedRHSNewDeepCopy = deepClone(toBeDisplayedRHSNew) || {};

currentState = getState();
// const copyOfCurrentState = deepClone(currentState);
const newState = deepMergeWithPriorityAndBlackList(
// copyOfCurrentState,
currentState,
snapshotState,
SNAPSHOT_VALUES_TO_BE_DELETED_SWITCHING_SNAPSHOTS
SNAPSHOT_VALUES_NOT_TO_BE_DELETED_SWITCHING_TARGETS
);

dispatch(setToBeDisplayedList(toBeDisplayedLHSNewDeepCopy));
dispatch(setToBeDisplayedLists(toBeDisplayedRHSNewDeepCopy));
// });
// await new Promise(r => setTimeout(r, 2000));

// dispatch(setEntireState(newState));
// console.log('msg');
};
98 changes: 64 additions & 34 deletions js/components/snapshot/redux/utilitySnapshotShapes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { setCurrentSnapshotTree } from '../../projects/redux/actions';
import { snapshotReducers } from './reducer';

export const SNAPSHOT_VALUES_TO_BE_DELETED = {
apiReducers: {
// target_id_list: [],
Expand All @@ -12,7 +15,7 @@ export const SNAPSHOT_VALUES_TO_BE_DELETED = {
rhsDataIsLoading: true,
rhsDataIsLoaded: false,
proteinIsLoading: false,
proteinsIsLoaded: false
proteinIsLoaded: false
},
nglReducers: {
objectsInView: {},
Expand All @@ -33,6 +36,9 @@ export const SNAPSHOT_VALUES_TO_BE_DELETED = {
vectorOnList: [],
isScrollFiredForLHS: false
},
snapshotReducers: {
openSavingDialog: false
},
previewReducers: {
molecule: {
imageCache: {}
Expand All @@ -55,43 +61,67 @@ export const SNAPSHOT_VALUES_TO_BE_DELETED = {
}
};

export const SNAPSHOT_VALUES_TO_BE_DELETED_SWITCHING_SNAPSHOTS = {
// export const SNAPSHOT_VALUES_TO_BE_DELETED_SWITCHING_SNAPSHOTS = {
// apiReducers: {
// // target_id_list: [],
// },
// nglReducers: {
// objectsInView: {},
// pdbCache: {},
// qualityCache: {},
// nglViewFromSnapshotRendered: false,
// snapshotOrientationApplied: false
// },
// selectionReducers: {
// fragmentDisplayList: [],
// proteinList: [],
// complexList: [],
// surfaceList: [],
// densityList: [],
// densityListCustom: [],
// densityListType: [],
// qualityList: [],
// vectorOnList: [],
// isScrollFiredForLHS: false
// },
// previewReducers: {
// molecule: {
// imageCache: {}
// }
// },
// datasetsReducers: {
// ligandLists: {},
// proteinLists: {},
// complexLists: {},
// surfaceLists: {},
// datasetScrolledMap: {},
// isSelectedDatasetScrolled: false
// },
// projectReducers: {
// isProjectModalLoading: false
// }
// };

export const SNAPSHOT_VALUES_NOT_TO_BE_DELETED_SWITCHING_TARGETS = {
apiReducers: {
// target_id_list: [],
},
nglReducers: {
objectsInView: {},
pdbCache: {},
qualityCache: {},
nglViewFromSnapshotRendered: false,
snapshotOrientationApplied: false
},
selectionReducers: {
fragmentDisplayList: [],
proteinList: [],
complexList: [],
surfaceList: [],
densityList: [],
densityListCustom: [],
densityListType: [],
qualityList: [],
vectorOnList: [],
isScrollFiredForLHS: false
},
previewReducers: {
molecule: {
imageCache: {}
}
target_id_list: [],
legacy_target_id_list: [],
all_mol_lists: [],
moleculeTags: [],
tagList: [],
categoryList: [],
lhs_compounds_list: []
},
datasetsReducers: {
ligandLists: {},
proteinLists: {},
complexLists: {},
surfaceLists: {},
datasetScrolledMap: {},
isSelectedDatasetScrolled: false
datasets: [],
moleculeLists: {},
scoreDatasetMap: {},
allInspirations: {}
},
projectReducers: {
isProjectModalLoading: false
currentSnapshot: {},
currentSnapshotList: [],
currentSnapshotTree: {},
currentProject: {}
}
};
Loading

0 comments on commit 34b95ec

Please sign in to comment.