Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#455' into #462
Browse files Browse the repository at this point in the history
# Conflicts:
#	js/reducers/tracking/dispatchActions.js
#	js/reducers/tracking/trackingActions.js
  • Loading branch information
Adriána Kohanová committed Nov 26, 2020
2 parents 799efbb + 11539d6 commit c5d562e
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 287 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +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';

export const clearAfterDeselectingMoleculeGroup = ({ molGroupId, currentMolGroup, majorViewStage }) => (
dispatch,
Expand Down Expand Up @@ -246,10 +247,13 @@ export const clearMoleculeGroupSelection = ({ getNglView }) => (dispatch, getSta

export const restoreFromCurrentSnapshot = ({ nglViewList }) => (dispatch, getState) => {
const snapshot = getState().projectReducers.currentSnapshot.data;

dispatch(reloadSession(snapshot, nglViewList));
};

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

export const onDeselectMoleculeGroup = ({ moleculeGroup, stageSummaryView, majorViewStage }) => (
dispatch,
getState
Expand Down
9 changes: 0 additions & 9 deletions js/components/preview/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ export const shouldLoadProtein = ({
});
}

// decide to load existing snapshot
else if (
currentSnapshotID !== null &&
(!routeSnapshotID || routeSnapshotID === currentSnapshotID.toString()) &&
currentSnapshotData !== null
) {
dispatch(reloadSession(currentSnapshotData, nglViewList));
}

if (targetOnName !== undefined) {
document.title = targetOnName + ': Fragalysis';
}
Expand Down
16 changes: 12 additions & 4 deletions js/components/projects/addProjectDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Autocomplete } from '@material-ui/lab';
import { Button } from '../../common/Inputs/Button';
import { useDispatch, useSelector } from 'react-redux';
import { createProjectFromSnapshotDialog } from '../redux/dispatchActions';
import { manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions';

const useStyles = makeStyles(theme => ({
body: {
Expand All @@ -34,6 +35,7 @@ export const AddProjectDetail = memo(({ handleCloseModal }) => {

const dispatch = useDispatch();
const targetId = useSelector(state => state.apiReducers.target_on);
const projectID = useSelector(state => state.projectReducers.currentProject.projectID);
const isProjectModalLoading = useSelector(state => state.projectReducers.isProjectModalLoading);

const [tags, setTags] = React.useState([]);
Expand Down Expand Up @@ -65,11 +67,17 @@ export const AddProjectDetail = memo(({ handleCloseModal }) => {
author: DJANGO_CONTEXT['pk'] || null,
tags: JSON.stringify(tags)
};
dispatch(createProjectFromSnapshotDialog(data)).catch(error => {
setState(() => {
throw error;

const oldProjectID = projectID;
dispatch(createProjectFromSnapshotDialog(data))
.then(() => {
dispatch(manageSendTrackingActions(oldProjectID, true));
})
.catch(error => {
setState(() => {
throw error;
});
});
});
}}
>
{({ submitForm, isSubmitting }) => (
Expand Down
47 changes: 30 additions & 17 deletions js/components/projects/projectPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ import { useRouteMatch } from 'react-router-dom';
import { loadCurrentSnapshotByID, loadSnapshotByProjectID } from '../redux/dispatchActions';
import { HeaderContext } from '../../header/headerContext';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import { restoreCurrentActionsList, restoreAfterTargetActions } from '../../../reducers/tracking/dispatchActions';
import { NglContext } from '../../nglView/nglProvider';

export const ProjectPreview = memo(({}) => {
const { setSnackBarTitle } = useContext(HeaderContext);
const [canShow, setCanShow] = useState(undefined);
const isSnapshotLoaded = useRef(undefined);
let match = useRouteMatch();
const dispatch = useDispatch();
const { nglViewList } = useContext(NglContext);

const projectId = match && match.params && match.params.projectId;
const snapshotId = match && match.params && match.params.snapshotId;
const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentProject = useSelector(state => state.projectReducers.currentProject);
const isActionRestoring = useSelector(state => state.trackingReducers.isActionRestoring);

useEffect(() => {
if (!snapshotId && currentSnapshotID === null) {
Expand All @@ -31,28 +36,36 @@ export const ProjectPreview = memo(({}) => {
throw new Error(error);
});
} else {
dispatch(loadCurrentSnapshotByID(snapshotId || currentSnapshotID))
.then(response => {
if (response !== false) {
if (response) {
if (response.session_project && `${response.session_project.id}` === projectId) {
isSnapshotLoaded.current = response.id;
setCanShow(true);
if (currentSnapshotID === null) {
dispatch(loadCurrentSnapshotByID(snapshotId))
.then(response => {
if (response !== false) {
if (response) {
if (response.session_project && `${response.session_project.id}` === projectId) {
isSnapshotLoaded.current = response.id;
setCanShow(true);
} else {
setCanShow(false);
}
} else {
isSnapshotLoaded.current = response;
setCanShow(false);
}
} else {
isSnapshotLoaded.current = response;
setCanShow(false);
}
}
})
.catch(error => {
setCanShow(false);
throw new Error(error);
});
})
.catch(error => {
setCanShow(false);
throw new Error(error);
});
} else {
if (isActionRestoring === false) {
dispatch(restoreCurrentActionsList(nglViewList));
} else if (nglViewList && nglViewList.length > 0) {
dispatch(restoreAfterTargetActions(nglViewList));
}
}
}
}, [currentSnapshotID, dispatch, projectId, snapshotId]);
}, [currentSnapshotID, dispatch, projectId, snapshotId, isActionRestoring, nglViewList, canShow]);

if (canShow === false) {
setSnackBarTitle('Not valid snapshot!');
Expand Down
8 changes: 4 additions & 4 deletions js/components/projects/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const assignSnapshotToProject = ({ projectID, snapshotID, ...rest }) => (
created: response.data.created,
children: response.data.children,
parent: response.data.parent,
data: JSON.parse(response.data.data)
data: '[]'
})
)
)
Expand Down Expand Up @@ -147,7 +147,7 @@ export const loadSnapshotByProjectID = projectID => (dispatch, getState) => {
created: response.data.results[0].created,
children: response.data.results[0].children,
parent: response.data.results[0].parent,
data: JSON.parse(response.data.results[0].data)
data: '[]'
})
);
return Promise.resolve(response.data.results[0].id);
Expand Down Expand Up @@ -184,7 +184,7 @@ export const loadCurrentSnapshotByID = snapshotID => (dispatch, getState) => {
created: response.data.created,
children: response.data.children,
parent: response.data.parent,
data: JSON.parse(response.data.data)
data: '[]'
})
);
return Promise.resolve(response.data);
Expand Down Expand Up @@ -294,7 +294,7 @@ const copySnapshot = (selectedSnapshot, projectID, history) => dispatch => {
title: selectedSnapshot.title,
author: (selectedSnapshot && selectedSnapshot.author && selectedSnapshot.author.id) || null,
description: selectedSnapshot.description,
data: JSON.parse(selectedSnapshot.data),
data: '[]',
created: selectedSnapshot.created,
parent: null,
children: selectedSnapshot.children,
Expand Down
26 changes: 11 additions & 15 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import { base_url, URLS } from '../../routes/constants';
import { resetCurrentSnapshot, setCurrentSnapshot, setForceCreateProject } from '../../projects/redux/actions';
import { selectFirstMolGroup } from '../../preview/moleculeGroups/redux/dispatchActions';
import { reloadDatasetsReducer } from '../../datasets/redux/actions';
import {
sendTruckingActionsByProjectId,
appendAndSendTruckingActions
} from '../../../reducers/tracking/dispatchActions';
import { saveCurrentActionsList } from '../../../reducers/tracking/dispatchActions';
import { sendTrackingActionsByProjectId, manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions';

export const getListOfSnapshots = () => (dispatch, getState) => {
const userID = DJANGO_CONTEXT['pk'] || null;
Expand Down Expand Up @@ -86,7 +84,7 @@ export const saveCurrentSnapshot = ({
dispatch(resetCurrentSnapshot());
return api({
url: `${base_url}/api/snapshots/`,
data: { type, title, author, description, data: JSON.stringify(data), created, parent, children, session_project },
data: { type, title, author, description, created, parent, data: '[]', children, session_project },
method: METHOD.POST
})
.then(response =>
Expand Down Expand Up @@ -185,8 +183,6 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
getState
) => {
const state = getState();
const { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers } = state;
const data = { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers };
const selectedSnapshotToSwitch = state.snapshotReducers.selectedSnapshotToSwitch;
const disableRedirect = state.snapshotReducers.disableRedirect;

Expand All @@ -212,13 +208,15 @@ export const createNewSnapshot = ({ title, description, type, author, parent, se
author,
parent,
session_project,
data: JSON.stringify(data),
data: '[]',
children: []
},
method: METHOD.POST
}).then(res => {
// redirect to project with newest created snapshot /:projectID/:snapshotID
if (res.data.id && session_project) {
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
// use react-router !
Expand Down Expand Up @@ -253,6 +251,7 @@ export const activateSnapshotDialog = (loggedInUserID = undefined, finallyShareS
const projectID = state.projectReducers.currentProject.projectID;
const currentSnapshotAuthor = state.projectReducers.currentSnapshot.author;

dispatch(manageSendTrackingActions());
dispatch(setDisableRedirect(finallyShareSnapshot));

if (!loggedInUserID && targetId) {
Expand All @@ -265,7 +264,7 @@ export const activateSnapshotDialog = (loggedInUserID = undefined, finallyShareS
};
dispatch(createProjectFromSnapshotDialog(data))
.then(() => {
dispatch(appendAndSendTruckingActions(null));
dispatch(manageSendTrackingActions(projectID, true));
dispatch(setOpenSnapshotSavingDialog(true));
})
.catch(error => {
Expand All @@ -287,10 +286,6 @@ export const createNewSnapshotWithoutStateModification = ({
parent,
session_project
}) => (dispatch, getState) => {
const state = getState();
const { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers } = state;
const data = { apiReducers, nglReducers, selectionReducers, previewReducers, datasetsReducers };

if (!session_project) {
return Promise.reject('Project ID is missing!');
}
Expand All @@ -311,7 +306,7 @@ export const createNewSnapshotWithoutStateModification = ({
author,
parent,
session_project,
data: JSON.stringify(data),
data: '[]',
children: []
},
method: METHOD.POST
Expand All @@ -325,6 +320,7 @@ export const createNewSnapshotWithoutStateModification = ({
disableRedirect: true
})
);
dispatch(saveCurrentActionsList(res.data.id, session_project));
}
});
});
Expand Down Expand Up @@ -358,7 +354,7 @@ export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState)
const parent = null;
const session_project = projectID;

dispatch(sendTruckingActionsByProjectId(projectID, author));
dispatch(sendTrackingActionsByProjectId(projectID, author));

return dispatch(
createNewSnapshotWithoutStateModification({ title, description, type, author, parent, session_project })
Expand Down
4 changes: 2 additions & 2 deletions js/components/snapshot/withSnapshotManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DJANGO_CONTEXT } from '../../utils/djangoContext';
import { useDisableUserInteraction } from '../helpers/useEnableUserInteracion';
import { activateSnapshotDialog, saveAndShareSnapshot } from './redux/dispatchActions';
import { NglContext } from '../nglView/nglProvider';
import { restoreFromCurrentSnapshot } from '../preview/moleculeGroups/redux/dispatchActions';
import { restoreSnapshotActions } from '../preview/moleculeGroups/redux/dispatchActions';

/**
* Created by ricgillams on 13/06/2018.
Expand Down Expand Up @@ -64,7 +64,7 @@ export const withSnapshotManagement = WrappedComponent => {
<Button
key="restoreSnapshot"
color="primary"
onClick={() => dispatch(restoreFromCurrentSnapshot({ nglViewList }))}
onClick={() => dispatch(restoreSnapshotActions({ nglViewList }))}
startIcon={<Restore />}
disabled={disableShareButton || disableUserInteraction}
>
Expand Down
14 changes: 10 additions & 4 deletions js/components/target/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const loadTargetList = onCancel => (dispatch, getState) => {
});
};

export const updateTarget = ({ target, setIsLoading, targetIdList, projectId }) => dispatch => {
export const updateTarget = ({ target, setIsLoading, targetIdList, projectId }) => (dispatch, getState) => {
const isActionRestoring = getState().trackingReducers.isActionRestoring;

// Get from the REST API
let targetUnrecognisedFlag = true;
if (target !== undefined) {
Expand Down Expand Up @@ -63,8 +65,11 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId })
setIsLoading(true);
return api({ url: `${base_url}/api/session-projects/${projectId}/` })
.then(response => {
return Promise.all([
dispatch(setTargetOn(response.data.target.id)),
let promises = [];
if (!isActionRestoring || isActionRestoring === false) {
promises.push(dispatch(setTargetOn(response.data.target.id, true)));
}
promises.push(
dispatch(
setCurrentProject({
projectID: response.data.id,
Expand All @@ -75,7 +80,8 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId })
tags: JSON.parse(response.data.tags)
})
)
]);
);
return Promise.all(promises);
})
.finally(() => setIsLoading(false));
}
Expand Down
3 changes: 2 additions & 1 deletion js/components/target/withUpdatingTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const withUpdatingTarget = WrappedContainer => {
const target = match && match.params && match.params.target;
const uuid = match && match.params && match.params.uuid;
const snapshotUuid = match && match.params && match.params.snapshotUuid;
const snapshotId = match && match.params && match.params.snapshotId;
const projectId = match && match.params && match.params.projectId;

const { isLoading, setIsLoading } = useContext(HeaderContext);
Expand All @@ -32,7 +33,7 @@ export const withUpdatingTarget = WrappedContainer => {
throw error;
});
});
}, [setIsLoading, target, updateTarget, targetIdList, projectId]);
}, [setIsLoading, target, updateTarget, targetIdList, projectId, snapshotId]);

if (isLoading === true) {
return null;
Expand Down
Loading

0 comments on commit c5d562e

Please sign in to comment.