From ef2f1abaedceff63d4ee9745ed09173eadbd1883 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Mon, 6 Apr 2020 17:43:46 -0400 Subject: [PATCH] refactor plugin setup --- .../application/mount_management_section.ts | 42 +++++++++++++++++++ .../plugins/ingest_pipelines/public/plugin.ts | 34 +++------------ 2 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 x-pack/plugins/ingest_pipelines/public/application/mount_management_section.ts diff --git a/x-pack/plugins/ingest_pipelines/public/application/mount_management_section.ts b/x-pack/plugins/ingest_pipelines/public/application/mount_management_section.ts new file mode 100644 index 0000000000000..29db501488e53 --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/mount_management_section.ts @@ -0,0 +1,42 @@ +/* + * 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 { documentationService, uiMetricService, apiService } from './services'; +import { renderApp } from '.'; + +export async function mountManagementSection( + coreSetup: CoreSetup, + params: ManagementAppMountParams +) { + const { element, setBreadcrumbs } = params; + const [coreStart] = await coreSetup.getStartServices(); + const { + docLinks, + i18n: { Context: I18nContext }, + } = coreStart; + + documentationService.setup(docLinks); + + setBreadcrumbs([ + { + text: i18n.translate('xpack.ingestPipelines.breadcrumbsTitle', { + defaultMessage: 'Ingest Pipelines', + }), + }, + ]); + + const services = { + setBreadcrumbs, + metric: uiMetricService, + documentation: documentationService, + api: apiService, + }; + + return renderApp(element, I18nContext, services); +} diff --git a/x-pack/plugins/ingest_pipelines/public/plugin.ts b/x-pack/plugins/ingest_pipelines/public/plugin.ts index 0e505f3a8d394..7d8eb73d35a19 100644 --- a/x-pack/plugins/ingest_pipelines/public/plugin.ts +++ b/x-pack/plugins/ingest_pipelines/public/plugin.ts @@ -8,13 +8,13 @@ import { i18n } from '@kbn/i18n'; import { CoreSetup, Plugin } from 'src/core/public'; import { PLUGIN_ID } from '../common/constants'; -import { documentationService, uiMetricService, apiService } from './application/services'; +import { uiMetricService, apiService } from './application/services'; import { Dependencies } from './types'; export class IngestPipelinesPlugin implements Plugin { public setup(coreSetup: CoreSetup, plugins: Dependencies): void { const { management, usageCollection } = plugins; - const { http, getStartServices } = coreSetup; + const { http } = coreSetup; // Initialize services apiService.setup(http); @@ -25,32 +25,10 @@ export class IngestPipelinesPlugin implements Plugin { title: i18n.translate('xpack.ingestPipelines.appTitle', { defaultMessage: 'Ingest Pipelines', }), - mount: async ({ element, setBreadcrumbs }) => { - const [coreStart] = await getStartServices(); - const { - docLinks, - i18n: { Context: I18nContext }, - } = coreStart; - - documentationService.setup(docLinks); - - setBreadcrumbs([ - { - text: i18n.translate('xpack.ingestPipelines.breadcrumbsTitle', { - defaultMessage: 'Ingest Pipelines', - }), - }, - ]); - - const services = { - setBreadcrumbs, - metric: uiMetricService, - documentation: documentationService, - api: apiService, - }; - - const { renderApp } = await import('./application'); - return renderApp(element, I18nContext, services); + mount: async params => { + const { mountManagementSection } = await import('./application/mount_management_section'); + + return await mountManagementSection(coreSetup, params); }, }); }