-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TIP] Investigate in timeline (#140496)
* [TIP] Investigate in timeline - 2 InvestigateInTimeline components (one for Button display the other for ButtonIcon) and 1 useInvestigateInTimeline hook - add new investigate in timeline hook in Security Solution plugin and pass via context to TI plugin - replace UrlOriginal by UrlFull in the threat.indicator.name mapping - bump kbn-optimizer limit for threatIntelligence - add EuiTooltip for all EuiButtonIcon - add missing translations - replace css with EuiFlexGroup where possible
- Loading branch information
1 parent
6add682
commit 3099159
Showing
44 changed files
with
1,330 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/security_solution/public/threat_intelligence/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const ACTION_INVESTIGATE_IN_TIMELINE = i18n.translate( | ||
'xpack.securitySolution.threatIntelligence.investigateInTimelineTitle', | ||
{ | ||
defaultMessage: 'Investigate in timeline', | ||
} | ||
); |
130 changes: 130 additions & 0 deletions
130
x-pack/plugins/security_solution/public/threat_intelligence/use_investigate_in_timeline.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useCallback, useMemo } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { timelineDefaults } from '../timelines/store/timeline/defaults'; | ||
import { APP_UI_ID } from '../../common/constants'; | ||
import type { DataProvider } from '../../common/types'; | ||
import { TimelineId, TimelineType } from '../../common/types'; | ||
import { useDeepEqualSelector } from '../common/hooks/use_selector'; | ||
import { useKibana } from '../common/lib/kibana'; | ||
import { useStartTransaction } from '../common/lib/apm/use_start_transaction'; | ||
import { timelineActions, timelineSelectors } from '../timelines/store/timeline'; | ||
import { useCreateTimeline } from '../timelines/components/timeline/properties/use_create_timeline'; | ||
import type { CreateTimelineProps } from '../detections/components/alerts_table/types'; | ||
import { dispatchUpdateTimeline } from '../timelines/components/open_timeline/helpers'; | ||
|
||
interface UseInvestigateInTimelineActionProps { | ||
/** | ||
* Created when the user clicks on the Investigate in Timeline button. | ||
* DataProvider contain the field(s) and value(s) displayed in the timeline. | ||
*/ | ||
dataProviders: DataProvider[]; | ||
/** | ||
* Start date used in the createTimeline method. | ||
*/ | ||
from: string; | ||
/** | ||
* End date used in the createTimeline method. | ||
*/ | ||
to: string; | ||
} | ||
|
||
/** | ||
* Hook passed down to the Threat Intelligence plugin, via context. | ||
* This code is closely duplicated from here: https://github.com/elastic/kibana/blob/main/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_investigate_in_timeline.tsx, | ||
* the main changes being: | ||
* - no exceptions are handled at the moment | ||
* - we use dataProviders, from and to directly instead of consuming ecsData | ||
*/ | ||
export const useInvestigateInTimeline = ({ | ||
dataProviders, | ||
from, | ||
to, | ||
}: UseInvestigateInTimelineActionProps) => { | ||
const { | ||
data: { query }, | ||
} = useKibana().services; | ||
const dispatch = useDispatch(); | ||
const { startTransaction } = useStartTransaction(); | ||
|
||
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] | ||
); | ||
|
||
const clearActiveTimeline = useCreateTimeline({ | ||
timelineId: TimelineId.active, | ||
timelineType: TimelineType.default, | ||
}); | ||
|
||
const createTimeline = useCallback( | ||
({ from: fromTimeline, timeline, to: toTimeline, ruleNote }: CreateTimelineProps) => { | ||
clearActiveTimeline(); | ||
updateTimelineIsLoading({ id: TimelineId.active, isLoading: false }); | ||
dispatchUpdateTimeline(dispatch)({ | ||
duplicate: true, | ||
from: fromTimeline, | ||
id: TimelineId.active, | ||
notes: [], | ||
timeline: { | ||
...timeline, | ||
filterManager, | ||
indexNames: timeline.indexNames ?? [], | ||
show: true, | ||
}, | ||
to: toTimeline, | ||
ruleNote, | ||
})(); | ||
}, | ||
[dispatch, filterManager, updateTimelineIsLoading, clearActiveTimeline] | ||
); | ||
|
||
const investigateInTimelineClick = useCallback(async () => { | ||
startTransaction({ name: `${APP_UI_ID} threat indicator investigateInTimeline` }); | ||
await createTimeline({ | ||
from, | ||
notes: null, | ||
timeline: { | ||
...timelineDefaults, | ||
dataProviders, | ||
id: TimelineId.active, | ||
indexNames: [], | ||
dateRange: { | ||
start: from, | ||
end: to, | ||
}, | ||
eventType: 'all', | ||
filters: [], | ||
kqlQuery: { | ||
filterQuery: { | ||
kuery: { | ||
kind: 'kuery', | ||
expression: '', | ||
}, | ||
serializedQuery: '', | ||
}, | ||
}, | ||
}, | ||
to, | ||
ruleNote: '', | ||
}); | ||
}, [startTransaction, createTimeline, dataProviders, from, to]); | ||
|
||
return investigateInTimelineClick; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.