Skip to content

Commit

Permalink
#455 Store and retrieve snapshot actions in/from the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Nov 26, 2020
1 parent c64a88a commit 11539d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
const dispatch = useDispatch();

const customDatasets = useSelector(state => state.datasetsReducers.datasets);
const [selectedDatasetIndex, setSelectedDatasetIndex] = useState();
const [selectedDatasetIndex, setSelectedDatasetIndex] = useState(0);
const currentDataset = customDatasets[selectedDatasetIndex];
const target_on = useSelector(state => state.apiReducers.target_on);
const isTrackingRestoring = useSelector(state => state.trackingReducers.isTrackingCompoundsRestoring);
Expand Down
4 changes: 2 additions & 2 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
}).then(res => {
// redirect to project with newest created snapshot /:projectID/:snapshotID
if (res.data.id && session_project) {
dispatch(saveCurrentActionsList(res.data.id));
dispatch(saveCurrentActionsList(res.data.id, session_project));

if (disableRedirect === false) {
// Really bad usage or redirection. Hint for everybody in this line ignore it, but in other parts of code
Expand Down Expand Up @@ -320,7 +320,7 @@ export const createNewSnapshotWithoutStateModification = ({
disableRedirect: true
})
);
dispatch(saveCurrentActionsList(res.data.id));
dispatch(saveCurrentActionsList(res.data.id, session_project));
}
});
});
Expand Down
25 changes: 20 additions & 5 deletions js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,24 @@ import {
setIsActionsRestoring
} from './actions';

export const saveCurrentActionsList = snapshotID => (dispatch, getState) => {
export const saveCurrentActionsList = (snapshotID, projectID) => (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 {
dispatch(saveActionsList(snapshotID, actionList));
}
};

export const saveActionsList = (snapshotID, actionList) => (dispatch, getState) => {
const state = getState();

const actionList = state.trackingReducers.track_actions_list;
const currentTargetOn = state.apiReducers.target_on;
const currentSites = state.selectionReducers.mol_group_selection;
const currentLigands = state.selectionReducers.fragmentDisplayList;
Expand All @@ -89,10 +103,11 @@ export const saveCurrentActionsList = snapshotID => (dispatch, getState) => {
const currentDatasetBuyList = state.datasetsReducers.compoundsToBuyDatasetMap;
const currentobjectsInView = state.nglReducers.objectsInView;

const orderedActionList = actionList.reverse((a, b) => a.timestamp - b.timestamp);
const currentTargets = (currentTargetOn && [currentTargetOn]) || [];
const currentVectorSmiles = (currentVector && [currentVector]) || [];

let orderedActionList = actionList.reverse((a, b) => a.timestamp - b.timestamp);

let currentActions = [];

getCurrentActionList(orderedActionList, actionType.TARGET_LOADED, getCollection(currentTargets), currentActions);
Expand Down Expand Up @@ -1078,7 +1093,7 @@ const getTrackingActions = projectID => (dispatch, getState) => {

let projectActions = [...listToSet, ...sendActions];
dispatch(setProjectActionList(projectActions));
return Promise.resolve();
return Promise.resolve(projectActions);
})
.catch(error => {
throw new Error(error);
Expand All @@ -1089,7 +1104,7 @@ const getTrackingActions = projectID => (dispatch, getState) => {
} else {
let projectActions = [...sendActions];
dispatch(setProjectActionList(projectActions));
return Promise.resolve();
return Promise.resolve(projectActions);
}
};

Expand Down
3 changes: 2 additions & 1 deletion js/reducers/tracking/trackingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const findTrackAction = (action, state) => {
const username = DJANGO_CONTEXT['username'];
const target_on_name = state.apiReducers.target_on_name;
const isUndoRedoAction = state.trackingReducers.isUndoRedoAction;
const isActionRestoring = state.trackingReducers.isActionRestoring;

let trackAction = null;
if (isUndoRedoAction === false && action.skipTracking !== true) {
if (isUndoRedoAction === false && isActionRestoring === false && action.skipTracking !== true) {
if (action.type.includes(apiConstants.SET_TARGET_ON)) {
if (action.target_on) {
let targetName = getTargetName(action.target_on, state);
Expand Down
1 change: 0 additions & 1 deletion js/reducers/tracking/trackingReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const INITIAL_STATE = {
isActionsSending: false,
isActionsLoading: false,
isActionSaving: false,
setIsActionsRestoring: false,
send_actions_list: [],
project_actions_list: [],
isActionRestoring: false
Expand Down

0 comments on commit 11539d6

Please sign in to comment.