Skip to content

Commit 7a5028d

Browse files
authored
Add loading page (#75362) (#75483)
1 parent ce730aa commit 7a5028d

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines changed

x-pack/plugins/monitoring/public/directives/main/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class MonitoringMainController {
205205

206206
export function monitoringMainProvider(breadcrumbs, license, $injector) {
207207
const $executor = $injector.get('$executor');
208+
const $parse = $injector.get('$parse');
208209

209210
return {
210211
restrict: 'E',
@@ -221,6 +222,10 @@ export function monitoringMainProvider(breadcrumbs, license, $injector) {
221222
Object.keys(setupObj.attributes).forEach((key) => {
222223
attributes.$observe(key, () => controller.setup(getSetupObj()));
223224
});
225+
if (attributes.onLoaded) {
226+
const onLoaded = $parse(attributes.onLoaded)(scope);
227+
onLoaded();
228+
}
224229
});
225230

226231
initSetupModeState(scope, $injector, () => {

x-pack/plugins/monitoring/public/views/all.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ import './beats/beat';
3535
import './apm/overview';
3636
import './apm/instances';
3737
import './apm/instance';
38+
import './loading';

x-pack/plugins/monitoring/public/views/cluster/listing/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ uiRoutes
7979
}
8080
},
8181
})
82-
.otherwise({ redirectTo: '/no-data' });
82+
.otherwise({ redirectTo: '/loading' });
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<monitoring-main name="overview" data-test-subj="clusterOverviewContainer">
1+
<monitoring-main name="overview" data-test-subj="clusterOverviewContainer" on-loaded="monitoringClusterOverview.init">
22
<div id="monitoringClusterOverviewApp"></div>
33
</monitoring-main>

x-pack/plugins/monitoring/public/views/cluster/overview/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ uiRoutes.when('/overview', {
2525
return routeInit({ codePaths: CODE_PATHS });
2626
},
2727
},
28+
controllerAs: 'monitoringClusterOverview',
2829
controller: class extends MonitoringViewBaseController {
2930
constructor($injector, $scope) {
3031
const monitoringClusters = $injector.get('monitoringClusters');
@@ -52,6 +53,8 @@ uiRoutes.when('/overview', {
5253
},
5354
});
5455

56+
this.init = () => this.renderReact(null);
57+
5558
$scope.$watch(
5659
() => this.data,
5760
async (data) => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<monitoring-main name="no-data" on-loaded="monitoringLoading.init">
2+
<div data-test-subj="monitoringLoadingContainer">
3+
<div id="monitoringLoadingReact"></div>
4+
</div>
5+
</monitoring-main>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
/**
8+
* Controller for single index detail
9+
*/
10+
import React from 'react';
11+
import { render } from 'react-dom';
12+
import { i18n } from '@kbn/i18n';
13+
import { uiRoutes } from '../../angular/helpers/routes';
14+
import { routeInitProvider } from '../../lib/route_init';
15+
import template from './index.html';
16+
import { Legacy } from '../../legacy_shims';
17+
import { CODE_PATH_ELASTICSEARCH } from '../../../common/constants';
18+
import { PageLoading } from '../../components';
19+
20+
const CODE_PATHS = [CODE_PATH_ELASTICSEARCH];
21+
uiRoutes.when('/loading', {
22+
template,
23+
controllerAs: 'monitoringLoading',
24+
controller: class {
25+
constructor($injector, $scope) {
26+
const Private = $injector.get('Private');
27+
const titleService = $injector.get('title');
28+
titleService(
29+
$scope.cluster,
30+
i18n.translate('xpack.monitoring.loading.pageTitle', {
31+
defaultMessage: 'Loading',
32+
})
33+
);
34+
35+
this.init = () => {
36+
const reactNodeId = 'monitoringLoadingReact';
37+
const renderElement = document.getElementById(reactNodeId);
38+
if (!renderElement) {
39+
console.warn(`"#${reactNodeId}" element has not been added to the DOM yet`);
40+
return;
41+
}
42+
const I18nContext = Legacy.shims.I18nContext;
43+
render(
44+
<I18nContext>
45+
<PageLoading />
46+
</I18nContext>,
47+
renderElement
48+
);
49+
};
50+
51+
const routeInit = Private(routeInitProvider);
52+
routeInit({ codePaths: CODE_PATHS, fetchAllClusters: true }).then((clusters) => {
53+
if (!clusters || !clusters.length) {
54+
window.location.hash = '#/no-data';
55+
return;
56+
}
57+
if (clusters.length === 1) {
58+
// Bypass the cluster listing if there is just 1 cluster
59+
window.history.replaceState(null, null, '#/overview');
60+
return;
61+
}
62+
63+
window.history.replaceState(null, null, '#/home');
64+
});
65+
}
66+
},
67+
});

0 commit comments

Comments
 (0)