Skip to content

Commit cacbb28

Browse files
committed
update query
1 parent af42270 commit cacbb28

File tree

16 files changed

+137
-114
lines changed

16 files changed

+137
-114
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
"react-use": "^13.10.2",
236236
"reactcss": "1.2.3",
237237
"redux": "4.0.0",
238-
"redux-actions": "2.2.1",
238+
"redux-actions": "2.6.5",
239239
"redux-thunk": "2.3.0",
240240
"regenerator-runtime": "^0.13.3",
241241
"regression": "2.0.1",
@@ -347,7 +347,7 @@
347347
"@types/react-router-dom": "^4.3.1",
348348
"@types/react-virtualized": "^9.18.7",
349349
"@types/redux": "^3.6.31",
350-
"@types/redux-actions": "^2.2.1",
350+
"@types/redux-actions": "^2.6.1",
351351
"@types/request": "^2.48.2",
352352
"@types/selenium-webdriver": "^4.0.3",
353353
"@types/semver": "^5.5.0",

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface FilterBarQueryResult {
2121
interface FilterBarDropdownsProps {
2222
currentFilter: string;
2323
onFilterUpdate: (kuery: string) => void;
24+
setFilters: Function;
2425
}
2526

2627
type Props = UptimeGraphQLQueryProps<FilterBarQueryResult> & FilterBarDropdownsProps;
@@ -30,6 +31,7 @@ export const FilterGroupComponent = ({
3031
currentFilter,
3132
data,
3233
onFilterUpdate,
34+
setFilters,
3335
}: Props) => {
3436
const locations = get<string[]>(data, 'filterBar.locations', []);
3537
const ports = get<string[]>(data, 'filterBar.ports', []);
@@ -61,10 +63,13 @@ export const FilterGroupComponent = ({
6163
// store the new set of filters
6264
const persistedFilters = Array.from(updatedFilterMap);
6365
onFilterUpdate(persistedFilters.length === 0 ? '' : JSON.stringify(persistedFilters));
66+
setFilters(new Map([[fieldName, values]]));
6467
};
6568

6669
const getSelectedItems = (fieldName: string) => filterKueries.get(fieldName) || [];
6770

71+
setFilters(filterKueries);
72+
6873
const filterPopoverProps: FilterPopoverProps[] = [
6974
{
7075
fieldName: 'observer.geo.name',

x-pack/legacy/plugins/uptime/public/components/functional/filter_group/index.ts

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

7-
export { FilterGroup } from './filter_group';
7+
import { connect } from 'react-redux';
8+
import { setFilters } from '../../../state/actions';
9+
import { FilterGroup as FilterGroupComponent } from './filter_group';
10+
11+
const mapDispatchToProps = (dispatch: any) => ({
12+
setFilters: (filters: Map<string, string[]>) => dispatch(setFilters(filters)),
13+
});
14+
15+
export const FilterGroup = connect(null, mapDispatchToProps)(FilterGroupComponent);

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { MonitorSummary } from '../../../../../common/graphql/types';
1313
import { AppState } from '../../../../state';
1414
import { fetchMonitorDetails } from '../../../../state/actions/monitor';
1515
import { MostRecentError } from './most_recent_error';
16-
import { getMonitorDetails } from '../../../../state/selectors';
16+
import { getMonitorDetails, getFilters } from '../../../../state/selectors';
1717
import { MonitorStatusList } from './monitor_status_list';
1818
import { MonitorDetails } from '../../../../../common/runtime_types';
1919
import { useUrlParams } from '../../../../hooks';
@@ -39,6 +39,11 @@ interface MonitorListDrawerProps {
3939
* Redux action to trigger , loading monitor details
4040
*/
4141
loadMonitorDetails: typeof fetchMonitorDetails;
42+
43+
/**
44+
* Filters from filter bar
45+
*/
46+
filters: Map<string, string[]>;
4247
}
4348

4449
/**
@@ -49,20 +54,22 @@ export function MonitorListDrawerComponent({
4954
summary,
5055
loadMonitorDetails,
5156
monitorDetails,
57+
filters,
5258
}: MonitorListDrawerProps) {
5359
if (!summary || !summary.state.checks) {
5460
return null;
5561
}
5662
const { monitor_id: monitorId } = summary;
5763
const [getUrlParams] = useUrlParams();
58-
const { dateRangeStart: dateStart, dateRangeEnd: dateEnd, filters } = getUrlParams();
64+
const { dateRangeStart: dateStart, dateRangeEnd: dateEnd } = getUrlParams();
5965

6066
useEffect(() => {
67+
const location = filters?.get('observer.geo.name') ?? [];
6168
loadMonitorDetails({
6269
dateStart,
6370
dateEnd,
64-
filters,
6571
monitorId,
72+
location: location.join(),
6673
});
6774
}, [dateStart, dateEnd, filters]);
6875

@@ -93,6 +100,7 @@ export function MonitorListDrawerComponent({
93100

94101
const mapStateToProps = (state: AppState, { summary }: any) => ({
95102
monitorDetails: getMonitorDetails(state, summary),
103+
filters: getFilters(state),
96104
});
97105

98106
const mapDispatchToProps = (dispatch: any) => ({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export interface MonitorDetailsActionPayload {
88
monitorId: string;
99
dateStart: string;
1010
dateEnd: string;
11-
filters?: string;
11+
location?: string;
1212
}

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

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,17 @@
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-
}
30-
31-
export type UiActionTypes =
32-
| SetIntegrationPopoverAction
33-
| SetBasePathAction
34-
| TriggerAppRefreshAction;
35-
36-
export function toggleIntegrationsPopover(popoverState: PopoverState): SetIntegrationPopoverAction {
37-
return {
38-
type: SET_INTEGRATION_POPOVER_STATE,
39-
payload: popoverState,
40-
};
41-
}
42-
43-
export function setBasePath(basePath: string): SetBasePathAction {
44-
return {
45-
type: SET_BASE_PATH,
46-
payload: basePath,
47-
};
48-
}
13+
export const setBasePath = createAction<string>('SET BASE PATH');
14+
export const triggerAppRefresh = createAction<number>('REFRESH APP');
4915

50-
export function triggerAppRefresh(refreshTime: number): TriggerAppRefreshAction {
51-
return {
52-
type: REFRESH_APP,
53-
payload: refreshTime,
54-
};
55-
}
16+
export const setFilters = createAction<Map<string, string[]>>('SET FILTERS');
17+
export const toggleIntegrationsPopover = createAction<PopoverState>(
18+
'TOGGLE INTEGRATION POPOVER STATE'
19+
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export const fetchMonitorDetails = async ({
2121
basePath,
2222
dateStart,
2323
dateEnd,
24-
filters,
24+
location,
2525
}: MonitorQueryParams): Promise<MonitorDetails> => {
2626
const url = getApiPath(`/api/uptime/monitor/details`, basePath);
2727
const params = {
2828
monitorId,
2929
dateStart,
3030
dateEnd,
31-
...(filters && { filters }),
31+
...(location && { location }),
3232
};
3333
const urlParams = new URLSearchParams(params).toString();
3434
const response = await fetch(`${url}?${urlParams}`);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export interface BaseParams {
1010
dateEnd: string;
1111
filters?: string;
1212
statusFilter?: string;
13+
location?: string;
1314
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import { getBasePath } from '../selectors';
1616
import { MonitorDetailsActionPayload } from '../actions/types';
1717

1818
function* monitorDetailsEffect(action: Action<any>) {
19-
const { monitorId, dateStart, dateEnd, filters }: MonitorDetailsActionPayload = action.payload;
19+
const { monitorId, dateStart, dateEnd, location }: MonitorDetailsActionPayload = action.payload;
2020
try {
2121
const basePath = yield select(getBasePath);
2222
const response = yield call(fetchMonitorDetails, {
2323
monitorId,
2424
basePath,
2525
dateStart,
2626
dateEnd,
27-
filters,
27+
location,
2828
});
2929
yield put({ type: FETCH_MONITOR_DETAILS_SUCCESS, payload: response });
3030
} catch (error) {

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

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

7+
import { handleActions, Action } from 'redux-actions';
78
import {
8-
UiActionTypes,
99
PopoverState,
10-
SET_INTEGRATION_POPOVER_STATE,
11-
SET_BASE_PATH,
12-
REFRESH_APP,
10+
toggleIntegrationsPopover,
11+
setBasePath,
12+
triggerAppRefresh,
13+
setFilters,
1314
} from '../actions/ui';
1415

1516
export interface UiState {
1617
integrationsPopoverOpen: PopoverState | null;
1718
basePath: string;
1819
lastRefresh: number;
20+
filters: Map<string, string[]>;
1921
}
2022

2123
const initialState: UiState = {
2224
integrationsPopoverOpen: null,
2325
basePath: '',
2426
lastRefresh: Date.now(),
27+
filters: new Map(),
2528
};
2629

27-
export function uiReducer(state = initialState, action: UiActionTypes): UiState {
28-
switch (action.type) {
29-
case REFRESH_APP:
30-
return {
31-
...state,
32-
lastRefresh: action.payload,
33-
};
34-
case SET_INTEGRATION_POPOVER_STATE:
35-
const popoverState = action.payload;
36-
return {
37-
...state,
38-
integrationsPopoverOpen: {
39-
id: popoverState.id,
40-
open: popoverState.open,
41-
},
42-
};
43-
case SET_BASE_PATH:
44-
const basePath = action.payload;
45-
return {
46-
...state,
47-
basePath,
48-
};
49-
default:
50-
return state;
51-
}
52-
}
30+
type UiPayload = PopoverState & string & boolean & number & Map<string, string[]>;
31+
32+
export const uiReducer = handleActions<UiState, UiPayload>(
33+
{
34+
[String(toggleIntegrationsPopover)]: (state, action: Action<PopoverState>) => ({
35+
...state,
36+
integrationsPopoverOpen: action.payload as PopoverState,
37+
}),
38+
39+
[String(setBasePath)]: (state, action: Action<string>) => ({
40+
...state,
41+
basePath: action.payload as string,
42+
}),
43+
44+
[String(triggerAppRefresh)]: (state, action: Action<number>) => ({
45+
...state,
46+
lastRefresh: action.payload as number,
47+
}),
48+
49+
[String(setFilters)]: (state, action: Action<Map<string, string[]>>) => ({
50+
...state,
51+
filters: new Map([...state.filters, ...(action.payload as Map<string, string[]>)]),
52+
}),
53+
},
54+
initialState
55+
);

0 commit comments

Comments
 (0)