Skip to content

Commit

Permalink
[Security Solution][Analyzer] Fix graph overlay persist despite filte…
Browse files Browse the repository at this point in the history
…r group changes (#144291)

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

* update reference to existing status type
  • Loading branch information
christineweng authored Nov 7, 2022
1 parent 0ed0065 commit 494aa9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const TGridIntegratedComponent: React.FC<TGridIntegratedProps> = ({
skip: !canQueryTimeline,
sort: sortField,
startDate: start,
filterStatus,
});

useEffect(() => {
Expand Down
35 changes: 30 additions & 5 deletions x-pack/plugins/timelines/public/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -82,6 +86,7 @@ export interface UseTimelineEventsProps {
sort?: TimelineRequestSortField[];
startDate: string;
timerangeKind?: 'absolute' | 'relative';
filterStatus?: AlertStatus;
}

const createFilter = (filterQuery: ESQuery | string | undefined) =>
Expand Down Expand Up @@ -154,6 +159,7 @@ export const useTimelineEvents = ({
skip = false,
timerangeKind,
data,
filterStatus,
}: UseTimelineEventsProps): [boolean, TimelineArgs] => {
const dispatch = useDispatch();
const { startTracking } = useApmTracking(id);
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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();
Expand All @@ -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(() => {
Expand All @@ -300,6 +322,7 @@ export const useTimelineEvents = ({
sort: prevRequest?.sort ?? initSortDefault,
timerange: prevRequest?.timerange ?? {},
runtimeMappings: prevRequest?.runtimeMappings ?? {},
filterStatus: prevRequest?.filterStatus,
};

const currentSearchParameters = {
Expand Down Expand Up @@ -339,6 +362,7 @@ export const useTimelineEvents = ({
from: startDate,
to: endDate,
},
filterStatus,
};

if (activePage !== newActivePage) {
Expand All @@ -364,6 +388,7 @@ export const useTimelineEvents = ({
sort,
fields,
runtimeMappings,
filterStatus,
]);

useEffect(() => {
Expand Down

0 comments on commit 494aa9c

Please sign in to comment.