Skip to content

Commit

Permalink
[Security Solution][Endpoint] Update endpoint middleware to load data…
Browse files Browse the repository at this point in the history
… correctly (elastic#108551)

* update endpoint middleware to load data correctly

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

* await results

fixes elastic/issues/108497

* review comments

* Add a test to cover this case

fixes elastic/issues/108497

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
ashokaditya and kibanamachine committed Aug 16, 2021
1 parent e737f79 commit 25dce13
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,34 +105,35 @@ 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 (
action.type === 'userChangedUrl' &&
hasSelectedEndpoint(getState()) === true &&
getIsOnEndpointDetailsActivityLog(getState())
) {
endpointDetailsActivityLogChangedMiddleware({ store, coreStart });
await endpointDetailsActivityLogChangedMiddleware({ store, coreStart });
}

// page activity log API
if (
action.type === 'endpointDetailsActivityLogUpdatePaging' &&
hasSelectedEndpoint(getState())
) {
endpointDetailsActivityLogPagingMiddleware({ store, coreStart });
await endpointDetailsActivityLogPagingMiddleware({ store, coreStart });
}

// Isolate Host
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 25dce13

Please sign in to comment.