-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Endpoint] add resolver middleware #58288
Changes from 10 commits
7a41134
e67ac7a
57133a6
d17e339
2c0df81
8ae65ae
c809dcd
0626d65
d291a46
bcda2d5
a609c11
c6a513e
2600144
24fb4fe
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 |
---|---|---|
|
@@ -9,13 +9,13 @@ import { | |
createSelector, | ||
createStructuredSelector as createStructuredSelectorWithBadType, | ||
} from 'reselect'; | ||
import { Immutable } from '../../../../../common/types'; | ||
import { | ||
AlertListState, | ||
AlertingIndexUIQueryParams, | ||
AlertsAPIQueryParams, | ||
CreateStructuredSelector, | ||
} from '../../types'; | ||
import { Immutable, LegacyEndpointEvent } from '../../../../../common/types'; | ||
|
||
const createStructuredSelector: CreateStructuredSelector = createStructuredSelectorWithBadType; | ||
/** | ||
|
@@ -92,3 +92,24 @@ export const hasSelectedAlert: (state: AlertListState) => boolean = createSelect | |
uiQueryParams, | ||
({ selected_alert: selectedAlert }) => selectedAlert !== undefined | ||
); | ||
|
||
/** | ||
* Determine if the alert event is most likely compatible with LegacyEndpointEvent. | ||
*/ | ||
function isAlertEventLegacyEndpointEvent(event: { endgame?: {} }): event is LegacyEndpointEvent { | ||
return event.endgame !== undefined && 'unique_pid' in event.endgame; | ||
} | ||
|
||
export const selectedEvent: ( | ||
state: AlertListState | ||
) => LegacyEndpointEvent | undefined = createSelector( | ||
uiQueryParams, | ||
alertListData, | ||
({ selected_alert: selectedAlert }, alertList) => { | ||
const found = alertList.find(alert => alert.event.id === selectedAlert); | ||
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. These will never equal each other based on how the rest of the details flyout is implemented. We use |
||
if (!found) { | ||
return found; | ||
} | ||
return isAlertEventLegacyEndpointEvent(found) ? found : undefined; | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import { urlFromQueryParams } from './url_from_query_params'; | |
import { AlertData } from '../../../../../common/types'; | ||
import * as selectors from '../../store/alerts/selectors'; | ||
import { useAlertListSelector } from './hooks/use_alerts_selector'; | ||
import { AlertDetailResolver } from './resolver'; | ||
|
||
export const AlertIndex = memo(() => { | ||
const history = useHistory(); | ||
|
@@ -86,6 +87,7 @@ export const AlertIndex = memo(() => { | |
const alertListData = useAlertListSelector(selectors.alertListData); | ||
const hasSelectedAlert = useAlertListSelector(selectors.hasSelectedAlert); | ||
const queryParams = useAlertListSelector(selectors.uiQueryParams); | ||
const selectedEvent = useAlertListSelector(selectors.selectedEvent); | ||
|
||
const onChangeItemsPerPage = useCallback( | ||
newPageSize => { | ||
|
@@ -132,12 +134,11 @@ export const AlertIndex = memo(() => { | |
} | ||
|
||
const row = alertListData[rowIndex % pageSize]; | ||
|
||
if (columnId === 'alert_type') { | ||
return ( | ||
<Link | ||
data-testid="alertTypeCellLink" | ||
to={urlFromQueryParams({ ...queryParams, selected_alert: 'TODO' })} | ||
to={urlFromQueryParams({ ...queryParams, selected_alert: row.event.id })} | ||
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. ❔ row could resolve to 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. @kqualters-elastic We use |
||
> | ||
{i18n.translate( | ||
'xpack.endpoint.application.endpoint.alerts.alertType.maliciousFileDescription', | ||
|
@@ -213,7 +214,9 @@ export const AlertIndex = memo(() => { | |
</h2> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody /> | ||
<EuiFlyoutBody> | ||
<AlertDetailResolver selectedEvent={selectedEvent} /> | ||
</EuiFlyoutBody> | ||
</EuiFlyout> | ||
)} | ||
<EuiPage data-test-subj="alertListPage" data-testid="alertListPage"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { Provider } from 'react-redux'; | ||
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; | ||
import { Resolver } from '../../../../embeddables/resolver/view'; | ||
import { EndpointPluginServices } from '../../../../plugin'; | ||
import { LegacyEndpointEvent } from '../../../../../common/types'; | ||
import { storeFactory } from '../../../../embeddables/resolver/store'; | ||
|
||
export const AlertDetailResolver = styled( | ||
React.memo( | ||
({ className, selectedEvent }: { className?: string; selectedEvent?: LegacyEndpointEvent }) => { | ||
const context = useKibana<EndpointPluginServices>(); | ||
const { store } = storeFactory(context); | ||
return ( | ||
<div className={className} data-test-subj="alertResolver" data-testid="alertResolver"> | ||
<Provider store={store}> | ||
<Resolver selectedEvent={selectedEvent} /> | ||
</Provider> | ||
</div> | ||
); | ||
} | ||
) | ||
)` | ||
height: 100%; | ||
width: 100%; | ||
display: flex; | ||
flex-grow: 1; | ||
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. ❔ just |
||
`; |
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.
@kqualters-elastic - maybe not for this PR, but we should consider using the kibana-react components for sharing
coreStart
in the app. I think the use of hooks rather than to forcecoreStart
down to each route's View would be better DX. If we did not want to use the kibana-react components, we could just create our own reactContext
and set of hooks.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.
agreed, updated to do just that.