Skip to content

Commit

Permalink
[ML] Removing context API (elastic#52953)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Dec 13, 2019
1 parent 938c704 commit ce496b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
19 changes: 11 additions & 8 deletions x-pack/legacy/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import 'ui/autoload/all';

// needed to make syntax highlighting work in ace editors
import 'ace';

import { AppMountContext, AppMountParameters } from 'kibana/public';
import { AppMountParameters, CoreStart } from 'kibana/public';
import {
IndexPatternsContract,
Plugin as DataPlugin,
Expand All @@ -30,24 +29,28 @@ export interface MlDependencies extends AppMountParameters {
}

interface AppProps {
context: AppMountContext;
coreStart: CoreStart;
indexPatterns: IndexPatternsContract;
}

const App: FC<AppProps> = ({ context, indexPatterns }) => {
const config = (context.core.uiSettings as never) as KibanaConfigTypeFix; // TODO - make this UiSettingsClientContract, get rid of KibanaConfigTypeFix
const App: FC<AppProps> = ({ coreStart, indexPatterns }) => {
const config = (coreStart.uiSettings as never) as KibanaConfigTypeFix; // TODO - make this UiSettingsClientContract, get rid of KibanaConfigTypeFix

return (
<MlRouter
config={config}
setBreadcrumbs={context.core.chrome.setBreadcrumbs}
setBreadcrumbs={coreStart.chrome.setBreadcrumbs}
indexPatterns={indexPatterns}
/>
);
};

export const renderApp = (context: AppMountContext, { element, indexPatterns }: MlDependencies) => {
ReactDOM.render(<App context={context} indexPatterns={indexPatterns} />, element);
export const renderApp = (
coreStart: CoreStart,
depsStart: object,
{ element, indexPatterns }: MlDependencies
) => {
ReactDOM.render(<App coreStart={coreStart} indexPatterns={indexPatterns} />, element);

return () => ReactDOM.unmountComponentAtNode(element);
};
10 changes: 2 additions & 8 deletions x-pack/legacy/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@ export interface MlSetupDependencies {
npData: ReturnType<DataPlugin['start']>;
}

export interface MlStartDependencies {
__LEGACY: {
Storage: any;
xpackInfo: any;
};
}

export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
setup(core: CoreSetup, { npData }: MlSetupDependencies) {
core.application.register({
id: 'ml',
title: 'Machine learning',
async mount(context, params) {
const [coreStart, depsStart] = await core.getStartServices();
const { renderApp } = await import('./application/app');
return renderApp(context, {
return renderApp(coreStart, depsStart, {
...params,
indexPatterns: npData.indexPatterns,
npData,
Expand Down

0 comments on commit ce496b3

Please sign in to comment.