Skip to content

Commit 4cf69a0

Browse files
committed
Fix explore tables don't display data when a global filter is applied
1 parent 294fe2b commit 4cf69a0

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

  • x-pack/plugins/security_solution/public/common/components/search_bar

x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { set } from '@elastic/safer-lodash-set/fp';
99
import { getOr } from 'lodash/fp';
1010
import React, { memo, useEffect, useCallback, useMemo } from 'react';
11-
import { connect, ConnectedProps } from 'react-redux';
11+
import { connect, ConnectedProps, useDispatch } from 'react-redux';
1212
import { Dispatch } from 'redux';
1313
import { Subscription } from 'rxjs';
1414
import styled from 'styled-components';
@@ -35,10 +35,11 @@ import {
3535
startSelector,
3636
toStrSelector,
3737
} from './selectors';
38-
import { hostsActions } from '../../../hosts/store';
39-
import { networkActions } from '../../../network/store';
4038
import { timelineActions } from '../../../timelines/store/timeline';
4139
import { useKibana } from '../../lib/kibana';
40+
import { usersActions } from '../../../users/store';
41+
import { hostsActions } from '../../../hosts/store';
42+
import { networkActions } from '../../../network/store';
4243

4344
const APP_STATE_STORAGE_KEY = 'securitySolution.searchBar.appState';
4445

@@ -91,16 +92,25 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
9192
},
9293
} = useKibana().services;
9394

95+
const dispatch = useDispatch();
96+
const setTablesActivePageToZero = useCallback(() => {
97+
dispatch(usersActions.setUsersTablesActivePageToZero());
98+
dispatch(hostsActions.setHostTablesActivePageToZero());
99+
dispatch(networkActions.setNetworkTablesActivePageToZero());
100+
}, [dispatch]);
101+
94102
useEffect(() => {
95103
if (fromStr != null && toStr != null) {
96104
timefilter.setTime({ from: fromStr, to: toStr });
97105
} else if (start != null && end != null) {
106+
setTablesActivePageToZero();
107+
98108
timefilter.setTime({
99109
from: new Date(start).toISOString(),
100110
to: new Date(end).toISOString(),
101111
});
102112
}
103-
}, [end, fromStr, start, timefilter, toStr]);
113+
}, [end, fromStr, start, timefilter, toStr, setTablesActivePageToZero]);
104114

105115
const onQuerySubmit = useCallback(
106116
(payload: { dateRange: TimeRange; query?: Query }) => {
@@ -119,6 +129,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
119129
isQuickSelection,
120130
updateTime: false,
121131
filterManager,
132+
setTablesActivePageToZero,
122133
};
123134
let isStateUpdated = false;
124135

@@ -164,6 +175,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
164175
filterQuery,
165176
queries,
166177
updateSearch,
178+
setTablesActivePageToZero,
167179
]
168180
);
169181

@@ -178,12 +190,13 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
178190
isQuickSelection: true,
179191
updateTime: true,
180192
filterManager,
193+
setTablesActivePageToZero,
181194
});
182195
} else {
183196
queries.forEach((q) => q.refetch && (q.refetch as inputsModel.Refetch)());
184197
}
185198
},
186-
[updateSearch, id, filterManager, queries]
199+
[updateSearch, id, filterManager, queries, setTablesActivePageToZero]
187200
);
188201

189202
const onSaved = useCallback(
@@ -209,6 +222,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
209222
isQuickSelection,
210223
updateTime: false,
211224
filterManager,
225+
setTablesActivePageToZero,
212226
};
213227

214228
if (savedQueryUpdated.attributes.timefilter) {
@@ -226,7 +240,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
226240

227241
updateSearch(updateSearchBar);
228242
},
229-
[id, toStr, end, fromStr, start, filterManager, updateSearch]
243+
[id, toStr, end, fromStr, start, filterManager, updateSearch, setTablesActivePageToZero]
230244
);
231245

232246
const onClearSavedQuery = useCallback(() => {
@@ -246,9 +260,20 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
246260
resetSavedQuery: true,
247261
savedQuery: undefined,
248262
filterManager,
263+
setTablesActivePageToZero,
249264
});
250265
}
251-
}, [savedQuery, updateSearch, id, toStr, end, fromStr, start, filterManager]);
266+
}, [
267+
savedQuery,
268+
updateSearch,
269+
id,
270+
toStr,
271+
end,
272+
fromStr,
273+
start,
274+
filterManager,
275+
setTablesActivePageToZero,
276+
]);
252277

253278
const saveAppStateToStorage = useCallback(
254279
(filters: Filter[]) => storage.set(APP_STATE_STORAGE_KEY, filters),
@@ -273,6 +298,8 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
273298
id,
274299
filters: filterManager.getFilters(),
275300
});
301+
302+
setTablesActivePageToZero();
276303
}
277304
},
278305
})
@@ -369,6 +396,7 @@ interface UpdateReduxSearchBar extends OnTimeChangeProps {
369396
resetSavedQuery?: boolean;
370397
timelineId?: string;
371398
updateTime: boolean;
399+
setTablesActivePageToZero: () => void;
372400
}
373401

374402
export const dispatchUpdateSearch =
@@ -385,6 +413,7 @@ export const dispatchUpdateSearch =
385413
timelineId,
386414
filterManager,
387415
updateTime = false,
416+
setTablesActivePageToZero,
388417
}: UpdateReduxSearchBar): void => {
389418
if (updateTime) {
390419
const fromDate = formatDate(start);
@@ -446,8 +475,7 @@ export const dispatchUpdateSearch =
446475
dispatch(inputsActions.setSavedQuery({ id, savedQuery }));
447476
}
448477

449-
dispatch(hostsActions.setHostTablesActivePageToZero());
450-
dispatch(networkActions.setNetworkTablesActivePageToZero());
478+
setTablesActivePageToZero();
451479
};
452480

453481
const mapDispatchToProps = (dispatch: Dispatch) => ({

0 commit comments

Comments
 (0)