Skip to content

Commit 334dff3

Browse files
authored
[Uptime] Added date range filter into expanded list query (#52609)
* added filters into expanded list query * update filters * update query * update snap * update tests * update filters * update test * remove side effect * ignore typcehck * update to remove location filter from query * update filter groups * remove code * update test
1 parent 23a0513 commit 334dff3

File tree

22 files changed

+205
-161
lines changed

22 files changed

+205
-161
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
"react-use": "^13.13.0",
241241
"reactcss": "1.2.3",
242242
"redux": "4.0.0",
243-
"redux-actions": "2.2.1",
243+
"redux-actions": "2.6.5",
244244
"redux-thunk": "2.3.0",
245245
"regenerator-runtime": "^0.13.3",
246246
"regression": "2.0.1",
@@ -353,7 +353,7 @@
353353
"@types/react-router-dom": "^5.1.3",
354354
"@types/react-virtualized": "^9.18.7",
355355
"@types/redux": "^3.6.31",
356-
"@types/redux-actions": "^2.2.1",
356+
"@types/redux-actions": "^2.6.1",
357357
"@types/request": "^2.48.2",
358358
"@types/selenium-webdriver": "^4.0.5",
359359
"@types/semver": "^5.5.0",

x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/__tests__/monitor_list_drawer.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { MonitorSummary, Check } from '../../../../../../common/graphql/types';
88
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
99
import React from 'react';
1010
import { MonitorListDrawerComponent } from '../monitor_list_drawer';
11+
import { MonitorDetails } from '../../../../../../common/runtime_types';
1112

1213
describe('MonitorListDrawer component', () => {
1314
let summary: MonitorSummary;
1415
let loadMonitorDetails: any;
15-
let monitorDetails: any;
16+
let monitorDetails: MonitorDetails;
1617

1718
beforeEach(() => {
1819
summary = {

x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/monitor_list_drawer.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import React, { useEffect } from 'react';
88
import { EuiLink, EuiSpacer, EuiFlexGroup, EuiFlexItem, EuiIcon, EuiText } from '@elastic/eui';
9-
import { get } from 'lodash';
109
import styled from 'styled-components';
1110
import { connect } from 'react-redux';
1211
import { MonitorSummary } from '../../../../../common/graphql/types';
@@ -16,6 +15,8 @@ import { MostRecentError } from './most_recent_error';
1615
import { getMonitorDetails } from '../../../../state/selectors';
1716
import { MonitorStatusList } from './monitor_status_list';
1817
import { MonitorDetails } from '../../../../../common/runtime_types';
18+
import { useUrlParams } from '../../../../hooks';
19+
import { MonitorDetailsActionPayload } from '../../../../state/actions/types';
1920
import { MonitorListActionsPopover } from '../monitor_list_actions_popover';
2021

2122
const ContainerDiv = styled.div`
@@ -50,19 +51,20 @@ export function MonitorListDrawerComponent({
5051
monitorDetails,
5152
}: MonitorListDrawerProps) {
5253
const monitorId = summary?.monitor_id;
53-
useEffect(() => {
54-
if (monitorId) {
55-
loadMonitorDetails(monitorId);
56-
}
57-
}, [loadMonitorDetails, monitorId]);
54+
const [getUrlParams] = useUrlParams();
55+
const { dateRangeStart: dateStart, dateRangeEnd: dateEnd } = getUrlParams();
5856

59-
if (!summary || !summary.state.checks) {
60-
return null;
61-
}
57+
useEffect(() => {
58+
loadMonitorDetails({
59+
dateStart,
60+
dateEnd,
61+
monitorId,
62+
});
63+
}, [dateStart, dateEnd, monitorId, loadMonitorDetails]);
6264

63-
const monitorUrl: string | undefined = get(summary.state.url, 'full', undefined);
65+
const monitorUrl = summary?.state?.url?.full || '';
6466

65-
return (
67+
return summary && summary.state.checks ? (
6668
<ContainerDiv>
6769
<EuiFlexGroup>
6870
<EuiFlexItem grow={true}>
@@ -87,15 +89,16 @@ export function MonitorListDrawerComponent({
8789
/>
8890
)}
8991
</ContainerDiv>
90-
);
92+
) : null;
9193
}
9294

9395
const mapStateToProps = (state: AppState, { summary }: any) => ({
9496
monitorDetails: getMonitorDetails(state, summary),
9597
});
9698

9799
const mapDispatchToProps = (dispatch: any) => ({
98-
loadMonitorDetails: (monitorId: string) => dispatch(fetchMonitorDetails(monitorId)),
100+
loadMonitorDetails: (actionPayload: MonitorDetailsActionPayload) =>
101+
dispatch(fetchMonitorDetails(actionPayload)),
99102
});
100103

101104
export const MonitorListDrawer = connect(

x-pack/legacy/plugins/uptime/public/state/actions/monitor.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { MonitorDetailsActionPayload } from './types';
8+
import { MonitorError } from '../../../common/runtime_types';
79
import { MonitorLocations } from '../../../common/runtime_types';
810
import { QueryParams } from './types';
911

@@ -17,12 +19,12 @@ export const FETCH_MONITOR_LOCATIONS_FAIL = 'FETCH_MONITOR_LOCATIONS_FAIL';
1719

1820
export interface MonitorDetailsState {
1921
monitorId: string;
20-
error: Error;
22+
error: MonitorError;
2123
}
2224

2325
interface GetMonitorDetailsAction {
2426
type: typeof FETCH_MONITOR_DETAILS;
25-
payload: string;
27+
payload: MonitorDetailsActionPayload;
2628
}
2729

2830
interface GetMonitorDetailsSuccessAction {
@@ -54,10 +56,10 @@ interface GetMonitorLocationsFailAction {
5456
payload: any;
5557
}
5658

57-
export function fetchMonitorDetails(monitorId: string): GetMonitorDetailsAction {
59+
export function fetchMonitorDetails(payload: MonitorDetailsActionPayload): GetMonitorDetailsAction {
5860
return {
5961
type: FETCH_MONITOR_DETAILS,
60-
payload: monitorId,
62+
payload,
6163
};
6264
}
6365

x-pack/legacy/plugins/uptime/public/state/actions/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ export interface QueryParams {
1010
filters?: string;
1111
statusFilter?: string;
1212
}
13+
14+
export interface MonitorDetailsActionPayload {
15+
monitorId: string;
16+
dateStart: string;
17+
dateEnd: string;
18+
location?: string;
19+
}

x-pack/legacy/plugins/uptime/public/state/actions/ui.ts

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,19 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
7-
export const SET_INTEGRATION_POPOVER_STATE = 'SET_INTEGRATION_POPOVER_STATE';
8-
export const SET_BASE_PATH = 'SET_BASE_PATH';
9-
export const REFRESH_APP = 'REFRESH_APP';
6+
import { createAction } from 'redux-actions';
107

118
export interface PopoverState {
129
id: string;
1310
open: boolean;
1411
}
1512

16-
interface SetBasePathAction {
17-
type: typeof SET_BASE_PATH;
18-
payload: string;
19-
}
20-
21-
interface SetIntegrationPopoverAction {
22-
type: typeof SET_INTEGRATION_POPOVER_STATE;
23-
payload: PopoverState;
24-
}
25-
26-
interface TriggerAppRefreshAction {
27-
type: typeof REFRESH_APP;
28-
payload: number;
29-
}
13+
export type UiPayload = PopoverState & string & number & Map<string, string[]>;
3014

31-
export type UiActionTypes =
32-
| SetIntegrationPopoverAction
33-
| SetBasePathAction
34-
| TriggerAppRefreshAction;
15+
export const setBasePath = createAction<string>('SET BASE PATH');
3516

36-
export function toggleIntegrationsPopover(popoverState: PopoverState): SetIntegrationPopoverAction {
37-
return {
38-
type: SET_INTEGRATION_POPOVER_STATE,
39-
payload: popoverState,
40-
};
41-
}
17+
export const triggerAppRefresh = createAction<number>('REFRESH APP');
4218

43-
export function setBasePath(basePath: string): SetBasePathAction {
44-
return {
45-
type: SET_BASE_PATH,
46-
payload: basePath,
47-
};
48-
}
49-
50-
export function triggerAppRefresh(refreshTime: number): TriggerAppRefreshAction {
51-
return {
52-
type: REFRESH_APP,
53-
payload: refreshTime,
54-
};
55-
}
19+
export const toggleIntegrationsPopover = createAction<PopoverState>(
20+
'TOGGLE INTEGRATION POPOVER STATE'
21+
);

x-pack/legacy/plugins/uptime/public/state/api/monitor.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { ThrowReporter } from 'io-ts/lib/ThrowReporter';
88
import { getApiPath } from '../../lib/helper';
9+
import { BaseParams } from './types';
910
import {
1011
MonitorDetailsType,
1112
MonitorDetails,
@@ -19,12 +20,23 @@ interface ApiRequest {
1920
basePath: string;
2021
}
2122

23+
export type MonitorQueryParams = BaseParams & ApiRequest;
24+
2225
export const fetchMonitorDetails = async ({
2326
monitorId,
2427
basePath,
25-
}: ApiRequest): Promise<MonitorDetails> => {
26-
const url = getApiPath(`/api/uptime/monitor/details?monitorId=${monitorId}`, basePath);
27-
const response = await fetch(url);
28+
dateStart,
29+
dateEnd,
30+
}: MonitorQueryParams): Promise<MonitorDetails> => {
31+
const url = getApiPath(`/api/uptime/monitor/details`, basePath);
32+
const params = {
33+
monitorId,
34+
dateStart,
35+
dateEnd,
36+
};
37+
const urlParams = new URLSearchParams(params).toString();
38+
const response = await fetch(`${url}?${urlParams}`);
39+
2840
if (!response.ok) {
2941
throw new Error(response.statusText);
3042
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export interface BaseParams {
8+
basePath: string;
9+
dateStart: string;
10+
dateEnd: string;
11+
filters?: string;
12+
statusFilter?: string;
13+
location?: string;
14+
}

x-pack/legacy/plugins/uptime/public/state/effects/monitor.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ import {
1616
} from '../actions/monitor';
1717
import { fetchMonitorDetails, fetchMonitorLocations } from '../api';
1818
import { getBasePath } from '../selectors';
19+
import { MonitorDetailsActionPayload } from '../actions/types';
1920

2021
function* monitorDetailsEffect(action: Action<any>) {
21-
const monitorId: string = action.payload;
22+
const { monitorId, dateStart, dateEnd }: MonitorDetailsActionPayload = action.payload;
2223
try {
2324
const basePath = yield select(getBasePath);
24-
const response = yield call(fetchMonitorDetails, { monitorId, basePath });
25+
const response = yield call(fetchMonitorDetails, {
26+
monitorId,
27+
basePath,
28+
dateStart,
29+
dateEnd,
30+
});
2531
yield put({ type: FETCH_MONITOR_DETAILS_SUCCESS, payload: response });
2632
} catch (error) {
2733
yield put({ type: FETCH_MONITOR_DETAILS_FAIL, payload: error.message });

x-pack/legacy/plugins/uptime/public/state/reducers/__tests__/__snapshots__/ui.test.ts.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)