From d2df9c0a72cb0f77a8deb3af14c699c91da005b7 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Fri, 24 Apr 2020 22:00:15 -0400 Subject: [PATCH] Fixed redirect when clicking on SM icon again --- .../public/angular/helpers/routes.ts | 2 +- .../plugins/monitoring/public/angular/index.ts | 18 +++++++++++++----- x-pack/plugins/monitoring/public/index.scss | 8 +++++++- x-pack/plugins/monitoring/public/plugin.ts | 17 +++++++++++++---- .../monitoring/public/views/no_data/index.js | 10 ++++------ 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/monitoring/public/angular/helpers/routes.ts b/x-pack/plugins/monitoring/public/angular/helpers/routes.ts index 176b7f154d2531..b9307e8594a7ae 100644 --- a/x-pack/plugins/monitoring/public/angular/helpers/routes.ts +++ b/x-pack/plugins/monitoring/public/angular/helpers/routes.ts @@ -11,7 +11,7 @@ interface Redirect { class Routes { private routes: RouteObject[] = []; - private redirect?: Redirect; + public redirect?: Redirect = { redirectTo: '/no-data' }; public when = (...args: RouteObject) => { const [, routeOptions] = args; diff --git a/x-pack/plugins/monitoring/public/angular/index.ts b/x-pack/plugins/monitoring/public/angular/index.ts index 6aba3339db95fd..b371503fdb7c95 100644 --- a/x-pack/plugins/monitoring/public/angular/index.ts +++ b/x-pack/plugins/monitoring/public/angular/index.ts @@ -12,7 +12,7 @@ import { localAppModule, appModuleName } from './app_modules'; import { MonitoringPluginDependencies } from '../types'; -const SAFARI_FIX = 'kbnLocalApplicationWrapper'; +const APP_WRAPPER_CLASS = 'monitoringApplicationWrapper'; export class AngularApp { private injector?: angular.auto.IInjectorService; @@ -41,11 +41,10 @@ export class AngularApp { configureAppAngularModule(app, np, true); const appElement = document.createElement('div'); appElement.setAttribute('style', 'height: 100%'); - appElement.setAttribute('class', SAFARI_FIX); - appElement.innerHTML = `
`; + appElement.innerHTML = '
'; - if (!element.classList.contains(SAFARI_FIX)) { - element.classList.add(SAFARI_FIX); + if (!element.classList.contains(APP_WRAPPER_CLASS)) { + element.classList.add(APP_WRAPPER_CLASS); } angular.bootstrap(appElement, [appModuleName]); @@ -57,4 +56,13 @@ export class AngularApp { this.injector.get('$rootScope').$destroy(); } }; + + public applyScope = () => { + if (!this.injector) { + return; + } + + const rootScope = this.injector.get('$rootScope'); + rootScope.$applyAsync(); + }; } diff --git a/x-pack/plugins/monitoring/public/index.scss b/x-pack/plugins/monitoring/public/index.scss index af1f1c92240acf..4dda80ee7454b6 100644 --- a/x-pack/plugins/monitoring/public/index.scss +++ b/x-pack/plugins/monitoring/public/index.scss @@ -21,4 +21,10 @@ @import 'components/logstash/pipeline_viewer/views/index'; @import 'components/elasticsearch/shard_allocation/index'; @import 'components/setup_mode/index'; -@import 'components/elasticsearch/ccr/index' +@import 'components/elasticsearch/ccr/index'; + +.monitoringApplicationWrapper { + display: flex; + flex-direction: column; + flex-grow: 1; +} diff --git a/x-pack/plugins/monitoring/public/plugin.ts b/x-pack/plugins/monitoring/public/plugin.ts index 14f3253d511557..6c50c6ae8b6393 100644 --- a/x-pack/plugins/monitoring/public/plugin.ts +++ b/x-pack/plugins/monitoring/public/plugin.ts @@ -8,7 +8,6 @@ import './views/all'; import { i18n } from '@kbn/i18n'; import { App, - AppMountContext, AppMountParameters, CoreSetup, CoreStart, @@ -22,11 +21,11 @@ import { import { initAngularBootstrap } from '../../../../src/plugins/kibana_legacy/public'; import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils'; import { MonitoringPluginDependencies, MonitoringConfig } from './types'; - import { MONITORING_CONFIG_ALERTING_EMAIL_ADDRESS, KIBANA_ALERTING_ENABLED, } from '../common/constants'; +import { uiRoutes } from './angular/helpers/routes'; export class MonitoringPlugin implements Plugin { @@ -72,7 +71,7 @@ export class MonitoringPlugin appRoute: path, euiIconType: icon, category: DEFAULT_APP_CATEGORIES.management, - mount: async (context: AppMountContext, params: AppMountParameters) => { + mount: async (params: AppMountParameters) => { const [coreStart, pluginsStart] = await core.getStartServices(); const { AngularApp } = await import('./angular'); const deps: MonitoringPluginDependencies = { @@ -89,7 +88,17 @@ export class MonitoringPlugin this.overrideAlertingEmailDefaults(deps); const monitoringApp = new AngularApp(deps); - return monitoringApp.destroy; + const removeHistoryListener = params.history.listen(location => { + if (location.pathname === '' && location.hash === '') { + params.history.push({ hash: uiRoutes.redirect?.redirectTo || '/no-data' }); + monitoringApp.applyScope(); + } + }); + + return () => { + removeHistoryListener(); + monitoringApp.destroy(); + }; }, }; diff --git a/x-pack/plugins/monitoring/public/views/no_data/index.js b/x-pack/plugins/monitoring/public/views/no_data/index.js index c427b15a5fd1e1..9876739dfcbbe6 100644 --- a/x-pack/plugins/monitoring/public/views/no_data/index.js +++ b/x-pack/plugins/monitoring/public/views/no_data/index.js @@ -8,9 +8,7 @@ import { uiRoutes } from '../../angular/helpers/routes'; import template from './index.html'; import { NoDataController } from './controller'; -uiRoutes - .when('/no-data', { - template, - controller: NoDataController, - }) - .otherwise({ redirectTo: '/home' }); +uiRoutes.when('/no-data', { + template, + controller: NoDataController, +});