From 1ce87d80e5bc979a1e3d61e0217c4a5687dc72bb Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Tue, 24 Mar 2020 15:10:10 -0500 Subject: [PATCH 1/4] Split link-to into Metrics and Logs routers --- .../infra/public/pages/link_to/index.ts | 3 +- .../public/pages/link_to/link_to_logs.tsx | 35 +++++++++++++++++++ .../{link_to.tsx => link_to_metrics.tsx} | 11 ++---- .../public/pages/link_to/redirect_to_logs.tsx | 2 +- .../infra/public/routers/logs_router.tsx | 4 +-- .../infra/public/routers/metrics_router.tsx | 4 +-- 6 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx rename x-pack/plugins/infra/public/pages/link_to/{link_to.tsx => link_to_metrics.tsx} (68%) diff --git a/x-pack/plugins/infra/public/pages/link_to/index.ts b/x-pack/plugins/infra/public/pages/link_to/index.ts index 4c8051f8da73e..27e2d483f8fa9 100644 --- a/x-pack/plugins/infra/public/pages/link_to/index.ts +++ b/x-pack/plugins/infra/public/pages/link_to/index.ts @@ -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'; diff --git a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx new file mode 100644 index 0000000000000..aa28e52a31548 --- /dev/null +++ b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx @@ -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 = props => { + return ( + + + + + + + ); +}; diff --git a/x-pack/plugins/infra/public/pages/link_to/link_to.tsx b/x-pack/plugins/infra/public/pages/link_to/link_to_metrics.tsx similarity index 68% rename from x-pack/plugins/infra/public/pages/link_to/link_to.tsx rename to x-pack/plugins/infra/public/pages/link_to/link_to_metrics.tsx index ce62a0a3f4e33..3eb4a9f26fe2e 100644 --- a/x-pack/plugins/infra/public/pages/link_to/link_to.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/link_to_metrics.tsx @@ -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 = props => { +export const LinkToMetricsPage: React.FC = props => { return ( - = props => { path={`${props.match.url}/host-detail-via-ip/:hostIp`} component={RedirectToHostDetailViaIP} /> - - + ); }; diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx index cc4b6967d34fb..712c5e6ced742 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx @@ -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'; diff --git a/x-pack/plugins/infra/public/routers/logs_router.tsx b/x-pack/plugins/infra/public/routers/logs_router.tsx index 6700ed1fc8479..8258f087b5872 100644 --- a/x-pack/plugins/infra/public/routers/logs_router.tsx +++ b/x-pack/plugins/infra/public/routers/logs_router.tsx @@ -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 ( - + {uiCapabilities?.logs?.show && ( )} diff --git a/x-pack/plugins/infra/public/routers/metrics_router.tsx b/x-pack/plugins/infra/public/routers/metrics_router.tsx index 7c2ebed8463f1..7cb9de65e7291 100644 --- a/x-pack/plugins/infra/public/routers/metrics_router.tsx +++ b/x-pack/plugins/infra/public/routers/metrics_router.tsx @@ -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 ( - + {uiCapabilities?.infrastructure?.show && ( )} From 2613bdd75b7846fe4a3da81f749e25e5596f5c19 Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Tue, 24 Mar 2020 15:33:22 -0500 Subject: [PATCH 2/4] Fix logs stream link-to --- .../logs/log_position/with_log_position_url_state.tsx | 2 ++ x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx | 3 +-- x-pack/test/functional/apps/infra/link_to.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/infra/public/containers/logs/log_position/with_log_position_url_state.tsx b/x-pack/plugins/infra/public/containers/logs/log_position/with_log_position_url_state.tsx index 0d3586f9376f3..ddd5b471a02c6 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_position/with_log_position_url_state.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_position/with_log_position_url_state.tsx @@ -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, }); diff --git a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx index aa28e52a31548..04d5c454a92cc 100644 --- a/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/link_to_logs.tsx @@ -27,8 +27,7 @@ export const LinkToLogsPage: React.FC = props => { path={`${props.match.url}/:sourceId?/:nodeType(${ITEM_TYPES})-logs/:nodeId`} component={RedirectToNodeLogs} /> - - + ); diff --git a/x-pack/test/functional/apps/infra/link_to.ts b/x-pack/test/functional/apps/infra/link_to.ts index 7e79f42ac94cb..a287d53d5df0b 100644 --- a/x-pack/test/functional/apps/infra/link_to.ts +++ b/x-pack/test/functional/apps/infra/link_to.ts @@ -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, }; From 0d8ae36796930f420d58d6513d61d26f76bfb09b Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Tue, 24 Mar 2020 16:12:57 -0500 Subject: [PATCH 3/4] Import fix --- x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx index 712c5e6ced742..cc4b6967d34fb 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import compose from 'lodash/fp/compose'; +import { compose } from 'lodash'; import React from 'react'; import { match as RouteMatch, Redirect, RouteComponentProps } from 'react-router-dom'; From 45ce14d6e2f6bf56080f446fd2680552cba49a6b Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Wed, 25 Mar 2020 10:55:58 -0500 Subject: [PATCH 4/4] Update snapshots --- .../infra/public/pages/link_to/redirect_to_logs.test.tsx | 4 ++-- .../infra/public/pages/link_to/redirect_to_node_logs.test.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.test.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.test.tsx index b4ed43f84e27f..0556955e47f66 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.test.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_logs.test.tsx @@ -19,7 +19,7 @@ describe('RedirectToLogs component', () => { expect(component).toMatchInlineSnapshot(` `); }); @@ -33,7 +33,7 @@ describe('RedirectToLogs component', () => { expect(component).toMatchInlineSnapshot(` `); }); diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.test.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.test.tsx index 519ee64060932..1394fc48107ef 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.test.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.test.tsx @@ -73,7 +73,7 @@ describe('RedirectToNodeLogs component', () => { expect(component).toMatchInlineSnapshot(` `); }); @@ -89,7 +89,7 @@ describe('RedirectToNodeLogs component', () => { expect(component).toMatchInlineSnapshot(` `); });