Skip to content

Commit

Permalink
[Security Solution][Endpoint] Show "no activity log" callout consiste…
Browse files Browse the repository at this point in the history
…ntly when no data on subsequent fetches (elastic#123039)

fixes elastic/issues/122922

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
ashokaditya and kibanamachine authored Jan 17, 2022
1 parent 75cf64d commit 314ae9a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ export const EndpointActivityLog = memo(
[hasActiveDateRange, isPagingDisabled, activityLogLoading, activityLogSize]
);

const doesNotHaveDataAlsoOnRefetch = useMemo(
() => !activityLastLogData?.data.length && !activityLogData.length,
[activityLastLogData, activityLogData]
);

const showCallout = useMemo(
() => !isPagingDisabled && activityLogLoaded && !activityLogData.length,
[isPagingDisabled, activityLogLoaded, activityLogData]
() =>
(!isPagingDisabled && activityLogLoaded && !activityLogData.length) ||
doesNotHaveDataAlsoOnRefetch,
[isPagingDisabled, activityLogLoaded, activityLogData, doesNotHaveDataAlsoOnRefetch]
);

const loadMoreTrigger = useRef<HTMLInputElement | null>(null);
Expand Down Expand Up @@ -153,7 +160,7 @@ export const EndpointActivityLog = memo(
ref={loadMoreTrigger}
/>
)}
{isPagingDisabled && !activityLogLoading && (
{isPagingDisabled && !activityLogLoading && !showCallout && (
<EuiText color="subdued" textAlign="center">
<p>{i18.ACTIVITY_LOG.LogEntry.endOfLog}</p>
</EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,57 @@ describe('when on the endpoint list page', () => {
expect(activityLogCallout).not.toBeNull();
});

it('should display a callout message if no log data also on refetch', async () => {
const userChangedUrlChecker = middlewareSpy.waitForAction('userChangedUrl');
reactTestingLibrary.act(() => {
history.push(
getEndpointDetailsPath({
page_index: '0',
page_size: '10',
name: 'endpointActivityLog',
selected_endpoint: '1',
})
);
});
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', {
page: 1,
pageSize: 50,
startDate: 'now-1d',
endDate: 'now',
data: [],
});
});

const activityLogCallout = await renderResult.findByTestId('activityLogNoDataCallout');
expect(activityLogCallout).not.toBeNull();

// click refresh button
const refreshLogButton = await renderResult.findByTestId('superDatePickerApplyTimeButton');
userEvent.click(refreshLogButton);

await middlewareSpy.waitForAction('endpointDetailsActivityLogChanged');
reactTestingLibrary.act(() => {
dispatchEndpointDetailsActivityLogChanged('success', {
page: 1,
pageSize: 50,
startDate: 'now-1d',
endDate: 'now',
data: [],
});
});

const activityLogNoDataCallout = await renderResult.findByTestId(
'activityLogNoDataCallout'
);
expect(activityLogNoDataCallout).not.toBeNull();
});

it('should not display scroll trigger when showing callout message', async () => {
const userChangedUrlChecker = middlewareSpy.waitForAction('userChangedUrl');
reactTestingLibrary.act(() => {
Expand Down

0 comments on commit 314ae9a

Please sign in to comment.