Skip to content

Commit

Permalink
Mostly done
Browse files Browse the repository at this point in the history
  • Loading branch information
ag-m2ms committed Jan 19, 2021
1 parent 95aa899 commit afb2397
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions js/components/preview/projectHistory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const ProjectHistory = memo(({ setHeight, showFullHistory }) => {
const { nglViewList } = useContext(NglContext);
const dispatch = useDispatch();
let match = useRouteMatch();
const projectID = match && match.params && match.params.projectId;
const snapshotId = match && match.params && match.params.snapshotId;
const projectID = useSelector(state => state.projectReducers.currentProject).projectID;
const snapshotId = useSelector(state => state.projectReducers.currentSnapshot).id;
const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentSnapshotList = useSelector(state => state.projectReducers.currentSnapshotList);
const currentSnapshotTree = useSelector(state => state.projectReducers.currentSnapshotTree);
Expand Down
33 changes: 19 additions & 14 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import moment from 'moment';
import { setProteinLoadingState } from '../../../reducers/ngl/actions';
import { reloadNglViewFromSnapshot } from '../../../reducers/ngl/dispatchActions';
import { base_url, URLS } from '../../routes/constants';
import { resetCurrentSnapshot, setCurrentSnapshot, setForceCreateProject } from '../../projects/redux/actions';
import { resetCurrentSnapshot, setCurrentSnapshot, setForceCreateProject, setForceProjectCreated } from '../../projects/redux/actions';
import { selectFirstMolGroup } from '../../preview/moleculeGroups/redux/dispatchActions';
import { reloadDatasetsReducer } from '../../datasets/redux/actions';
import {
Expand Down Expand Up @@ -227,6 +227,8 @@ export const createNewSnapshot = ({
api({ url: `${base_url}/api/snapshots/?session_project=${session_project}&type=INIT` }).then(response => {
if (response.data.count === 0) {
newType = SnapshotType.INIT;
// Without this, the snapshot tree wouldnt work
dispatch(setForceProjectCreated(false));
}

return api({
Expand All @@ -250,29 +252,29 @@ export const createNewSnapshot = ({

Promise.resolve(dispatch(saveCurrentActionsList(snapshot, project, nglViewList))).then(() => {
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 !
// A hacky way of changing the URL without triggering react-router
window.history.replaceState(
null, null,
`${URLS.projects}${session_project}/${
selectedSnapshotToSwitch === null ? res.data.id : selectedSnapshotToSwitch
}`
);
api({ url: `${base_url}/api/session-projects/${session_project}/` }).then(projectResponse => {
api({ url: `${base_url}/api/snapshots/?session_project=${session_project}&type=INIT` }).then(response => {
if (response.data.results.length === 0) {
api({ url: `${base_url}/api/snapshots/?session_project=${session_project}` }).then(response => {
const length = response.data.results.length;
if (length === 0) {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[0] !== undefined) {
} else if (response.data.results[length - 1] !== undefined) {
dispatch(
setCurrentSnapshot({
id: response.data.results[0].id,
type: response.data.results[0].type,
title: response.data.results[0].title,
author: response.data.results[0].author,
description: response.data.results[0].description,
created: response.data.results[0].created,
children: response.data.results[0].children,
parent: response.data.results[0].parent,
id: response.data.results[length - 1].id,
type: response.data.results[length - 1].type,
title: response.data.results[length - 1].title,
author: response.data.results[length - 1].author,
description: response.data.results[length - 1].description,
created: response.data.results[length - 1].created,
children: response.data.results[length - 1].children,
parent: response.data.results[length - 1].parent,
data: '[]'
})
);
Expand All @@ -286,6 +288,9 @@ export const createNewSnapshot = ({
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(loadSnapshotTree(projectResponse.data.id)).catch(error => {
throw new Error(error);
});
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
Expand Down
10 changes: 7 additions & 3 deletions js/components/snapshot/withSnapshotManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export const withSnapshotManagement = WrappedComponent => {
const directDisplay = useSelector(state => state.apiReducers.direct_access);

const snapshotJustSaved = useSelector(state => state.snapshotReducers.snapshotJustSaved);
let projectId = match && match.params && match.params.projectId;
projectId = snapshotJustSaved || projectId;
let projectId = currentProject.projectID;
/*let projectId = match && match.params && match.params.projectId;
projectId = snapshotJustSaved || projectId;*/
let target = match && match.params && match.params.target;
target = snapshotJustSaved ? undefined : target;
//const disableUserInteraction = useDisableUserInteraction();
Expand Down Expand Up @@ -99,6 +100,9 @@ export const withSnapshotManagement = WrappedComponent => {
};
}, [enableSaveButton, dispatch, sessionTitle, setHeaderNavbarTitle, setHeaderButtons, setSnackBarTitle, targetIdList, targetName, setSnackBarColor, projectId, currentSnapshotID, currentProject, disableShareButton, target, nglViewList, currentSnapshot.id, history]);

return <WrappedComponent {...rest} />;
return <WrappedComponent {...rest} hideProjects={
DJANGO_CONTEXT['pk'] === undefined ||
(DJANGO_CONTEXT['pk'] !== undefined && (currentProject.projectID === null || currentProject.authorID === null))
}/>;
});
};

0 comments on commit afb2397

Please sign in to comment.