Skip to content

Commit

Permalink
fix: reset app when New is clicked (DHIS2-9876) (#1470)
Browse files Browse the repository at this point in the history
The app should reset also when the URL does not change, like when a
non-saved visualization is shown and New in the FileMenu is clicked.
This used to work in 2.34.

(cherry picked from commit 0dc16ed)
  • Loading branch information
edoardo committed Nov 19, 2020
1 parent a9c2d5b commit 3d6a299
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/app/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class App extends Component {
this.unlisten = history.listen(location => {
const isSaving = location.state?.isSaving
const isOpening = location.state?.isOpening
const isResetting = location.state?.isResetting
const { interpretationId } = this.parseLocation(location)

if (
Expand All @@ -180,6 +181,7 @@ export class App extends Component {
if (
isSaving ||
isOpening ||
isResetting ||
this.state.previousLocation !== location.pathname
) {
this.loadVisualization(location)
Expand Down
8 changes: 7 additions & 1 deletion packages/app/src/components/MenuBar/MenuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ const onOpen = id => {
history.push(path)
}
}
const onNew = () => history.push('/')
const onNew = () => {
if (history.location.pathname === '/') {
history.replace({ pathname: '/', state: { isResetting: true } })
} else {
history.push('/')
}
}
const getOnRename = props => details => props.onRenameVisualization(details)
const getOnSave = props => details => props.onSaveVisualization(details, false)
const getOnSaveAs = props => details => props.onSaveVisualization(details, true)
Expand Down

0 comments on commit 3d6a299

Please sign in to comment.