Skip to content

Commit

Permalink
Fixed redirect when clicking on SM icon again
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic committed Apr 25, 2020
1 parent 3335746 commit d2df9c0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/public/angular/helpers/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions x-pack/plugins/monitoring/public/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = `<div ng-view style="height: 100%" id="monitoring-angular-app" class="${SAFARI_FIX}"></div>`;
appElement.innerHTML = '<div ng-view style="height: 100%" id="monitoring-angular-app"></div>';

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]);
Expand All @@ -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();
};
}
8 changes: 7 additions & 1 deletion x-pack/plugins/monitoring/public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 13 additions & 4 deletions x-pack/plugins/monitoring/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import './views/all';
import { i18n } from '@kbn/i18n';
import {
App,
AppMountContext,
AppMountParameters,
CoreSetup,
CoreStart,
Expand All @@ -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<void, void, MonitoringPluginDependencies, MonitoringPluginDependencies> {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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();
};
},
};

Expand Down
10 changes: 4 additions & 6 deletions x-pack/plugins/monitoring/public/views/no_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

0 comments on commit d2df9c0

Please sign in to comment.