From 3f9a722f37cc501cccbd11df16987ad0b720bdb0 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Tue, 15 Sep 2020 10:49:09 +0200 Subject: [PATCH 1/3] fix: confirm dialog when navigating to/from interpretation Since no change is actually lost when navigating in and out of an interpretation's view, remove the confirm dialog. Also, when answering No to the confirm dialog (meaning i don't want to navigate to the new URL) restore the previous URL with history.goBack() so that the app really is in the same state as before the confirm dialog. --- packages/app/src/components/App.js | 45 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/app/src/components/App.js b/packages/app/src/components/App.js index f356981117..1541312a13 100644 --- a/packages/app/src/components/App.js +++ b/packages/app/src/components/App.js @@ -72,6 +72,13 @@ export class App extends Component { return false } + parseLocation = location => { + const pathParts = location.pathname.slice(1).split('/') + const id = pathParts[0] + const interpretationId = pathParts[2] + return { id, interpretationId } + } + loadVisualization = async location => { const { store } = this.context @@ -79,9 +86,8 @@ export class App extends Component { // /currentAnalyticalObject // /${id}/ // /${id}/interpretation/${interpretationId} - const pathParts = location.pathname.slice(1).split('/') - const id = pathParts[0] - const interpretationId = pathParts[2] + const { id, interpretationId } = this.parseLocation(location) + const urlContainsCurrentAOKey = id === CURRENT_AO_KEY if (urlContainsCurrentAOKey) { @@ -153,18 +159,28 @@ export class App extends Component { this.unlisten = history.listen(location => { const isSaving = location.state?.isSaving + const { interpretationId } = this.parseLocation(location) + if ( + // currently editing getVisualizationState( this.props.visualization, this.props.current ) === STATE_DIRTY && - this.state.locationToConfirm !== location && + // wanting to navigate elsewhere + this.state.previousLocation !== location.pathname && + // currently *not* viewing an interpretation + !(this.props.interpretation.id || interpretationId) && + // not saving !isSaving ) { this.setState({ locationToConfirm: location }) } else { + if (this.state.previousLocation !== location.pathname) { + this.loadVisualization(location) + } + this.setState({ locationToConfirm: null }) - this.loadVisualization(location) } }) @@ -258,21 +274,27 @@ export class App extends Component {