Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Endpoint] add react router to endpoint app #53808

Merged
merged 12 commits into from
Jan 2, 2020
29 changes: 24 additions & 5 deletions x-pack/plugins/endpoint/public/applications/endpoint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,43 @@ import * as React from 'react';
import ReactDOM from 'react-dom';
import { CoreStart, AppMountParameters } from 'kibana/public';
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react';
import { History, createHashHistory } from 'history';
import { Route, Router, Switch } from 'react-router-dom';

/**
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle.
*/
export function renderApp(coreStart: CoreStart, { element }: AppMountParameters) {
coreStart.http.get('/api/endpoint/hello-world');

ReactDOM.render(<AppRoot />, element);
const history = createHashHistory()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kibana testing utils all seem to use hash history (see test below), doesn't mean we have to

ReactDOM.render(<AppRoot history={history}/>, element);

return () => {
ReactDOM.unmountComponentAtNode(element);
};
}

const AppRoot = React.memo(() => (
interface RouterProps {
history: History;
}

const AppRoot: React.FC<RouterProps> = React.memo(({history}) => (
<I18nProvider>
<h1 data-test-subj="welcomeTitle">
<FormattedMessage id="xpack.endpoint.welcomeTitle" defaultMessage="Hello World" />
</h1>
<Router history={history}>
<Switch>
<Route exact path="/" render={() => (
<h1 data-test-subj="welcomeTitle">
<FormattedMessage id="xpack.endpoint.welcomeTitle" defaultMessage="Hello World" />
</h1>
)} />
<Route path="/management" render={() => (
<h1 data-test-subj="management ">
<FormattedMessage id="xpack.endpoint.management" defaultMessage="Manage Endpoints" />
</h1>
)} />
<Route render={() => <FormattedMessage id="xpack.endpoint.notFound" defaultMessage="Page Not Found" />} />
</Switch>
</Router>
</I18nProvider>
));
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export default function({ getPageObjects, getService }: FtrProviderContext) {
});
await testSubjects.existOrFail('welcomeTitle');
});

it(`endpoint management shows 'Manage Endpoints'`, async () => {
await pageObjects.common.navigateToActualUrl('endpoint', '/management', {
basePath: '/s/custom_space',
ensureCurrentUrl: false,
shouldLoginIfPrompted: false,
});
await testSubjects.existOrFail('management');
});
});

describe('space with endpoint disabled', () => {
Expand Down