Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Timeline uses existing filter manager #111143

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import { useDispatch } from 'react-redux';

import { EuiContextMenuItem } from '@elastic/eui';
Expand All @@ -13,11 +13,12 @@ import { useKibana } from '../../../../common/lib/kibana';
import { TimelineId } from '../../../../../common/types/timeline';
import { Ecs } from '../../../../../common/ecs';
import { TimelineNonEcsData } from '../../../../../common/search_strategy/timeline';
import { timelineActions } from '../../../../timelines/store/timeline';
import { timelineActions, timelineSelectors } from '../../../../timelines/store/timeline';
import { sendAlertToTimelineAction } from '../actions';
import { dispatchUpdateTimeline } from '../../../../timelines/components/open_timeline/helpers';
import { CreateTimelineProps } from '../types';
import { ACTION_INVESTIGATE_IN_TIMELINE } from '../translations';
import { useDeepEqualSelector } from '../../../../common/hooks/use_selector';
import { useFetchEcsAlertsData } from '../../../containers/detection_engine/alerts/use_fetch_ecs_alerts_data';

interface UseInvestigateInTimelineActionProps {
Expand All @@ -34,10 +35,20 @@ export const useInvestigateInTimeline = ({
onInvestigateInTimelineAlertClick,
}: UseInvestigateInTimelineActionProps) => {
const {
data: { search: searchStrategyClient },
data: { search: searchStrategyClient, query },
} = useKibana().services;
const dispatch = useDispatch();

const filterManagerBackup = useMemo(() => query.filterManager, [query.filterManager]);
const getManageTimeline = useMemo(() => timelineSelectors.getManageTimelineById(), []);
const { filterManager: activeFilterManager } = useDeepEqualSelector((state) =>
getManageTimeline(state, TimelineId.active ?? '')
);
const filterManager = useMemo(() => activeFilterManager ?? filterManagerBackup, [
activeFilterManager,
filterManagerBackup,
]);

const updateTimelineIsLoading = useCallback(
(payload) => dispatch(timelineActions.updateIsLoading(payload)),
[dispatch]
Expand All @@ -53,6 +64,7 @@ export const useInvestigateInTimeline = ({
notes: [],
timeline: {
...timeline,
filterManager,
// by setting as an empty array, it will default to all in the reducer because of the event type
indexNames: [],
show: true,
Expand All @@ -61,7 +73,7 @@ export const useInvestigateInTimeline = ({
ruleNote,
})();
},
[dispatch, updateTimelineIsLoading]
[dispatch, filterManager, updateTimelineIsLoading]
);

const showInvestigateInTimelineAction = alertIds != null;
Expand Down