-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Alerty summary table flyout setup #217421
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
Merged
PhilippeOberti
merged 2 commits into
elastic:main
from
PhilippeOberti:alerty-summary-table-flyout-setup
Apr 10, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...rity_solution/public/detections/components/alert_summary/common/integration_icon.test.tsx
This file contains hidden or 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,58 @@ | ||
| /* | ||
| * 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 { render } from '@testing-library/react'; | ||
| import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; | ||
| import React from 'react'; | ||
| import { useGetIntegrationFromRuleId } from '../../../hooks/alert_summary/use_get_integration_from_rule_id'; | ||
| import { usePackageIconType } from '@kbn/fleet-plugin/public/hooks'; | ||
| import { | ||
| INTEGRATION_INTEGRATION_ICON_TEST_ID, | ||
| INTEGRATION_LOADING_SKELETON_TEST_ID, | ||
| IntegrationIcon, | ||
| } from './integration_icon'; | ||
|
|
||
| jest.mock('../../../hooks/alert_summary/use_get_integration_from_rule_id'); | ||
| jest.mock('@kbn/fleet-plugin/public/hooks'); | ||
|
|
||
| describe('IntegrationIcon', () => { | ||
| it('should return a single integration icon', () => { | ||
| (useGetIntegrationFromRuleId as jest.Mock).mockReturnValue({ | ||
| integration: { | ||
| title: 'title', | ||
| icons: [{ type: 'type', src: 'src' }], | ||
| name: 'name', | ||
| version: 'version', | ||
| }, | ||
| isLoading: false, | ||
| }); | ||
| (usePackageIconType as jest.Mock).mockReturnValue('iconType'); | ||
|
|
||
| const { getByTestId } = render( | ||
| <IntlProvider locale="en"> | ||
| <IntegrationIcon ruleId={'name'} /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| expect(getByTestId(INTEGRATION_INTEGRATION_ICON_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should return a single integration loading', () => { | ||
| (useGetIntegrationFromRuleId as jest.Mock).mockReturnValue({ | ||
| integration: {}, | ||
| isLoading: true, | ||
| }); | ||
|
|
||
| const { getByTestId } = render( | ||
| <IntlProvider locale="en"> | ||
| <IntegrationIcon ruleId={''} /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| expect(getByTestId(INTEGRATION_LOADING_SKELETON_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
| }); |
55 changes: 55 additions & 0 deletions
55
.../security_solution/public/detections/components/alert_summary/common/integration_icon.tsx
This file contains hidden or 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,55 @@ | ||
| /* | ||
| * 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 React, { memo } from 'react'; | ||
| import { EuiSkeletonText } from '@elastic/eui'; | ||
| import { CardIcon } from '@kbn/fleet-plugin/public'; | ||
| import type { IconSize } from '@elastic/eui/src/components/icon/icon'; | ||
| import { useGetIntegrationFromRuleId } from '../../../hooks/alert_summary/use_get_integration_from_rule_id'; | ||
|
|
||
| export const INTEGRATION_LOADING_SKELETON_TEST_ID = 'ai-for-soc-alert-integration-loading-skeleton'; | ||
| export const INTEGRATION_INTEGRATION_ICON_TEST_ID = 'ai-for-soc-alert-integration-icon'; | ||
|
|
||
| interface IntegrationProps { | ||
| /** | ||
| * Id of the rule the alert was generated by | ||
| */ | ||
| ruleId: string; | ||
| /** | ||
| * Changes the size of the icon. Uses the Eui IconSize interface. | ||
| * Defaults to s | ||
| */ | ||
| iconSize?: IconSize; | ||
| } | ||
|
|
||
| /** | ||
| * Renders the icon for the integration that matches the rule id. | ||
| * In AI for SOC, we can retrieve the integration/package that matches a specific rule, via the related_integrations field on the rule. | ||
| */ | ||
| export const IntegrationIcon = memo(({ ruleId, iconSize = 's' }: IntegrationProps) => { | ||
| const { integration, isLoading } = useGetIntegrationFromRuleId({ ruleId }); | ||
|
|
||
| return ( | ||
| <EuiSkeletonText | ||
| data-test-subj={INTEGRATION_LOADING_SKELETON_TEST_ID} | ||
| isLoading={isLoading} | ||
| lines={1} | ||
| > | ||
| {integration ? ( | ||
| <CardIcon | ||
| data-test-subj={INTEGRATION_INTEGRATION_ICON_TEST_ID} | ||
| icons={integration.icons} | ||
| integrationName={integration.title} | ||
| packageName={integration.name} | ||
| size={iconSize} | ||
| version={integration.version} | ||
| /> | ||
| ) : null} | ||
| </EuiSkeletonText> | ||
| ); | ||
| }); | ||
| IntegrationIcon.displayName = 'IntegrationIcon'; |
58 changes: 58 additions & 0 deletions
58
.../security_solution/public/detections/components/alert_summary/table/actions_cell.test.tsx
This file contains hidden or 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,58 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import type { Alert } from '@kbn/alerting-types'; | ||
| import { ActionsCell, ROW_ACTION_FLYOUT_ICON_TEST_ID } from './actions_cell'; | ||
| import { useExpandableFlyoutApi } from '@kbn/expandable-flyout'; | ||
| import { IOCPanelKey } from '../../../../flyout/ai_for_soc/constants/panel_keys'; | ||
|
|
||
| jest.mock('@kbn/expandable-flyout'); | ||
|
|
||
| describe('ActionsCell', () => { | ||
| it('should render icons', () => { | ||
| (useExpandableFlyoutApi as jest.Mock).mockReturnValue({ | ||
| openFlyout: jest.fn(), | ||
| }); | ||
|
|
||
| const alert: Alert = { | ||
| _id: '_id', | ||
| _index: '_index', | ||
| }; | ||
|
|
||
| const { getByTestId } = render(<ActionsCell alert={alert} />); | ||
|
|
||
| expect(getByTestId(ROW_ACTION_FLYOUT_ICON_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should open flyout after click', () => { | ||
| const openFlyout = jest.fn(); | ||
| (useExpandableFlyoutApi as jest.Mock).mockReturnValue({ | ||
| openFlyout, | ||
| }); | ||
|
|
||
| const alert: Alert = { | ||
| _id: '_id', | ||
| _index: '_index', | ||
| }; | ||
|
|
||
| const { getByTestId } = render(<ActionsCell alert={alert} />); | ||
|
|
||
| getByTestId(ROW_ACTION_FLYOUT_ICON_TEST_ID).click(); | ||
|
|
||
| expect(openFlyout).toHaveBeenCalledWith({ | ||
| right: { | ||
| id: IOCPanelKey, | ||
| params: { | ||
| id: alert._id, | ||
| indexName: alert._index, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| }); |
66 changes: 66 additions & 0 deletions
66
...ugins/security_solution/public/detections/components/alert_summary/table/actions_cell.tsx
This file contains hidden or 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,66 @@ | ||
| /* | ||
| * 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 React, { memo, useCallback } from 'react'; | ||
| import { useExpandableFlyoutApi } from '@kbn/expandable-flyout'; | ||
| import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
| import type { Alert } from '@kbn/alerting-types'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { IOCPanelKey } from '../../../../flyout/ai_for_soc/constants/panel_keys'; | ||
|
|
||
| export const ROW_ACTION_FLYOUT_ICON_TEST_ID = 'alert-summary-table-row-action-flyout-icon'; | ||
|
|
||
| export interface ActionsCellProps { | ||
| /** | ||
| * Alert data passed from the renderCellValue callback via the AlertWithLegacyFormats interface | ||
| */ | ||
| alert: Alert; | ||
| } | ||
|
|
||
| /** | ||
| * Component used in the AI for SOC alert summary table. | ||
| * It is passed to the renderActionsCell property of the EuiDataGrid. | ||
| * It renders all the icons in the row action icons: | ||
| * - open flyout | ||
| * - assistant (soon) | ||
| * - more actions (soon) | ||
| */ | ||
| export const ActionsCell = memo(({ alert }: ActionsCellProps) => { | ||
| const { openFlyout } = useExpandableFlyoutApi(); | ||
| const onOpenFlyout = useCallback( | ||
| () => | ||
| openFlyout({ | ||
| right: { | ||
| id: IOCPanelKey, | ||
| params: { | ||
| id: alert._id, | ||
| indexName: alert._index, | ||
| }, | ||
| }, | ||
| }), | ||
| [alert, openFlyout] | ||
| ); | ||
|
|
||
| return ( | ||
| <EuiFlexGroup alignItems="center" gutterSize="xs"> | ||
| <EuiFlexItem> | ||
| <EuiButtonIcon | ||
| aria-label={i18n.translate('xpack.securitySolution.alertSummary.table.flyoutIcon', { | ||
| defaultMessage: 'Open flyout', | ||
| })} | ||
| color="primary" | ||
| data-test-subj={ROW_ACTION_FLYOUT_ICON_TEST_ID} | ||
| iconType="expand" | ||
| onClick={onOpenFlyout} | ||
| size="xs" | ||
| /> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| ); | ||
| }); | ||
|
|
||
| ActionsCell.displayName = 'ActionsCell'; |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.