Skip to content

Commit 16c751d

Browse files
use i18n context from core
1 parent 04e3001 commit 16c751d

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

x-pack/legacy/plugins/index_management/public/app/constants/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export {
1313
TAB_STATS,
1414
TAB_EDIT_SETTINGS,
1515
} from './detail_panel_tabs';
16+
17+
export const REACT_ROOT_ID = 'indexManagementReactRoot';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { Provider } from 'react-redux';
9+
import { render, unmountComponentAtNode } from 'react-dom';
10+
11+
import { App } from './app';
12+
import { indexManagementStore } from './store';
13+
14+
export const mountReactApp = (elem: HTMLElement | null, { core }: { core: Core }): void => {
15+
if (elem) {
16+
const { notifications, i18n } = core;
17+
const { Context: I18nContext } = i18n;
18+
19+
render(
20+
<I18nContext>
21+
<Provider store={indexManagementStore()}>
22+
<App />
23+
</Provider>
24+
</I18nContext>,
25+
elem
26+
);
27+
}
28+
};
29+
30+
export const unmountReactApp = (elem: HTMLElement | null) => {
31+
if (elem) {
32+
unmountComponentAtNode(elem);
33+
}
34+
};

x-pack/legacy/plugins/index_management/public/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export class IndexMgmtPlugin {
2727

2828
// Register management section and Angular route
2929
registerManagementSection(management.getSection('elasticsearch'));
30-
registerRoutes();
30+
registerRoutes(core as CoreStart);
3131
}
3232
}

x-pack/legacy/plugins/index_management/public/register_routes.tsx

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,31 @@
77
import React from 'react';
88
import { render, unmountComponentAtNode } from 'react-dom';
99
import { Provider } from 'react-redux';
10+
1011
import routes from 'ui/routes';
11-
import { I18nContext } from 'ui/i18n';
1212

13-
import { App } from './app/app';
14-
import { BASE_PATH } from '../common/constants/base_path';
13+
import { CoreStart } from '../../../../../src/core/public';
14+
15+
import { mountReactApp, unmountReactApp } from './app';
16+
import { REACT_ROOT_ID } from './app/constants';
17+
import { BASE_PATH } from '../common/constants';
1518

1619
import template from './index.html';
1720
import { manageAngularLifecycle } from './app/lib/manage_angular_lifecycle';
18-
import { indexManagementStore } from './app/store';
1921

2022
let elem: HTMLElement | null;
2123

22-
const renderReact = async () => {
23-
render(
24-
<I18nContext>
25-
<Provider store={indexManagementStore()}>
26-
<App />
27-
</Provider>
28-
</I18nContext>,
29-
elem
30-
);
31-
};
32-
33-
export const registerRoutes = () => {
24+
export const registerRoutes = (core: CoreStart) => {
3425
routes.when(`${BASE_PATH}:view?/:action?/:id?`, {
3526
template,
3627
controller: ($scope: any, $route: any) => {
3728
// clean up previously rendered React app if one exists
3829
// this happens because of React Router redirects
39-
if (elem) {
40-
unmountComponentAtNode(elem);
41-
}
30+
unmountReactApp(elem);
4231

4332
$scope.$$postDigest(() => {
44-
elem = document.getElementById('indexManagementReactRoot');
45-
renderReact();
33+
elem = document.getElementById(REACT_ROOT_ID);
34+
mountReactApp(elem, { core });
4635
manageAngularLifecycle($scope, $route, elem);
4736
});
4837
},

0 commit comments

Comments
 (0)