[Security Solution][Analyzer] Fix graph overlay persist despite filter group changes (#144291)

* [Security Solution][Resolver] bug fix - added filter status check to disable graph overlay

* update reference to existing status type
This commit is contained in:
christineweng 2022-11-07 14:57:00 -06:00 committed by GitHub
parent 0ed00652d7
commit 494aa9cc8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View file

@ -12,7 +12,7 @@ import type { IEsSearchResponse } from '@kbn/data-plugin/common';
import type { Ecs } from '../../../../ecs';
import type { CursorType, Inspect, Maybe, PaginationInputPaginated } from '../../../common';
import type { TimelineRequestOptionsPaginated } from '../..';
import type { AlertStatus } from '../../../../types/timeline';
export interface TimelineEdges {
node: TimelineItem;
cursor: CursorType;
@ -45,4 +45,5 @@ export interface TimelineEventsAllRequestOptions extends TimelineRequestOptionsP
fields: string[] | Array<{ field: string; include_unmapped: boolean }>;
language: 'eql' | 'kuery' | 'lucene';
runtimeMappings: MappingRuntimeFields;
filterStatus?: AlertStatus;
}

View file

@ -263,6 +263,7 @@ const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({
skip: !canQueryTimeline,
sort: sortField,
startDate: start,
filterStatus,
});
useEffect(() => {

View file

@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { AlertConsumers } from '@kbn/rule-data-utils';
import deepEqual from 'fast-deep-equal';
import { isEmpty, isString, noop } from 'lodash/fp';
@ -13,10 +12,15 @@ import { useDispatch } from 'react-redux';
import { Subscription } from 'rxjs';
import { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { isCompleteResponse, isErrorResponse } from '@kbn/data-plugin/common';
import { clearEventsLoading, clearEventsDeleted, setTableUpdatedAt } from '../store/t_grid/actions';
import {
clearEventsLoading,
clearEventsDeleted,
setTableUpdatedAt,
updateGraphEventId,
} from '../store/t_grid/actions';
import {
Direction,
TimelineFactoryQueryTypes,
@ -34,7 +38,7 @@ import type {
TimelineRequestSortField,
} from '../../common/search_strategy';
import type { ESQuery } from '../../common/typed_json';
import type { KueryFilterQueryKind } from '../../common/types/timeline';
import type { KueryFilterQueryKind, AlertStatus } from '../../common/types/timeline';
import { useAppToasts } from '../hooks/use_app_toasts';
import { TableId } from '../store/t_grid/types';
import * as i18n from './translations';
@ -82,6 +86,7 @@ export interface UseTimelineEventsProps {
sort?: TimelineRequestSortField[];
startDate: string;
timerangeKind?: 'absolute' | 'relative';
filterStatus?: AlertStatus;
}
const createFilter = (filterQuery: ESQuery | string | undefined) =>
@ -154,6 +159,7 @@ export const useTimelineEvents = ({
skip = false,
timerangeKind,
data,
filterStatus,
}: UseTimelineEventsProps): [boolean, TimelineArgs] => {
const dispatch = useDispatch();
const { startTracking } = useApmTracking(id);
@ -165,6 +171,7 @@ export const useTimelineEvents = ({
const [timelineRequest, setTimelineRequest] = useState<TimelineRequest<typeof language> | null>(
null
);
const [prevFilterStatus, setFilterStatus] = useState(filterStatus);
const prevTimelineRequest = useRef<TimelineRequest<typeof language> | null>(null);
const clearSignalsState = useCallback(() => {
@ -259,6 +266,10 @@ export const useTimelineEvents = ({
setUpdated(newTimelineResponse.updatedAt);
return newTimelineResponse;
});
if (prevFilterStatus !== request.filterStatus) {
dispatch(updateGraphEventId({ id, graphEventId: '' }));
}
setFilterStatus(request.filterStatus);
setLoading(false);
searchSubscription$.current.unsubscribe();
@ -284,7 +295,18 @@ export const useTimelineEvents = ({
asyncSearch();
refetch.current = asyncSearch;
},
[skip, data, entityType, dataViewId, setUpdated, addWarning, startTracking]
[
skip,
data,
entityType,
dataViewId,
setUpdated,
addWarning,
startTracking,
dispatch,
id,
prevFilterStatus,
]
);
useEffect(() => {
@ -300,6 +322,7 @@ export const useTimelineEvents = ({
sort: prevRequest?.sort ?? initSortDefault,
timerange: prevRequest?.timerange ?? {},
runtimeMappings: prevRequest?.runtimeMappings ?? {},
filterStatus: prevRequest?.filterStatus,
};
const currentSearchParameters = {
@ -339,6 +362,7 @@ export const useTimelineEvents = ({
from: startDate,
to: endDate,
},
filterStatus,
};
if (activePage !== newActivePage) {
@ -364,6 +388,7 @@ export const useTimelineEvents = ({
sort,
fields,
runtimeMappings,
filterStatus,
]);
useEffect(() => {