[Logs / Metrics UI] [NP followup] Cleanup link-to routes (#61162)

* Split link-to into Metrics and Logs routers

* Fix logs stream link-to

* Import fix

* Update snapshots

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Zacqary Adam Xeper 2020-03-25 15:56:35 -05:00 committed by GitHub
parent a16968dd3a
commit d50fe0c985
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 19 deletions

View file

@ -144,5 +144,7 @@ export const replaceLogPositionInQueryString = (time: number) =>
time,
tiebreaker: 0,
},
end: new Date(time + ONE_HOUR).toISOString(),
start: new Date(time - ONE_HOUR).toISOString(),
streamLive: false,
});

View file

@ -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';

View file

@ -0,0 +1,34 @@
/*
* 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?`} component={RedirectToLogs} />
<Redirect to="/" />
</Switch>
);
};

View file

@ -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';
@ -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}
@ -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>
);
};

View file

@ -19,7 +19,7 @@ describe('RedirectToLogs component', () => {
expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'',kind:kuery)"
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'',kind:kuery)"
/>
`);
});
@ -33,7 +33,7 @@ describe('RedirectToLogs component', () => {
expect(component).toMatchInlineSnapshot(`
<Redirect
to="/stream?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
to="/stream?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'FILTER_FIELD:FILTER_VALUE',kind:kuery)"
/>
`);
});

View file

@ -73,7 +73,7 @@ describe('RedirectToNodeLogs component', () => {
expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'HOST_FIELD:%20HOST_NAME',kind:kuery)"
to="/?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'HOST_FIELD:%20HOST_NAME',kind:kuery)"
/>
`);
});
@ -89,7 +89,7 @@ describe('RedirectToNodeLogs component', () => {
expect(component).toMatchInlineSnapshot(`
<Redirect
to="/?logPosition=(position:(tiebreaker:0,time:1550671089404),streamLive:!f)&sourceId=default&logFilter=(expression:'(HOST_FIELD:%20HOST_NAME)%20and%20(FILTER_FIELD:FILTER_VALUE)',kind:kuery)"
to="/?logPosition=(end:'2019-02-20T14:58:09.404Z',position:(tiebreaker:0,time:1550671089404),start:'2019-02-20T12:58:09.404Z',streamLive:!f)&sourceId=default&logFilter=(expression:'(HOST_FIELD:%20HOST_NAME)%20and%20(FILTER_FIELD:FILTER_VALUE)',kind:kuery)"
/>
`);
});

View file

@ -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';
@ -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" />
)}

View file

@ -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';
@ -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" />
)}

View file

@ -25,7 +25,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
it('redirects to the logs app and parses URL search params correctly', async () => {
const location = {
hash: '',
pathname: '/link-to/logs',
pathname: '/link-to',
search: `time=${timestamp}&filter=trace.id:${traceId}`,
state: undefined,
};