Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] load assets lazily in es-ui plugins (#62487) #62578

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { CoreSetup } from 'kibana/public';
import { getUrlIdFromGotoRoute, getUrlPath, GOTO_PREFIX } from '../../common/short_url_routes';
import { hashUrl } from '../../../kibana_utils/public';

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup } from 'src/core/public';
import { ManagementAppMountParams } from 'src/plugins/management/public/';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';

import { ExtensionsService } from '../services';
import { IndexMgmtMetricsType } from '../types';
import { AppDependencies } from './app_context';
import { breadcrumbService } from './services/breadcrumbs';
import { documentationService } from './services/documentation';
import { HttpService, NotificationService, UiMetricService } from './services';

import { renderApp } from '.';

interface InternalServices {
httpService: HttpService;
notificationService: NotificationService;
uiMetricService: UiMetricService<IndexMgmtMetricsType>;
extensionsService: ExtensionsService;
}

export async function mountManagementSection(
coreSetup: CoreSetup,
usageCollection: UsageCollectionSetup,
services: InternalServices,
params: ManagementAppMountParams
) {
const { element, setBreadcrumbs } = params;
const [core] = await coreSetup.getStartServices();
const { docLinks, fatalErrors } = core;

breadcrumbService.setup(setBreadcrumbs);
documentationService.setup(docLinks);

const appDependencies: AppDependencies = {
core: {
fatalErrors,
},
plugins: {
usageCollection,
},
services,
};

return renderApp(element, { core, dependencies: appDependencies });
}
36 changes: 9 additions & 27 deletions x-pack/plugins/index_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/p
import { ManagementSetup } from '../../../../src/plugins/management/public';
import { UIM_APP_NAME, PLUGIN } from '../common/constants';

import { AppDependencies } from './application';
import { httpService } from './application/services/http';
import { breadcrumbService } from './application/services/breadcrumbs';
import { documentationService } from './application/services/documentation';
import { notificationService } from './application/services/notification';
import { UiMetricService } from './application/services/ui_metric';

Expand Down Expand Up @@ -44,7 +41,7 @@ export class IndexMgmtUIPlugin {
}

