Skip to content

Commit

Permalink
Routing fixes (elastic#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
orouz committed Jan 13, 2022
1 parent 2f4fcd9 commit b80652f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
43 changes: 21 additions & 22 deletions x-pack/plugins/cloud_security_posture/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { I18nProvider } from '@kbn/i18n-react';
import { Router, Redirect, Switch, Route } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from 'react-query';
import { routes } from './routes';

import { UnknownRoute } from '../components/unknown_route';
import { CSP_DASHBOARD_PATH } from '../common/constants';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';

import type { AppMountParameters, CoreStart } from '../../../../../src/core/public';
import type { CspStart } from '../types';

Expand All @@ -24,22 +23,22 @@ interface CspAppDeps {
params: AppMountParameters;
}

export const CspApp = ({ core, deps, params }: CspAppDeps) => {
return (
<KibanaContextProvider services={{ ...deps, ...core }}>
<QueryClientProvider client={queryClient}>
<Router history={params.history}>
<I18nProvider>
<Switch>
{routes.map((route) => (
<Route {...route} />
))}
<Route exact path="/" component={() => <Redirect to="/dashboard" />} />
<Route path="*" component={() => <div>not found</div>} />
</Switch>
</I18nProvider>
</Router>
</QueryClientProvider>
</KibanaContextProvider>
);
};
export const CspApp = ({ core, deps, params }: CspAppDeps) => (
<KibanaContextProvider services={{ ...deps, ...core }}>
<QueryClientProvider client={queryClient}>
<Router history={params.history}>
<I18nProvider>
<Switch>
{routes.map((route) => (
<Route key={route.path as string} {...route} />
))}
<Route exact path="/" component={RedirectToDashboard} />
<Route path="*" component={UnknownRoute} />
</Switch>
</I18nProvider>
</Router>
</QueryClientProvider>
</KibanaContextProvider>
);

const RedirectToDashboard = () => <Redirect to={CSP_DASHBOARD_PATH} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiEmptyPrompt } from '@elastic/eui';
import { CspPageTemplate } from './page_template';

export const UnknownRoute = React.memo(() => (
<CspPageTemplate template="centeredContent">
<EuiEmptyPrompt
data-test-subj="unknownRoute"
iconColor="default"
iconType="logoElastic"
title={
<p>
<FormattedMessage id="xpack.csp.unknownRoute" defaultMessage="Page not found" />
</p>
}
/>
</CspPageTemplate>
));

0 comments on commit b80652f

Please sign in to comment.