Skip to content

Commit

Permalink
#520 After saving snapshot wrong snapshot is selected in project history
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Jan 29, 2021
1 parent e78af5e commit 04d97df
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,59 +257,62 @@ export const createNewSnapshot = ({

Promise.resolve(dispatch(saveCurrentActionsList(snapshot, project, nglViewList))).then(() => {
if (disableRedirect === false) {
// 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(async projectResponse => {
const response = await api({
url: `${base_url}/api/snapshots/?session_project=${session_project}`
});
const length = response.data.results.length;
if (length === 0) {
if (selectedSnapshotToSwitch != null) {
window.location.replace(`${URLS.projects}${session_project}/${selectedSnapshotToSwitch}`);
} else {
// 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(async projectResponse => {
const response = await api({
url: `${base_url}/api/snapshots/?session_project=${session_project}`
});
const length = response.data.results.length;
if (length === 0) {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[length - 1] !== undefined) {
// If the tree fails to load, bail out first without modifying the store
dispatch(loadSnapshotTree(projectResponse.data.id));
// Pick the latest snapshot which should be the last one
dispatch(
setCurrentSnapshot({
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: '[]'
})
);
dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
}
})
.catch(error => {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[length - 1] !== undefined) {
// If the tree fails to load, bail out first without modifying the store
dispatch(loadSnapshotTree(projectResponse.data.id));
// Pick the latest snapshot which should be the last one
dispatch(
setCurrentSnapshot({
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: '[]'
})
);
dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
}
})
.catch(error => {
dispatch(resetCurrentSnapshot());
dispatch(setIsLoadingSnapshotDialog(false));
});
});
}
} else {
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
Expand Down

0 comments on commit 04d97df

Please sign in to comment.