[Security Solution][Endpoint] Update endpoint middleware to load data correctly (#108551)

* update endpoint middleware to load data correctly

fixes kibana/issues/108497
modifies changes done in elastic/kibana/pull/107632
and elastic/kibana/pull/108330

* await results

fixes elastic/kibana/issues/108497

* review comments

* Add a test to cover this case

fixes elastic/kibana/issues/108497

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Ashokaditya 2021-08-16 14:08:23 +02:00 committed by GitHub
parent fe0322ac1f
commit a5e97fc21e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 12 deletions

View file

@ -105,18 +105,19 @@ export const endpointMiddlewareFactory: ImmutableMiddlewareFactory<EndpointState
if (
(action.type === 'userChangedUrl' || action.type === 'appRequestedEndpointList') &&
isOnEndpointPage(getState()) &&
hasSelectedEndpoint(getState()) !== true
!hasSelectedEndpoint(getState())
) {
endpointDetailsListMiddleware({ coreStart, store, fetchIndexPatterns });
await endpointDetailsListMiddleware({ coreStart, store, fetchIndexPatterns });
}
// Endpoint Details
if (action.type === 'userChangedUrl' && hasSelectedEndpoint(getState()) === true) {
endpointDetailsMiddleware({ store, coreStart });
if (action.type === 'userChangedUrl' && hasSelectedEndpoint(getState())) {
const { selected_endpoint: selectedEndpoint } = uiQueryParams(getState());
await endpointDetailsMiddleware({ store, coreStart, selectedEndpoint });
}
if (action.type === 'endpointDetailsLoad') {
loadEndpointDetails({ store, coreStart, selectedEndpoint: action.payload.endpointId });
await loadEndpointDetails({ store, coreStart, selectedEndpoint: action.payload.endpointId });
}
if (
@ -124,7 +125,7 @@ export const endpointMiddlewareFactory: ImmutableMiddlewareFactory<EndpointState
hasSelectedEndpoint(getState()) === true &&
getIsOnEndpointDetailsActivityLog(getState())
) {
endpointDetailsActivityLogChangedMiddleware({ store, coreStart });
await endpointDetailsActivityLogChangedMiddleware({ store, coreStart });
}
// page activity log API
@ -132,7 +133,7 @@ export const endpointMiddlewareFactory: ImmutableMiddlewareFactory<EndpointState
action.type === 'endpointDetailsActivityLogUpdatePaging' &&
hasSelectedEndpoint(getState())
) {
endpointDetailsActivityLogPagingMiddleware({ store, coreStart });
await endpointDetailsActivityLogPagingMiddleware({ store, coreStart });
}
// Isolate Host
@ -665,11 +666,13 @@ async function loadEndpointDetails({
}
async function endpointDetailsMiddleware({
store,
coreStart,
selectedEndpoint,
store,
}: {
store: ImmutableMiddlewareAPI<EndpointState, AppAction>;
coreStart: CoreStart;
selectedEndpoint?: string;
store: ImmutableMiddlewareAPI<EndpointState, AppAction>;
}) {
const { getState, dispatch } = store;
dispatch({
@ -703,11 +706,12 @@ async function endpointDetailsMiddleware({
type: 'serverCancelledEndpointListLoading',
});
}
const { selected_endpoint: selectedEndpoint } = uiQueryParams(getState());
if (selectedEndpoint !== undefined) {
loadEndpointDetails({ store, coreStart, selectedEndpoint });
if (typeof selectedEndpoint === 'undefined') {
return;
}
await loadEndpointDetails({ store, coreStart, selectedEndpoint });
}
async function endpointDetailsActivityLogChangedMiddleware({
store,
coreStart,

View file

@ -876,6 +876,25 @@ describe('when on the endpoint list page', () => {
expect(emptyState).toBe(null);
expect(dateRangePicker).not.toBe(null);
});
it('should display activity log when tab is loaded using the URL', async () => {
const userChangedUrlChecker = middlewareSpy.waitForAction('userChangedUrl');
reactTestingLibrary.act(() => {
history.push(
`${MANAGEMENT_PATH}/endpoints?page_index=0&page_size=10&selected_endpoint=1&show=activity_log`
);
});
const changedUrlAction = await userChangedUrlChecker;
expect(changedUrlAction.payload.search).toEqual(
'?page_index=0&page_size=10&selected_endpoint=1&show=activity_log'
);
await middlewareSpy.waitForAction('endpointDetailsActivityLogChanged');
reactTestingLibrary.act(() => {
dispatchEndpointDetailsActivityLogChanged('success', getMockData());
});
const logEntries = await renderResult.queryAllByTestId('timelineEntry');
expect(logEntries.length).toEqual(2);
});
});
describe('when showing host Policy Response panel', () => {