Skip to content

Commit cde854b

Browse files
authored
load assets lazily in es-ui plugins (#62487) (#62578)
* load assets lazily * addres cj comments
1 parent 307338f commit cde854b

File tree

7 files changed

+143
-60
lines changed

7 files changed

+143
-60
lines changed

src/plugins/share/public/services/short_url_redirect_app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import { CoreSetup } from 'kibana/public';
2121
import { getUrlIdFromGotoRoute, getUrlPath, GOTO_PREFIX } from '../../common/short_url_routes';
22-
import { hashUrl } from '../../../kibana_utils/public';
2322

2423
export const createShortUrlRedirectApp = (core: CoreSetup, location: Location) => ({
2524
id: 'short_url_redirect',
@@ -35,6 +34,7 @@ export const createShortUrlRedirectApp = (core: CoreSetup, location: Location) =
3534

3635
const response = await core.http.get<{ url: string }>(getUrlPath(urlId));
3736
const redirectUrl = response.url;
37+
const { hashUrl } = await import('../../../kibana_utils/public');
3838
const hashedUrl = hashUrl(redirectUrl);
3939
const url = core.http.basePath.prepend(hashedUrl);
4040

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import { CoreSetup } from 'src/core/public';
8+
import { ManagementAppMountParams } from 'src/plugins/management/public/';
9+
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
10+
11+
import { ExtensionsService } from '../services';
12+
import { IndexMgmtMetricsType } from '../types';
13+
import { AppDependencies } from './app_context';
14+
import { breadcrumbService } from './services/breadcrumbs';
15+
import { documentationService } from './services/documentation';
16+
import { HttpService, NotificationService, UiMetricService } from './services';
17+
18+
import { renderApp } from '.';
19+
20+
interface InternalServices {
21+
httpService: HttpService;
22+
notificationService: NotificationService;
23+
uiMetricService: UiMetricService<IndexMgmtMetricsType>;
24+
extensionsService: ExtensionsService;
25+
}
26+
27+
export async function mountManagementSection(
28+
coreSetup: CoreSetup,
29+
usageCollection: UsageCollectionSetup,
30+
services: InternalServices,
31+
params: ManagementAppMountParams
32+
) {
33+
const { element, setBreadcrumbs } = params;
34+
const [core] = await coreSetup.getStartServices();
35+
const { docLinks, fatalErrors } = core;
36+
37+
breadcrumbService.setup(setBreadcrumbs);
38+
documentationService.setup(docLinks);
39+
40+
const appDependencies: AppDependencies = {
41+
core: {
42+
fatalErrors,
43+
},
44+
plugins: {
45+
usageCollection,
46+
},
47+
services,
48+
};
49+
50+
return renderApp(element, { core, dependencies: appDependencies });
51+
}

x-pack/plugins/index_management/public/plugin.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/p
1010
import { ManagementSetup } from '../../../../src/plugins/management/public';
1111
import { UIM_APP_NAME, PLUGIN } from '../common/constants';
1212

13-
import { AppDependencies } from './application';
1413
import { httpService } from './application/services/http';
15-
import { breadcrumbService } from './application/services/breadcrumbs';
16-
import { documentationService } from './application/services/documentation';
1714
import { notificationService } from './application/services/notification';
1815
import { UiMetricService } from './application/services/ui_metric';
1916

@@ -44,7 +41,7 @@ export class IndexMgmtUIPlugin {
4441
}
4542

4643
public setup(coreSetup: CoreSetup, plugins: PluginsDependencies): IndexMgmtSetup {
47-
const { http, notifications, getStartServices } = coreSetup;
44+
const { http, notifications } = coreSetup;
4845
const { usageCollection, management } = plugins;
4946

5047
httpService.setup(http);
@@ -55,30 +52,15 @@ export class IndexMgmtUIPlugin {
5552
id: PLUGIN.id,
5653
title: i18n.translate('xpack.idxMgmt.appTitle', { defaultMessage: 'Index Management' }),
5754
order: 1,
58-
mount: async ({ element, setBreadcrumbs }) => {
59-
const [core] = await getStartServices();
60-
const { docLinks, fatalErrors } = core;
61-
62-
breadcrumbService.setup(setBreadcrumbs);
63-
documentationService.setup(docLinks);
64-
65-
const appDependencies: AppDependencies = {
66-
core: {
67-
fatalErrors,
68-
},
69-
plugins: {
70-
usageCollection,
71-
},
72-
services: {
73-
uiMetricService: this.uiMetricService,
74-
extensionsService: this.extensionsService,
75-
httpService,
76-
notificationService,
77-
},
55+
mount: async params => {
56+
const { mountManagementSection } = await import('./application/mount_management_section');
57+
const services = {
58+
httpService,
59+
notificationService,
60+
uiMetricService: this.uiMetricService,
61+
extensionsService: this.extensionsService,
7862
};
79-
80-
const { renderApp } = await import('./application');
81-
return renderApp(element, { core, dependencies: appDependencies });
63+
return mountManagementSection(coreSetup, usageCollection, services, params);
8264
},
8365
});
8466

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
import { CoreSetup } from 'src/core/public';
7+
import { ManagementAppMountParams } from 'src/plugins/management/public';
8+
import { i18n } from '@kbn/i18n';
9+
10+
import { ClientConfigType } from '../types';
11+
import { httpService } from './services/http';
12+
import { UiMetricService } from './services';
13+
import { breadcrumbService, docTitleService } from './services/navigation';
14+
import { documentationLinksService } from './services/documentation';
15+
import { AppDependencies } from './app_context';
16+
import { renderApp } from '.';
17+
18+
export async function mountManagementSection(
19+
coreSetup: CoreSetup,
20+
services: {
21+
uiMetricService: UiMetricService;
22+
},
23+
config: ClientConfigType,
24+
params: ManagementAppMountParams
25+
) {
26+
const { element, setBreadcrumbs } = params;
27+
const [core] = await coreSetup.getStartServices();
28+
const {
29+
docLinks,
30+
chrome: { docTitle },
31+
} = core;
32+
33+
docTitleService.setup(docTitle.change);
34+
breadcrumbService.setup(setBreadcrumbs);
35+
documentationLinksService.setup(docLinks);
36+
37+
const appDependencies: AppDependencies = {
38+
core,
39+
config,
40+
services: {
41+
httpService,
42+
uiMetricService: services.uiMetricService,
43+
i18n,
44+
},
45+
};
46+
47+
return renderApp(element, appDependencies);
48+
}

x-pack/plugins/snapshot_restore/public/plugin.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { CoreSetup, PluginInitializerContext } from 'src/core/public';
99
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';
1010
import { ManagementSetup } from '../../../../src/plugins/management/public';
1111
import { PLUGIN } from '../common/constants';
12-
import { AppDependencies } from './application';
12+
1313
import { ClientConfigType } from './types';
1414

15-
import { breadcrumbService, docTitleService } from './application/services/navigation';
16-
import { documentationLinksService } from './application/services/documentation';
1715
import { httpService, setUiMetricService } from './application/services/http';
1816
import { textService } from './application/services/text';
1917
import { UiMetricService } from './application/services';
@@ -34,7 +32,7 @@ export class SnapshotRestoreUIPlugin {
3432

3533
public setup(coreSetup: CoreSetup, plugins: PluginsDependencies): void {
3634
const config = this.initializerContext.config.get<ClientConfigType>();
37-
const { http, getStartServices } = coreSetup;
35+
const { http } = coreSetup;
3836
const { management, usageCollection } = plugins;
3937

4038
// Initialize services
@@ -48,29 +46,12 @@ export class SnapshotRestoreUIPlugin {
4846
defaultMessage: 'Snapshot and Restore',
4947
}),
5048
order: 7,
51-
mount: async ({ element, setBreadcrumbs }) => {
52-
const [core] = await getStartServices();
53-
const {
54-
docLinks,
55-
chrome: { docTitle },
56-
} = core;
57-
58-
docTitleService.setup(docTitle.change);
59-
breadcrumbService.setup(setBreadcrumbs);
60-
documentationLinksService.setup(docLinks);
61-
62-
const appDependencies: AppDependencies = {
63-
core,
64-
config,
65-
services: {
66-
httpService,
67-
uiMetricService: this.uiMetricService,
68-
i18n,
69-
},
49+
mount: async params => {
50+
const { mountManagementSection } = await import('./application/mount_management_section');
51+
const services = {
52+
uiMetricService: this.uiMetricService,
7053
};
71-
72-
const { renderApp } = await import('./application');
73-
return renderApp(element, appDependencies);
54+
return await mountManagementSection(coreSetup, services, config, params);
7455
},
7556
});
7657
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
import { CoreSetup } from 'src/core/public';
7+
import { ManagementAppMountParams } from '../../../../../src/plugins/management/public';
8+
import { renderApp } from './render_app';
9+
10+
export async function mountManagementSection(
11+
coreSetup: CoreSetup,
12+
isCloudEnabled: boolean,
13+
params: ManagementAppMountParams
14+
) {
15+
const [{ i18n, docLinks }] = await coreSetup.getStartServices();
16+
return renderApp({
17+
element: params.element,
18+
isCloudEnabled,
19+
http: coreSetup.http,
20+
i18n,
21+
docLinks,
22+
});
23+
}

x-pack/plugins/upgrade_assistant/public/plugin.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ import { ManagementSetup } from '../../../../src/plugins/management/public';
1212
import { NEXT_MAJOR_VERSION } from '../common/version';
1313
import { Config } from '../common/config';
1414

15-
import { renderApp } from './application/render_app';
16-
1715
interface Dependencies {
1816
cloud: CloudSetup;
1917
management: ManagementSetup;
2018
}
2119

2220
export class UpgradeAssistantUIPlugin implements Plugin {
2321
constructor(private ctx: PluginInitializerContext) {}
24-
setup({ http, getStartServices }: CoreSetup, { cloud, management }: Dependencies) {
22+
setup(coreSetup: CoreSetup, { cloud, management }: Dependencies) {
2523
const { enabled } = this.ctx.config.get<Config>();
2624
if (!enabled) {
2725
return;
@@ -36,9 +34,9 @@ export class UpgradeAssistantUIPlugin implements Plugin {
3634
values: { version: `${NEXT_MAJOR_VERSION}.0` },
3735
}),
3836
order: 1000,
39-
async mount({ element }) {
40-
const [{ i18n: i18nDep, docLinks }] = await getStartServices();
41-
return renderApp({ element, isCloudEnabled, http, i18n: i18nDep, docLinks });
37+
async mount(params) {
38+
const { mountManagementSection } = await import('./application/mount_management_section');
39+
return mountManagementSection(coreSetup, isCloudEnabled, params);
4240
},
4341
});
4442
}

0 commit comments

Comments
 (0)