Skip to content

Commit

Permalink
Improve security alerts t-grid loading and empty state (#108527)
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Aug 16, 2021
1 parent cb40692 commit c2d5d1b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 40 deletions.
107 changes: 68 additions & 39 deletions x-pack/plugins/timelines/public/components/t_grid/integrated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
import type { AlertConsumers as AlertConsumersTyped } from '@kbn/rule-data-utils';
// @ts-expect-error
import { AlertConsumers as AlertConsumersNonTyped } from '@kbn/rule-data-utils/target_node/alerts_as_data_rbac';
import { EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui';
import { EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem, EuiPanel, EuiProgress } from '@elastic/eui';
import { isEmpty } from 'lodash/fp';
import React, { useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import { useDispatch } from 'react-redux';

import { FormattedMessage } from '@kbn/i18n/react';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { Direction, EntityType } from '../../../../common/search_strategy';
import type { DocValueFields } from '../../../../common/search_strategy';
import type { CoreStart } from '../../../../../../../src/core/public';
import type { BrowserFields } from '../../../../common/search_strategy/index_fields';
import { TGridCellAction, TimelineId, TimelineTabs } from '../../../../common/types/timeline';

import type {
CellValueElementProps,
ColumnHeaderOptions,
Expand Down Expand Up @@ -66,6 +68,7 @@ const TitleText = styled.span`
const StyledEuiPanel = styled(EuiPanel)<{ $isFullScreen: boolean }>`
display: flex;
flex-direction: column;
position: relative;
${({ $isFullScreen }) =>
$isFullScreen &&
Expand Down Expand Up @@ -310,6 +313,8 @@ const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({
return (
<InspectButtonContainer>
<StyledEuiPanel data-test-subj="events-viewer-panel" $isFullScreen={globalFullScreen}>
{loading && <EuiProgress size="xs" position="absolute" color="accent" />}

{canQueryTimeline ? (
<>
<HeaderSection
Expand All @@ -335,44 +340,68 @@ const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({

<FullWidthFlexGroup $visible={!graphEventId} gutterSize="none">
<ScrollableFlexItem grow={1}>
<StatefulBody
activePage={pageInfo.activePage}
browserFields={browserFields}
filterQuery={filterQuery}
data={nonDeletedEvents}
defaultCellActions={defaultCellActions}
id={id}
isEventViewer={true}
loadPage={loadPage}
onRuleChange={onRuleChange}
renderCellValue={renderCellValue}
rowRenderers={rowRenderers}
tabType={TimelineTabs.query}
totalPages={calculateTotalPages({
itemsCount: totalCountMinusDeleted,
itemsPerPage,
})}
totalItems={totalCountMinusDeleted}
unit={unit}
filterStatus={filterStatus}
leadingControlColumns={leadingControlColumns}
trailingControlColumns={trailingControlColumns}
refetch={refetch}
indexNames={indexNames}
/>
<Footer
activePage={pageInfo.activePage}
data-test-subj="events-viewer-footer"
height={footerHeight}
id={id}
isLive={isLive}
isLoading={loading}
itemsCount={nonDeletedEvents.length}
itemsPerPage={itemsPerPage}
itemsPerPageOptions={itemsPerPageOptions}
onChangePage={loadPage}
totalCount={totalCountMinusDeleted}
/>
{nonDeletedEvents.length === 0 && loading === false ? (
<EuiEmptyPrompt
title={
<h2>
<FormattedMessage
id="xpack.timelines.tGrid.noResultsMatchSearchCriteriaTitle"
defaultMessage="No results match your search criteria"
/>
</h2>
}
titleSize="s"
body={
<p>
<FormattedMessage
id="xpack.timelines.tGrid.noResultsMatchSearchCriteriaDescription"
defaultMessage="Try searching over a longer period of time or modifying your search."
/>
</p>
}
/>
) : (
<>
<StatefulBody
activePage={pageInfo.activePage}
browserFields={browserFields}
filterQuery={filterQuery}
data={nonDeletedEvents}
defaultCellActions={defaultCellActions}
id={id}
isEventViewer={true}
loadPage={loadPage}
onRuleChange={onRuleChange}
renderCellValue={renderCellValue}
rowRenderers={rowRenderers}
tabType={TimelineTabs.query}
totalPages={calculateTotalPages({
itemsCount: totalCountMinusDeleted,
itemsPerPage,
})}
totalItems={totalCountMinusDeleted}
unit={unit}
filterStatus={filterStatus}
leadingControlColumns={leadingControlColumns}
trailingControlColumns={trailingControlColumns}
refetch={refetch}
indexNames={indexNames}
/>
<Footer
activePage={pageInfo.activePage}
data-test-subj="events-viewer-footer"
height={footerHeight}
id={id}
isLive={isLive}
isLoading={loading}
itemsCount={nonDeletedEvents.length}
itemsPerPage={itemsPerPage}
itemsPerPageOptions={itemsPerPageOptions}
onChangePage={loadPage}
totalCount={totalCountMinusDeleted}
/>
</>
)}
</ScrollableFlexItem>
</FullWidthFlexGroup>
</EventsContainerLoading>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/timelines/public/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export const useTimelineEvents = ({
.subscribe({
next: (response) => {
if (isCompleteResponse(response)) {
setLoading(false);
setTimelineResponse((prevResponse) => {
const newTimelineResponse = {
...prevResponse,
Expand All @@ -225,6 +224,8 @@ export const useTimelineEvents = ({
setUpdated(newTimelineResponse.updatedAt);
return newTimelineResponse;
});
setLoading(false);

searchSubscription$.current.unsubscribe();
} else if (isErrorResponse(response)) {
setLoading(false);
Expand Down

0 comments on commit c2d5d1b

Please sign in to comment.