From a816f8904d4a9474308845537a85ff64f71156b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Tue, 3 Oct 2017 15:46:17 +0200 Subject: [PATCH] SONAR-9446 Redirect to previous page after server start/migration --- .../main/js/app/components/MigrationContainer.js | 13 ++++++++----- .../components/MaintenanceAppContainer.tsx | 8 ++++++-- .../maintenance/components/SetupAppContainer.tsx | 8 ++++++-- .../sonar-web/src/main/js/apps/maintenance/init.js | 4 ++-- .../src/main/js/apps/maintenance/main-view.js | 8 ++++---- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/MigrationContainer.js b/server/sonar-web/src/main/js/app/components/MigrationContainer.js index ef24c09e991..04055272af3 100644 --- a/server/sonar-web/src/main/js/app/components/MigrationContainer.js +++ b/server/sonar-web/src/main/js/app/components/MigrationContainer.js @@ -27,20 +27,23 @@ class MigrationContainer extends React.PureComponent { /*:: props: { children?: React.Element<*>, - router: { push: (path: string) => void } + router: { push: ({ pathname: string, query?: { return_to: string } }) => void } }; */ - state = { - loading: true - }; + state = { loading: true }; componentDidMount() { getSystemStatus().then(r => { if (r.status === 'UP') { this.setState({ loading: false }); } else { - this.props.router.push('/maintenance'); + this.props.router.push({ + pathname: '/maintenance', + query: { + return_to: window.location.pathname + window.location.search + window.location.hash + } + }); } }); } diff --git a/server/sonar-web/src/main/js/apps/maintenance/components/MaintenanceAppContainer.tsx b/server/sonar-web/src/main/js/apps/maintenance/components/MaintenanceAppContainer.tsx index 923d805efd7..58f06438b41 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/components/MaintenanceAppContainer.tsx +++ b/server/sonar-web/src/main/js/apps/maintenance/components/MaintenanceAppContainer.tsx @@ -20,9 +20,13 @@ import * as React from 'react'; import init from '../init'; -export default class MaintenanceAppContainer extends React.PureComponent { +interface Props { + location: { query: { return_to: string } }; +} + +export default class MaintenanceAppContainer extends React.PureComponent { componentDidMount() { - init(this.refs.container, false); + init(this.refs.container, false, this.props.location.query['return_to']); } render() { diff --git a/server/sonar-web/src/main/js/apps/maintenance/components/SetupAppContainer.tsx b/server/sonar-web/src/main/js/apps/maintenance/components/SetupAppContainer.tsx index 398ebb69fd6..eeb57f47fe4 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/components/SetupAppContainer.tsx +++ b/server/sonar-web/src/main/js/apps/maintenance/components/SetupAppContainer.tsx @@ -20,9 +20,13 @@ import * as React from 'react'; import init from '../init'; -export default class SetupAppContainer extends React.PureComponent { +interface Props { + location: { query: { return_to: string } }; +} + +export default class SetupAppContainer extends React.PureComponent { componentDidMount() { - init(this.refs.container, true); + init(this.refs.container, true, this.props.location.query['return_to']); } render() { diff --git a/server/sonar-web/src/main/js/apps/maintenance/init.js b/server/sonar-web/src/main/js/apps/maintenance/init.js index 3d86d8fc881..e71347b423b 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/init.js +++ b/server/sonar-web/src/main/js/apps/maintenance/init.js @@ -32,6 +32,6 @@ App.on('start', options => { mainView.render().refresh(); }); -export default function(el, setup) { - App.start({ el, setup }); +export default function(el, setup, returnTo) { + App.start({ el, setup, returnTo }); } diff --git a/server/sonar-web/src/main/js/apps/maintenance/main-view.js b/server/sonar-web/src/main/js/apps/maintenance/main-view.js index 68b234721bf..26ed8f944ba 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/main-view.js +++ b/server/sonar-web/src/main/js/apps/maintenance/main-view.js @@ -51,10 +51,10 @@ export default Marionette.ItemView.extend({ this.stopPolling(); } if (this.model.get('status') === 'UP' && this.wasStarting) { - this.goHome(); + this.loadPreviousPage(); } if (this.model.get('state') === 'MIGRATION_SUCCEEDED') { - this.goHome(); + this.loadPreviousPage(); } }); }, @@ -80,9 +80,9 @@ export default Marionette.ItemView.extend({ ); }, - goHome() { + loadPreviousPage() { setInterval(() => { - window.location = window.baseUrl + '/'; + window.location = window.baseUrl + (this.options.returnTo || '/'); }, 2500); }, -- 2.39.5