Skip to content

Commit

Permalink
ml async assets loading (#62403)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov authored Apr 3, 2020
1 parent 2e7448f commit 048a854
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 3 additions & 7 deletions x-pack/plugins/ml/public/application/management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import { LICENSE_CHECK_STATE } from '../../../../licensing/public';
import { PLUGIN_ID, PLUGIN_ICON } from '../../../common/constants/app';
import { MINIMUM_FULL_LICENSE } from '../../../common/license';

import { getJobsListBreadcrumbs } from './breadcrumbs';
import { renderApp } from './jobs_list';

export function initManagementSection(
pluginsSetup: MlSetupDependencies,
core: CoreSetup<MlStartDependencies>
Expand All @@ -47,10 +44,9 @@ export function initManagementSection(
defaultMessage: 'Jobs list',
}),
order: 10,
async mount({ element, setBreadcrumbs }) {
const [coreStart] = await core.getStartServices();
setBreadcrumbs(getJobsListBreadcrumbs());
return renderApp(element, coreStart);
async mount(params) {
const { mountApp } = await import('./jobs_list');
return mountApp(core, params);
},
});
}
Expand Down
16 changes: 14 additions & 2 deletions x-pack/plugins/ml/public/application/management/jobs_list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@

import ReactDOM, { unmountComponentAtNode } from 'react-dom';
import React from 'react';
import { CoreStart } from 'kibana/public';
import { CoreSetup, CoreStart } from 'kibana/public';
import { ManagementAppMountParams } from '../../../../../../../src/plugins/management/public/';
import { MlStartDependencies } from '../../../plugin';
import { JobsListPage } from './components';
import { getJobsListBreadcrumbs } from '../breadcrumbs';

export const renderApp = (element: HTMLElement, coreStart: CoreStart) => {
const renderApp = (element: HTMLElement, coreStart: CoreStart) => {
const I18nContext = coreStart.i18n.Context;
ReactDOM.render(React.createElement(JobsListPage, { I18nContext }), element);
return () => {
unmountComponentAtNode(element);
};
};

export async function mountApp(
core: CoreSetup<MlStartDependencies>,
params: ManagementAppMountParams
) {
const [coreStart] = await core.getStartServices();
params.setBreadcrumbs(getJobsListBreadcrumbs());
return renderApp(params.element, coreStart);
}

0 comments on commit 048a854

Please sign in to comment.