public setup(coreSetup: CoreSetup, plugins: PluginsDependencies): IndexMgmtSetup {
const { http, notifications, getStartServices } = coreSetup;
const { http, notifications } = coreSetup;
const { usageCollection, management } = plugins;

httpService.setup(http);
Expand All @@ -55,30 +52,15 @@ export class IndexMgmtUIPlugin {
id: PLUGIN.id,
title: i18n.translate('xpack.idxMgmt.appTitle', { defaultMessage: 'Index Management' }),
order: 1,
mount: async ({ element, setBreadcrumbs }) => {
const [core] = await getStartServices();
const { docLinks, fatalErrors } = core;

breadcrumbService.setup(setBreadcrumbs);
documentationService.setup(docLinks);

const appDependencies: AppDependencies = {
core: {
fatalErrors,
},
plugins: {
usageCollection,
},
services: {
uiMetricService: this.uiMetricService,
extensionsService: this.extensionsService,
httpService,
notificationService,
},
mount: async params => {
const { mountManagementSection } = await import('./application/mount_management_section');
const services = {
httpService,
notificationService,
uiMetricService: this.uiMetricService,
extensionsService: this.extensionsService,
};

const { renderApp } = await import('./application');
return renderApp(element, { core, dependencies: appDependencies });
return mountManagementSection(coreSetup, usageCollection, services, params);
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreSetup } from 'src/core/public';
import { ManagementAppMountParams } from 'src/plugins/management/public';
import { i18n } from '@kbn/i18n';

import { ClientConfigType } from '../types';
import { httpService } from './services/http';
import { UiMetricService } from './services';
import { breadcrumbService, docTitleService } from './services/navigation';
import { documentationLinksService } from './services/documentation';
import { AppDependencies } from './app_context';
import { renderApp } from '.';

export async function mountManagementSection(
coreSetup: CoreSetup,
services: {
uiMetricService: UiMetricService;
},
config: ClientConfigType,
params: ManagementAppMountParams
) {
const { element, setBreadcrumbs } = params;
const [core] = await coreSetup.getStartServices();
const {
docLinks,
chrome: { docTitle },
} = core;

docTitleService.setup(docTitle.change);
breadcrumbService.setup(setBreadcrumbs);
documentationLinksService.setup(docLinks);

const appDependencies: AppDependencies = {
core,
config,
services: {
httpService,
uiMetricService: services.uiMetricService,
i18n,
},
};

return renderApp(element, appDependencies);
}
33 changes: 7 additions & 26 deletions x-pack/plugins/snapshot_restore/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { CoreSetup, PluginInitializerContext } from 'src/core/public';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';
import { ManagementSetup } from '../../../../src/plugins/management/public';
import { PLUGIN } from '../common/constants';
import { AppDependencies } from './application';

import { ClientConfigType } from './types';

import { breadcrumbService, docTitleService } from './application/services/navigation';
import { documentationLinksService } from './application/services/documentation';
import { httpService, setUiMetricService } from './application/services/http';
import { textService } from './application/services/text';
import { UiMetricService } from './application/services';
Expand All @@ -34,7 +32,7 @@ export class SnapshotRestoreUIPlugin {

public setup(coreSetup: CoreSetup, plugins: PluginsDependencies): void {
const config = this.initializerContext.config.get<ClientConfigType>();
const { http, getStartServices } = coreSetup;
const { http } = coreSetup;
const { management, usageCollection } = plugins;

// Initialize services
Expand All @@ -48,29 +46,12 @@ export class SnapshotRestoreUIPlugin {
defaultMessage: 'Snapshot and Restore',
}),
order: 7,
mount: async ({ element, setBreadcrumbs }) => {
const [core] = await getStartServices();
const {
docLinks,
chrome: { docTitle },
} = core;

docTitleService.setup(docTitle.change);
breadcrumbService.setup(setBreadcrumbs);
documentationLinksService.setup(docLinks);

const appDependencies: AppDependencies = {
core,
config,
services: {
httpService,
uiMetricService: this.uiMetricService,
i18n,
},
mount: async params => {
const { mountManagementSection } = await import('./application/mount_management_section');
const services = {
uiMetricService: this.uiMetricService,
};

const { renderApp } = await import('./application');
return renderApp(element, appDependencies);
return await mountManagementSection(coreSetup, services, config, params);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreSetup } from 'src/core/public';
import { ManagementAppMountParams } from '../../../../../src/plugins/management/public';
import { renderApp } from './render_app';

export async function mountManagementSection(
coreSetup: CoreSetup,
isCloudEnabled: boolean,
params: ManagementAppMountParams
) {
const [{ i18n, docLinks }] = await coreSetup.getStartServices();
return renderApp({
element: params.element,
isCloudEnabled,
http: coreSetup.http,
i18n,
docLinks,
});
}
10 changes: 4 additions & 6 deletions x-pack/plugins/upgrade_assistant/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import { ManagementSetup } from '../../../../src/plugins/management/public';
import { NEXT_MAJOR_VERSION } from '../common/version';
import { Config } from '../common/config';

import { renderApp } from './application/render_app';

interface Dependencies {
cloud: CloudSetup;
management: ManagementSetup;
}

export class UpgradeAssistantUIPlugin implements Plugin {
constructor(private ctx: PluginInitializerContext) {}
setup({ http, getStartServices }: CoreSetup, { cloud, management }: Dependencies) {
setup(coreSetup: CoreSetup, { cloud, management }: Dependencies) {
const { enabled } = this.ctx.config.get<Config>();
if (!enabled) {
return;
Expand All @@ -36,9 +34,9 @@ export class UpgradeAssistantUIPlugin implements Plugin {
values: { version: `${NEXT_MAJOR_VERSION}.0` },
}),
order: 1000,
async mount({ element }) {
const [{ i18n: i18nDep, docLinks }] = await getStartServices();
return renderApp({ element, isCloudEnabled, http, i18n: i18nDep, docLinks });
async mount(params) {
const { mountManagementSection } = await import('./application/mount_management_section');
return mountManagementSection(coreSetup, isCloudEnabled, params);
},
});
}
Expand Down