Skip to content

Commit eaa37c2

Browse files
committed
[Infra UI] Adding time ranges to detail links
- Adds timeranges to hosts, containers, and pods links - Fixes #24228 - Typos and what not prevented urls from working
1 parent 2b6cd21 commit eaa37c2

File tree

6 files changed

+92
-26
lines changed

6 files changed

+92
-26
lines changed

x-pack/plugins/infra/public/containers/metrics/with_metrics_time.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const WithMetricsTime = asChildFunctionRenderer(withMetricsTime, {
3535
*/
3636

3737
interface MetricTimeUrlState {
38-
timeRange?: ReturnType<typeof metricTimeSelectors.selectRangeTime>;
38+
time?: ReturnType<typeof metricTimeSelectors.selectRangeTime>;
3939
autoReload?: ReturnType<typeof metricTimeSelectors.selectIsAutoReloading>;
4040
}
4141

@@ -47,8 +47,8 @@ export const WithMetricsTimeUrlState = () => (
4747
urlStateKey="metricTime"
4848
mapToUrlState={mapToUrlState}
4949
onChange={newUrlState => {
50-
if (newUrlState && newUrlState.timeRange) {
51-
setRangeTime(newUrlState.timeRange);
50+
if (newUrlState && newUrlState.time) {
51+
setRangeTime(newUrlState.time);
5252
}
5353
if (newUrlState && newUrlState.autoReload) {
5454
startMetricsAutoReload();
@@ -61,8 +61,8 @@ export const WithMetricsTimeUrlState = () => (
6161
}
6262
}}
6363
onInitialize={initialUrlState => {
64-
if (initialUrlState && initialUrlState.timeRange) {
65-
setRangeTime(initialUrlState.timeRange);
64+
if (initialUrlState && initialUrlState.time) {
65+
setRangeTime(initialUrlState.time);
6666
}
6767
if (initialUrlState && initialUrlState.autoReload) {
6868
startMetricsAutoReload();
@@ -85,7 +85,7 @@ const selectTimeUrlState = createSelector(
8585
const mapToUrlState = (value: any): MetricTimeUrlState | undefined =>
8686
value
8787
? {
88-
timeRange: mapToTimeUrlState(value.timeRange),
88+
time: mapToTimeUrlState(value.time),
8989
autoReload: mapToAutoReloadUrlState(value.autoReload),
9090
}
9191
: undefined;

x-pack/plugins/infra/public/containers/waffle/with_waffle_options.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { createSelector } from 'reselect';
1010
import { InfraMetricInput, InfraMetricType, InfraPathType } from '../../../common/graphql/types';
1111
import { InfraNodeType } from '../../../server/lib/adapters/nodes';
1212
import { State, waffleOptionsActions, waffleOptionsSelectors } from '../../store';
13-
import { initialWaffleOptionsState } from '../../store/local/waffle_options/reducer';
1413
import { asChildFunctionRenderer } from '../../utils/typed_react';
1514
import { bindPlainActionCreators } from '../../utils/typed_redux';
1615
import { UrlStateContainer } from '../../utils/url_state';
@@ -19,8 +18,8 @@ const selectOptionsUrlState = createSelector(
1918
waffleOptionsSelectors.selectMetric,
2019
waffleOptionsSelectors.selectGroupBy,
2120
waffleOptionsSelectors.selectNodeType,
22-
(metrics, groupBy, nodeType) => ({
23-
metrics,
21+
(metric, groupBy, nodeType) => ({
22+
metric,
2423
groupBy,
2524
nodeType,
2625
})
@@ -71,10 +70,14 @@ export const WithWaffleOptionsUrlState = () => (
7170
}
7271
}}
7372
onInitialize={initialUrlState => {
74-
if (initialUrlState) {
75-
changeMetric(initialUrlState.metric || initialWaffleOptionsState.metric);
76-
changeGroupBy(initialUrlState.groupBy || initialWaffleOptionsState.groupBy);
77-
changeNodeType(initialUrlState.nodeType || initialWaffleOptionsState.nodeType);
73+
if (initialUrlState && initialUrlState.metric) {
74+
changeMetric(initialUrlState.metric);
75+
}
76+
if (initialUrlState && initialUrlState.groupBy) {
77+
changeGroupBy(initialUrlState.groupBy);
78+
}
79+
if (initialUrlState && initialUrlState.nodeType) {
80+
changeNodeType(initialUrlState.nodeType);
7881
}
7982
}}
8083
/>

x-pack/plugins/infra/public/pages/link_to/query_params.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ export const getTimeFromLocation = (location: Location) => {
1212
const timeParam = getParamFromQueryString(getQueryStringFromLocation(location), 'time');
1313
return timeParam ? parseFloat(timeParam) : NaN;
1414
};
15+
16+
export const getToFromLocation = (location: Location) => {
17+
const timeParam = getParamFromQueryString(getQueryStringFromLocation(location), 'to');
18+
return timeParam ? parseFloat(timeParam) : NaN;
19+
};
20+
21+
export const getFromFromLocation = (location: Location) => {
22+
const timeParam = getParamFromQueryString(getQueryStringFromLocation(location), 'from');
23+
return timeParam ? parseFloat(timeParam) : NaN;
24+
};

x-pack/plugins/infra/public/pages/link_to/redirect_to_container_detail.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@
66

77
import React from 'react';
88
import { Redirect, RouteComponentProps } from 'react-router-dom';
9+
import { getFromFromLocation, getToFromLocation } from './query_params';
910

10-
export const RedirectToContainerDetail = ({ match }: RouteComponentProps<{ name: string }>) => (
11-
<Redirect to={`/metrics/container/${match.params.name}`} />
12-
);
11+
export const RedirectToContainerDetail = ({
12+
match,
13+
location,
14+
}: RouteComponentProps<{ name: string }>) => {
15+
const to = getToFromLocation(location);
16+
const from = getFromFromLocation(location);
17+
const args =
18+
to && from ? `?metricTime=(autoReload:!f,time:(from:${from},interval:>%3D1m,to:${to}))` : '';
19+
return <Redirect to={`/metrics/container/${match.params.name}${args}`} />;
20+
};
1321

14-
export const getContainerDetailUrl = ({ name }: { name: string }) =>
15-
`#/link-to/container-detail/${name}`;
22+
export const getContainerDetailUrl = ({
23+
name,
24+
to,
25+
from,
26+
}: {
27+
name: string;
28+
to?: number;
29+
from?: number;
30+
}) => {
31+
const args = to && from ? `?to=${to}&from=${from}` : '';
32+
return `#/link-to/container-detail/${name}${args}`;
33+
};

x-pack/plugins/infra/public/pages/link_to/redirect_to_host_detail.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,28 @@
66

77
import React from 'react';
88
import { Redirect, RouteComponentProps } from 'react-router-dom';
9+
import { getFromFromLocation, getToFromLocation } from './query_params';
910

10-
export const RedirectToHostDetail = ({ match }: RouteComponentProps<{ name: string }>) => (
11-
<Redirect to={`/metrics/host/${match.params.name}`} />
12-
);
11+
export const RedirectToHostDetail = ({
12+
match,
13+
location,
14+
}: RouteComponentProps<{ name: string }>) => {
15+
const to = getToFromLocation(location);
16+
const from = getFromFromLocation(location);
17+
const args =
18+
to && from ? `?metricTime=(autoReload:!f,time:(from:${from},interval:>%3D1m,to:${to}))` : '';
19+
return <Redirect to={`/metrics/host/${match.params.name}${args}`} />;
20+
};
1321

14-
export const getHostDetailUrl = ({ name }: { name: string }) => `#/link-to/host-detail/${name}`;
22+
export const getHostDetailUrl = ({
23+
name,
24+
to,
25+
from,
26+
}: {
27+
name: string;
28+
to?: number;
29+
from?: number;
30+
}) => {
31+
const args = to && from ? `?to=${to}&from=${from}` : '';
32+
return `#/link-to/host-detail/${name}${args}`;
33+
};

x-pack/plugins/infra/public/pages/link_to/redirect_to_pod_detail.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,25 @@
66

77
import React from 'react';
88
import { Redirect, RouteComponentProps } from 'react-router-dom';
9+
import { getFromFromLocation, getToFromLocation } from './query_params';
910

10-
export const RedirectToPodDetail = ({ match }: RouteComponentProps<{ name: string }>) => (
11-
<Redirect to={`/metrics/pod/${match.params.name}`} />
12-
);
11+
export const RedirectToPodDetail = ({ match, location }: RouteComponentProps<{ name: string }>) => {
12+
const to = getToFromLocation(location);
13+
const from = getFromFromLocation(location);
14+
const args =
15+
to && from ? `?metricTime=(autoReload:!f,time:(from:${from},interval:>%3D1m,to:${to}))` : '';
16+
return <Redirect to={`/metrics/pod/${match.params.name}${args}`} />;
17+
};
1318

14-
export const getPodDetailUrl = ({ name }: { name: string }) => `#/link-to/pod-detail/${name}`;
19+
export const getPodDetailUrl = ({
20+
name,
21+
to,
22+
from,
23+
}: {
24+
name: string;
25+
to?: number;
26+
from?: number;
27+
}) => {
28+
const args = to && from ? `?to=${to}&from=${from}` : '';
29+
return `#/link-to/pod-detail/${name}${args}`;
30+
};

0 commit comments

Comments
 (0)