Skip to content

Commit

Permalink
refactor plugin setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Apr 6, 2020
1 parent 5a536bd commit ef2f1ab
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
34 changes: 6 additions & 28 deletions x-pack/plugins/ingest_pipelines/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
},
});
}
Expand Down

0 comments on commit ef2f1ab

Please sign in to comment.