-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[Osquery] Add to timeline button #128596
[Osquery] Add to timeline button #128596
Changes from 19 commits
9a0ea9f
ef1bcd4
635af17
e483a17
2d4b13b
0b3d977
b06a58f
9b33c21
2bdb838
d7cccf6
2650b51
24649a5
1e86af8
99bdaeb
cb087ec
1a00d81
b77290c
5caef62
afc5980
3c66905
bcf8613
0742331
dbe1048
faaaced
6717b51
7cbda37
81ebe56
8cead6b
ad9c19c
dae6719
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,20 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import React, { useCallback } from 'react'; | ||
import styled from 'styled-components'; | ||
import { EuiFlyout, EuiFlyoutFooter, EuiFlyoutBody, EuiFlyoutHeader } from '@elastic/eui'; | ||
import { | ||
EuiFlyout, | ||
EuiFlyoutFooter, | ||
EuiFlyoutBody, | ||
EuiFlyoutHeader, | ||
EuiButtonEmpty, | ||
} from '@elastic/eui'; | ||
import { useKibana } from '../../../common/lib/kibana'; | ||
import { OsqueryEventDetailsFooter } from './osquery_flyout_footer'; | ||
import { OsqueryEventDetailsHeader } from './osquery_flyout_header'; | ||
import { ACTION_OSQUERY } from './translations'; | ||
import { DataProvider } from '../../../timelines/components/timeline/data_providers/data_provider'; | ||
|
||
const OsqueryActionWrapper = styled.div` | ||
padding: 8px; | ||
|
@@ -22,11 +29,44 @@ export interface OsqueryFlyoutProps { | |
onClose: () => void; | ||
} | ||
|
||
export const OsqueryFlyout: React.FC<OsqueryFlyoutProps> = ({ agentId, onClose }) => { | ||
const TimelineComponent = React.memo((props) => { | ||
return <EuiButtonEmpty {...props} size="xs" />; | ||
}); | ||
TimelineComponent.displayName = 'TimelineComponent'; | ||
|
||
export const OsqueryFlyoutComponent: React.FC<OsqueryFlyoutProps> = ({ agentId, onClose }) => { | ||
const { | ||
services: { osquery }, | ||
services: { osquery, timelines }, | ||
} = useKibana(); | ||
|
||
const { getAddToTimelineButton } = timelines.getHoverActions(); | ||
|
||
const handleAddToTimeline = useCallback( | ||
(payload: { query: [string, string]; isIcon?: true }) => { | ||
const [field, value] = payload.query; | ||
const providerA: DataProvider = { | ||
and: [], | ||
enabled: true, | ||
excluded: false, | ||
id: value, | ||
kqlQuery: '', | ||
name: value, | ||
queryMatch: { | ||
field, | ||
value, | ||
operator: ':', | ||
}, | ||
}; | ||
|
||
return getAddToTimelineButton({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have at least a unit test to check the flyout is rendered correctly according to the props and then check if add to timeline was executed with the right options. |
||
dataProvider: providerA, | ||
field: value, | ||
ownFocus: false, | ||
...(payload.isIcon ? { showTooltip: true } : { Component: TimelineComponent }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this ever called with isIcon false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, never. It's either |
||
}); | ||
}, | ||
[getAddToTimelineButton] | ||
); | ||
// @ts-expect-error | ||
const { OsqueryAction } = osquery; | ||
return ( | ||
|
@@ -45,7 +85,7 @@ export const OsqueryFlyout: React.FC<OsqueryFlyoutProps> = ({ agentId, onClose } | |
</EuiFlyoutHeader> | ||
<EuiFlyoutBody> | ||
<OsqueryActionWrapper data-test-subj="flyout-body-osquery"> | ||
<OsqueryAction agentId={agentId} formType="steps" hideFullscreen={true} /> | ||
<OsqueryAction agentId={agentId} formType="steps" addToTimeline={handleAddToTimeline} /> | ||
</OsqueryActionWrapper> | ||
</EuiFlyoutBody> | ||
<EuiFlyoutFooter> | ||
|
@@ -55,4 +95,4 @@ export const OsqueryFlyout: React.FC<OsqueryFlyoutProps> = ({ agentId, onClose } | |
); | ||
}; | ||
|
||
OsqueryFlyout.displayName = 'OsqueryFlyout'; | ||
export const OsqueryFlyout = React.memo(OsqueryFlyoutComponent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could change this to
const { query: [field, value], isIcon } = payload
so it's more clear that isIcon is used belowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