Skip to content

Commit

Permalink
Split link-to into Metrics and Logs routers
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Mar 24, 2020
1 parent 676a03d commit 1ce87d8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/infra/public/pages/link_to/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { LinkToPage } from './link_to';
export { LinkToLogsPage } from './link_to_logs';
export { LinkToMetricsPage } from './link_to_metrics';
export { getNodeLogsUrl, RedirectToNodeLogs } from './redirect_to_node_logs';
export { getNodeDetailUrl, RedirectToNodeDetail } from './redirect_to_node_detail';
35 changes: 35 additions & 0 deletions x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { match as RouteMatch, Redirect, Route, Switch } from 'react-router-dom';

import { RedirectToLogs } from './redirect_to_logs';
import { RedirectToNodeLogs } from './redirect_to_node_logs';
import { inventoryModels } from '../../../common/inventory_models';

interface LinkToPageProps {
match: RouteMatch<{}>;
location: {
search: string;
};
}

const ITEM_TYPES = inventoryModels.map(m => m.id).join('|');

export const LinkToLogsPage: React.FC<LinkToPageProps> = props => {
return (
<Switch>
<Route
path={`${props.match.url}/:sourceId?/:nodeType(${ITEM_TYPES})-logs/:nodeId`}
component={RedirectToNodeLogs}
/>
<Route path={`${props.match.url}/:sourceId?/stream`} component={RedirectToLogs} />
<Redirect from={`${props.match.url}/logs`} to={`/link-to/stream?${props.location.search}`} />
<Redirect to="/" />
</Switch>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import React from 'react';
import { match as RouteMatch, Redirect, Route, Switch } from 'react-router-dom';

import { RedirectToLogs } from './redirect_to_logs';
import { RedirectToNodeDetail } from './redirect_to_node_detail';
import { RedirectToNodeLogs } from './redirect_to_node_logs';
import { RedirectToHostDetailViaIP } from './redirect_to_host_detail_via_ip';
import { inventoryModels } from '../../../common/inventory_models';

Expand All @@ -19,13 +17,9 @@ interface LinkToPageProps {

const ITEM_TYPES = inventoryModels.map(m => m.id).join('|');

export const LinkToPage: React.FC<LinkToPageProps> = props => {
export const LinkToMetricsPage: React.FC<LinkToPageProps> = props => {
return (
<Switch>
<Route
path={`${props.match.url}/:sourceId?/:nodeType(${ITEM_TYPES})-logs/:nodeId`}
component={RedirectToNodeLogs}
/>
<Route
path={`${props.match.url}/:nodeType(${ITEM_TYPES})-detail/:nodeId`}
component={RedirectToNodeDetail}
Expand All @@ -34,8 +28,7 @@ export const LinkToPage: React.FC<LinkToPageProps> = props => {
path={`${props.match.url}/host-detail-via-ip/:hostIp`}
component={RedirectToHostDetailViaIP}
/>
<Route path={`${props.match.url}/:sourceId?/logs`} component={RedirectToLogs} />
<Redirect to="/infrastructure" />
<Redirect to="/" />
</Switch>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { compose } from 'lodash';
import compose from 'lodash/fp/compose';
import React from 'react';
import { match as RouteMatch, Redirect, RouteComponentProps } from 'react-router-dom';

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/routers/logs_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import { Route, Router, Switch } from 'react-router-dom';

import { NotFoundPage } from '../pages/404';
import { LinkToPage } from '../pages/link_to';
import { LinkToLogsPage } from '../pages/link_to';
import { LogsPage } from '../pages/logs';
import { RedirectWithQueryParams } from '../utils/redirect_with_query_params';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
Expand All @@ -19,7 +19,7 @@ export const LogsRouter: AppRouter = ({ history }) => {
return (
<Router history={history}>
<Switch>
<Route path="/link-to" component={LinkToPage} />
<Route path="/link-to" component={LinkToLogsPage} />
{uiCapabilities?.logs?.show && (
<RedirectWithQueryParams from="/" exact={true} to="/stream" />
)}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/routers/metrics_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Route, Router, Switch } from 'react-router-dom';

import { NotFoundPage } from '../pages/404';
import { InfrastructurePage } from '../pages/infrastructure';
import { LinkToPage } from '../pages/link_to';
import { LinkToMetricsPage } from '../pages/link_to';
import { MetricDetail } from '../pages/metrics';
import { RedirectWithQueryParams } from '../utils/redirect_with_query_params';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
Expand All @@ -20,7 +20,7 @@ export const MetricsRouter: AppRouter = ({ history }) => {
return (
<Router history={history}>
<Switch>
<Route path="/link-to" component={LinkToPage} />
<Route path="/link-to" component={LinkToMetricsPage} />
{uiCapabilities?.infrastructure?.show && (
<RedirectWithQueryParams from="/" exact={true} to="/inventory" />
)}
Expand Down

0 comments on commit 1ce87d8

Please sign in to comment.