-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Atack/Alerts] Flyout header: Assignees #252190
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
agusruidiazgd
merged 8 commits into
elastic:main
from
agusruidiazgd:feat/attacks-alerts-flyout-header-asignees
Feb 10, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ec3dcd
wip
agusruidiazgd d088c9d
fix tests ids
agusruidiazgd d479b0a
Merge branch 'main' into feat/attacks-alerts-flyout-header-asignees
agusruidiazgd b13c283
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine 2e70ea6
fix types test
agusruidiazgd 66b8443
Merge branch 'main' into feat/attacks-alerts-flyout-header-asignees
agusruidiazgd d7b9d67
fix failing test
agusruidiazgd 1ded9ee
Merge branch 'main' into feat/attacks-alerts-flyout-header-asignees
agusruidiazgd 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
144 changes: 144 additions & 0 deletions
144
...rity/plugins/security_solution/public/flyout/attack_details/components/assignees.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,144 @@ | ||
| /* | ||
| * 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, screen } from '@testing-library/react'; | ||
|
|
||
| import { Assignees } from './assignees'; | ||
| import { TestProviders } from '../../../common/mock'; | ||
| import { useAttackDetailsAssignees } from '../hooks/use_attack_details_assignees'; | ||
| import { HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID } from '../constants/test_ids'; | ||
|
|
||
| import { | ||
| USERS_AVATARS_COUNT_BADGE_TEST_ID, | ||
| USERS_AVATARS_PANEL_TEST_ID, | ||
| USER_AVATAR_ITEM_TEST_ID, | ||
| } from '../../../common/components/user_profiles/test_ids'; | ||
|
|
||
| jest.mock('../hooks/use_attack_details_assignees'); | ||
| jest.mock('../../../common/components/empty_value', () => ({ | ||
| getEmptyTagValue: () => '—', | ||
| })); | ||
|
|
||
| const mockUseAttackDetailsAssignees = useAttackDetailsAssignees as jest.MockedFunction< | ||
| typeof useAttackDetailsAssignees | ||
| >; | ||
|
|
||
| const defaultHookReturn = { | ||
| assignedUserIds: ['uid-1'], | ||
| assignedUsers: [ | ||
| { | ||
| uid: 'uid-1', | ||
| enabled: true, | ||
| user: { username: 'user1', full_name: 'User 1' }, | ||
| data: {}, | ||
| }, | ||
| ], | ||
| onApplyAssignees: jest.fn().mockResolvedValue(undefined), | ||
| hasPermission: true, | ||
| isPlatinumPlus: true, | ||
| upsellingMessage: undefined, | ||
| isLoading: false, | ||
| }; | ||
|
|
||
| const renderAssignees = () => | ||
| render( | ||
| <TestProviders> | ||
| <Assignees /> | ||
| </TestProviders> | ||
| ); | ||
|
|
||
| describe('Assignees', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockUseAttackDetailsAssignees.mockReturnValue( | ||
| defaultHookReturn as ReturnType<typeof useAttackDetailsAssignees> | ||
| ); | ||
| }); | ||
|
|
||
| it('renders empty state when user has no permission', () => { | ||
| mockUseAttackDetailsAssignees.mockReturnValue({ | ||
| ...defaultHookReturn, | ||
| hasPermission: false, | ||
| } as ReturnType<typeof useAttackDetailsAssignees>); | ||
|
|
||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId('attackDetailsFlyoutHeaderAssigneesEmpty')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('attackDetailsFlyoutHeaderAssigneesEmpty')).toHaveTextContent('—'); | ||
| expect(screen.queryByTestId('attackDetailsFlyoutHeaderAssignees')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders empty state when not platinum plus', () => { | ||
| mockUseAttackDetailsAssignees.mockReturnValue({ | ||
| ...defaultHookReturn, | ||
| isPlatinumPlus: false, | ||
| } as ReturnType<typeof useAttackDetailsAssignees>); | ||
|
|
||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId('attackDetailsFlyoutHeaderAssigneesEmpty')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('attackDetailsFlyoutHeaderAssignees')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders assignees block with add button when has permission and platinum', () => { | ||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId('attackDetailsFlyoutHeaderAssignees')).toBeInTheDocument(); | ||
| expect(screen.getByTestId(HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID)).toBeInTheDocument(); | ||
| expect(screen.getByTestId(HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID)).not.toBeDisabled(); | ||
| }); | ||
|
|
||
| it('renders avatars when assignedUsers is provided', () => { | ||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId(USERS_AVATARS_PANEL_TEST_ID)).toBeInTheDocument(); | ||
| expect(screen.getByTestId(USER_AVATAR_ITEM_TEST_ID('user1'))).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders count badge when more than two assignees', () => { | ||
| mockUseAttackDetailsAssignees.mockReturnValue({ | ||
| ...defaultHookReturn, | ||
| assignedUserIds: ['uid-1', 'uid-2', 'uid-3'], | ||
| assignedUsers: [ | ||
| { uid: 'uid-1', enabled: true, user: { username: 'u1', full_name: 'U1' }, data: {} }, | ||
| { uid: 'uid-2', enabled: true, user: { username: 'u2', full_name: 'U2' }, data: {} }, | ||
| { uid: 'uid-3', enabled: true, user: { username: 'u3', full_name: 'U3' }, data: {} }, | ||
| ], | ||
| } as ReturnType<typeof useAttackDetailsAssignees>); | ||
|
|
||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId(USERS_AVATARS_COUNT_BADGE_TEST_ID)).toBeInTheDocument(); | ||
| expect(screen.getByTestId(USERS_AVATARS_COUNT_BADGE_TEST_ID)).toHaveTextContent('3'); | ||
| }); | ||
|
|
||
| it('disables add button when loading', () => { | ||
| mockUseAttackDetailsAssignees.mockReturnValue({ | ||
| ...defaultHookReturn, | ||
| isLoading: true, | ||
| } as ReturnType<typeof useAttackDetailsAssignees>); | ||
|
|
||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId(HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID)).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('does not render avatars when assignedUsers is empty', () => { | ||
| mockUseAttackDetailsAssignees.mockReturnValue({ | ||
| ...defaultHookReturn, | ||
| assignedUserIds: [], | ||
| assignedUsers: undefined, | ||
| } as ReturnType<typeof useAttackDetailsAssignees>); | ||
|
|
||
| renderAssignees(); | ||
|
|
||
| expect(screen.getByTestId('attackDetailsFlyoutHeaderAssignees')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId(USERS_AVATARS_PANEL_TEST_ID)).not.toBeInTheDocument(); | ||
| expect(screen.getByTestId(HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID)).toBeInTheDocument(); | ||
| }); | ||
| }); |
144 changes: 144 additions & 0 deletions
144
.../security/plugins/security_solution/public/flyout/attack_details/components/assignees.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,144 @@ | ||
| /* | ||
| * 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 type { FC } from 'react'; | ||
| import React, { memo, useCallback, useMemo, useState } from 'react'; | ||
|
|
||
| import { | ||
| EuiButtonIcon, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiPopover, | ||
| EuiToolTip, | ||
| useGeneratedHtmlId, | ||
| } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { getEmptyTagValue } from '../../../common/components/empty_value'; | ||
| import { ASSIGNEES_PANEL_WIDTH } from '../../../common/components/assignees/constants'; | ||
| import type { AssigneesApplyPanelProps } from '../../../common/components/assignees/assignees_apply_panel'; | ||
| import { AssigneesApplyPanel } from '../../../common/components/assignees/assignees_apply_panel'; | ||
| import { UsersAvatarsPanel } from '../../../common/components/user_profiles/users_avatars_panel'; | ||
| import { useAttackDetailsAssignees } from '../hooks/use_attack_details_assignees'; | ||
| import { HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID } from '../constants/test_ids'; | ||
|
|
||
| const UpdateAssigneesButton: FC<{ | ||
| isDisabled: boolean; | ||
| toolTipMessage: string; | ||
| togglePopover: () => void; | ||
| }> = memo(({ togglePopover, isDisabled, toolTipMessage }) => ( | ||
| <EuiToolTip position="bottom" content={toolTipMessage}> | ||
| <EuiButtonIcon | ||
| aria-label="Update assignees" | ||
| data-test-subj={HEADER_ASSIGNEES_ADD_BUTTON_TEST_ID} | ||
| iconType="plusInCircle" | ||
| onClick={togglePopover} | ||
| isDisabled={isDisabled} | ||
| /> | ||
| </EuiToolTip> | ||
| )); | ||
| UpdateAssigneesButton.displayName = 'UpdateAssigneesButton'; | ||
|
|
||
| /** | ||
| * Assignees block for the Attack details flyout header. | ||
| * Matches the look of document_details assignees (avatars + popover with AssigneesApplyPanel). | ||
| */ | ||
| export const Assignees = memo(() => { | ||
| const { | ||
| assignedUserIds, | ||
| assignedUsers, | ||
| onApplyAssignees, | ||
| hasPermission, | ||
| isPlatinumPlus, | ||
| upsellingMessage, | ||
| isLoading, | ||
| } = useAttackDetailsAssignees(); | ||
|
|
||
| const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
|
||
| const togglePopover = useCallback(() => { | ||
| setIsPopoverOpen((value) => !value); | ||
| }, []); | ||
|
|
||
| const handleApplyAssignees = useCallback<AssigneesApplyPanelProps['onApply']>( | ||
| async (assignees) => { | ||
| setIsPopoverOpen(false); | ||
| await onApplyAssignees(assignees); | ||
| }, | ||
| [onApplyAssignees] | ||
| ); | ||
|
|
||
| const searchInputId = useGeneratedHtmlId({ | ||
| prefix: 'attackDetailsAssigneesSearchInput', | ||
| }); | ||
|
|
||
| const showAssignees = hasPermission && isPlatinumPlus; | ||
|
|
||
| const toolTipMessage = | ||
| upsellingMessage ?? | ||
| i18n.translate('xpack.securitySolution.attackDetailsFlyout.header.assignees.popoverTooltip', { | ||
| defaultMessage: 'Assign attack', | ||
| }); | ||
|
|
||
| const updateAssigneesPopover = useMemo( | ||
| () => ( | ||
| <EuiPopover | ||
| panelPaddingSize="none" | ||
| initialFocus={`[id="${searchInputId}"]`} | ||
| button={ | ||
| <UpdateAssigneesButton | ||
| togglePopover={togglePopover} | ||
| isDisabled={!hasPermission || !isPlatinumPlus || isLoading} | ||
| toolTipMessage={toolTipMessage} | ||
| /> | ||
| } | ||
| isOpen={isPopoverOpen} | ||
| panelStyle={{ | ||
| minWidth: ASSIGNEES_PANEL_WIDTH, | ||
| }} | ||
| closePopover={togglePopover} | ||
| > | ||
| <AssigneesApplyPanel | ||
| searchInputId={searchInputId} | ||
| assignedUserIds={assignedUserIds} | ||
| onApply={handleApplyAssignees} | ||
| /> | ||
| </EuiPopover> | ||
| ), | ||
| [ | ||
| assignedUserIds, | ||
| handleApplyAssignees, | ||
| hasPermission, | ||
| isPlatinumPlus, | ||
| isLoading, | ||
| isPopoverOpen, | ||
| searchInputId, | ||
| togglePopover, | ||
| toolTipMessage, | ||
| ] | ||
| ); | ||
|
|
||
| if (!showAssignees) { | ||
| return <div data-test-subj="attackDetailsFlyoutHeaderAssigneesEmpty">{getEmptyTagValue()}</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <EuiFlexGroup | ||
| gutterSize="none" | ||
| responsive={false} | ||
| data-test-subj="attackDetailsFlyoutHeaderAssignees" | ||
| > | ||
| {assignedUsers && assignedUsers.length > 0 && ( | ||
| <EuiFlexItem grow={false}> | ||
| <UsersAvatarsPanel userProfiles={assignedUsers} maxVisibleAvatars={2} /> | ||
| </EuiFlexItem> | ||
| )} | ||
| <EuiFlexItem grow={false}>{updateAssigneesPopover}</EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| ); | ||
| }); | ||
|
|
||
| Assignees.displayName = 'Assignees'; | ||
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
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.
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.
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.
I'm wondering if we could follow the pattern that we have in the https://github.com/elastic/kibana/blob/main/x-pack/solutions/security/plugins/security_solution/public/flyout/attack_details/components/status_popover_button.tsx
There we:
enrichedFieldInfowhich from my understanding holds needed info (status)useAttackWorkflowStatusContextMenuItemswhich returns context menu itemsThe
useAttackWorkflowStatusContextMenuItemshandles all logic that updates status for the attack and related alerts (showing modal etc.).Following it will allow us to get rid of this new hook
x-pack/solutions/security/plugins/security_solution/public/flyout/attack_details/hooks/use_attack_details_assignees.tsand just use existinguseAttackDetailsContext.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.
Implemented here: #253729