Skip to content

Commit f81b849

Browse files
kibanamachineymao1stephmilovicelasticmachine
authored
[9.3] [Entity Analytics] Add ability to access anonymization modal in entity highlight component (#247887) (#248266)
# Backport This will backport the following commits from `main` to `9.3`: - [[Entity Analytics] Add ability to access anonymization modal in entity highlight component (#247887)](#247887) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ying Mao","email":"ying.mao@elastic.co"},"sourceCommit":{"committedDate":"2026-01-08T13:11:56Z","message":"[Entity Analytics] Add ability to access anonymization modal in entity highlight component (#247887)\n\nResolves https://github.com/elastic/kibana/issues/247028\n\n## Summary\n\nThe entity highlight component uses global anonymization settings that\ncan be managed via the anonymization modal. Previously, we were allowing\nusers to toggle anonymization on and off but were not allowing access to\nadjust the anonymization settings from this menu. This PR adds the\nability to open the anonymization modal settings from the menu.\n\nNote, the original issue description mentioned that these anonymization\nsettings should not be shown in Agent Builder mode. While it is true\nthat Agent Builder does not handle anonymization, the entity highlight\ndoes not directly use Agent Builder and so these anonymization settings\nshould show up regardless of whether we're using Agent Builder or\nClassic AI Assistant. [This\ncomment](https://github.com/elastic/kibana/issues/247028#issuecomment-3682941117)\nis a better description of the issue.\n\n## To Verify\n\n1. Start ES and Kibana\n2. Generate some alerts using the `security-documents-generator` and run\nthe risk scoring task\n3. Navigate to the Entity Analytics Overview and open the details flyout\nfor an entity\n4. Click the hamburger menu and see that an \"gear\" icon is available\n(although the screenshot is old and shows an \"eye\")\n<img width=\"831\" height=\"268\" alt=\"Screenshot 2026-01-05 at 4 44 28 PM\"\nsrc=\"https://github.com/user-attachments/assets/e7b3d1a0-e4ab-4d16-b25c-47475d705315\"\n/>\n\n5. Click the icon and open the anonymization settings modal to customize\nanonymization settings\n<img width=\"771\" height=\"887\" alt=\"Screenshot 2026-01-05 at 4 46 55 PM\"\nsrc=\"https://github.com/user-attachments/assets/b8895f32-f75b-4af9-835b-0cf8a5bbecf7\"\n/>\n\n---------\n\nCo-authored-by: Steph Milovic <stephanie.milovic@elastic.co>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"4e40a027a46e6c6969ae9c7c69f961ae3d3f9dcf","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Entity Analytics","backport:version","v9.3.0","v9.4.0"],"title":"[Entity Analytics] Add ability to access anonymization modal in entity highlight component","number":247887,"url":"https://github.com/elastic/kibana/pull/247887","mergeCommit":{"message":"[Entity Analytics] Add ability to access anonymization modal in entity highlight component (#247887)\n\nResolves https://github.com/elastic/kibana/issues/247028\n\n## Summary\n\nThe entity highlight component uses global anonymization settings that\ncan be managed via the anonymization modal. Previously, we were allowing\nusers to toggle anonymization on and off but were not allowing access to\nadjust the anonymization settings from this menu. This PR adds the\nability to open the anonymization modal settings from the menu.\n\nNote, the original issue description mentioned that these anonymization\nsettings should not be shown in Agent Builder mode. While it is true\nthat Agent Builder does not handle anonymization, the entity highlight\ndoes not directly use Agent Builder and so these anonymization settings\nshould show up regardless of whether we're using Agent Builder or\nClassic AI Assistant. [This\ncomment](https://github.com/elastic/kibana/issues/247028#issuecomment-3682941117)\nis a better description of the issue.\n\n## To Verify\n\n1. Start ES and Kibana\n2. Generate some alerts using the `security-documents-generator` and run\nthe risk scoring task\n3. Navigate to the Entity Analytics Overview and open the details flyout\nfor an entity\n4. Click the hamburger menu and see that an \"gear\" icon is available\n(although the screenshot is old and shows an \"eye\")\n<img width=\"831\" height=\"268\" alt=\"Screenshot 2026-01-05 at 4 44 28 PM\"\nsrc=\"https://github.com/user-attachments/assets/e7b3d1a0-e4ab-4d16-b25c-47475d705315\"\n/>\n\n5. Click the icon and open the anonymization settings modal to customize\nanonymization settings\n<img width=\"771\" height=\"887\" alt=\"Screenshot 2026-01-05 at 4 46 55 PM\"\nsrc=\"https://github.com/user-attachments/assets/b8895f32-f75b-4af9-835b-0cf8a5bbecf7\"\n/>\n\n---------\n\nCo-authored-by: Steph Milovic <stephanie.milovic@elastic.co>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"4e40a027a46e6c6969ae9c7c69f961ae3d3f9dcf"}},"sourceBranch":"main","suggestedTargetBranches":["9.3"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/247887","number":247887,"mergeCommit":{"message":"[Entity Analytics] Add ability to access anonymization modal in entity highlight component (#247887)\n\nResolves https://github.com/elastic/kibana/issues/247028\n\n## Summary\n\nThe entity highlight component uses global anonymization settings that\ncan be managed via the anonymization modal. Previously, we were allowing\nusers to toggle anonymization on and off but were not allowing access to\nadjust the anonymization settings from this menu. This PR adds the\nability to open the anonymization modal settings from the menu.\n\nNote, the original issue description mentioned that these anonymization\nsettings should not be shown in Agent Builder mode. While it is true\nthat Agent Builder does not handle anonymization, the entity highlight\ndoes not directly use Agent Builder and so these anonymization settings\nshould show up regardless of whether we're using Agent Builder or\nClassic AI Assistant. [This\ncomment](https://github.com/elastic/kibana/issues/247028#issuecomment-3682941117)\nis a better description of the issue.\n\n## To Verify\n\n1. Start ES and Kibana\n2. Generate some alerts using the `security-documents-generator` and run\nthe risk scoring task\n3. Navigate to the Entity Analytics Overview and open the details flyout\nfor an entity\n4. Click the hamburger menu and see that an \"gear\" icon is available\n(although the screenshot is old and shows an \"eye\")\n<img width=\"831\" height=\"268\" alt=\"Screenshot 2026-01-05 at 4 44 28 PM\"\nsrc=\"https://github.com/user-attachments/assets/e7b3d1a0-e4ab-4d16-b25c-47475d705315\"\n/>\n\n5. Click the icon and open the anonymization settings modal to customize\nanonymization settings\n<img width=\"771\" height=\"887\" alt=\"Screenshot 2026-01-05 at 4 46 55 PM\"\nsrc=\"https://github.com/user-attachments/assets/b8895f32-f75b-4af9-835b-0cf8a5bbecf7\"\n/>\n\n---------\n\nCo-authored-by: Steph Milovic <stephanie.milovic@elastic.co>\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"4e40a027a46e6c6969ae9c7c69f961ae3d3f9dcf"}}]}] BACKPORT--> Co-authored-by: Ying Mao <ying.mao@elastic.co> Co-authored-by: Steph Milovic <stephanie.milovic@elastic.co> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 48f11e0 commit f81b849

File tree

2 files changed

+98
-13
lines changed

2 files changed

+98
-13
lines changed

x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/components/entity_highlights_settings.test.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import React from 'react';
99
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
10+
import { userEvent } from '@testing-library/user-event';
1011
import { EntityHighlightsSettings } from './entity_highlights_settings';
1112
import { TestProviders } from '../../../../common/mock';
1213

@@ -34,6 +35,19 @@ jest.mock('../../../../agent_builder/hooks/use_agent_builder_attachment', () =>
3435
}),
3536
}));
3637

38+
jest.mock(
39+
'@kbn/elastic-assistant/impl/data_anonymization/settings/anonymization_settings_management',
40+
() => ({
41+
AnonymizationSettingsManagement: ({ onClose }: { onClose: () => void }) => (
42+
<div data-test-subj="anonymizationSettingsModal">
43+
<button type="button" data-test-subj="closeAnonymizationSettingsModal" onClick={onClose}>
44+
{'Close'}
45+
</button>
46+
</div>
47+
),
48+
})
49+
);
50+
3751
describe('EntityHighlightsSettings', () => {
3852
const defaultProps = {
3953
showAnonymizedValues: false,
@@ -225,4 +239,37 @@ describe('EntityHighlightsSettings', () => {
225239

226240
expect(screen.getByRole('switch')).not.toBeChecked();
227241
});
242+
243+
it('renders the anonymization settings button', () => {
244+
render(<EntityHighlightsSettings {...defaultProps} />, {
245+
wrapper: TestProviders,
246+
});
247+
248+
expect(screen.getByTestId('anonymizationSettings')).toBeInTheDocument();
249+
});
250+
251+
it('opens the anonymization settings modal when the settings button is clicked', async () => {
252+
render(<EntityHighlightsSettings {...defaultProps} />, {
253+
wrapper: TestProviders,
254+
});
255+
256+
await userEvent.click(screen.getByTestId('anonymizationSettings'));
257+
await waitFor(() =>
258+
expect(screen.getByTestId('anonymizationSettingsModal')).toBeInTheDocument()
259+
);
260+
});
261+
262+
it('closes the anonymization settings modal when onClose is triggered', async () => {
263+
render(<EntityHighlightsSettings {...defaultProps} />, {
264+
wrapper: TestProviders,
265+
});
266+
267+
await userEvent.click(screen.getByTestId('anonymizationSettings'));
268+
await waitFor(() => expect(screen.getByTestId('anonymizationSettingsModal')).toBeVisible());
269+
270+
await userEvent.click(screen.getByTestId('closeAnonymizationSettingsModal'));
271+
await waitFor(() =>
272+
expect(screen.queryByTestId('anonymizationSettingsModal')).not.toBeInTheDocument()
273+
);
274+
});
228275
});

x-pack/solutions/security/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/components/entity_highlights_settings.tsx

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import {
1616
EuiPopover,
1717
EuiButtonIcon,
1818
} from '@elastic/eui';
19-
import React, { useMemo, useCallback } from 'react';
19+
import React, { useMemo, useCallback, useState } from 'react';
2020
import { i18n } from '@kbn/i18n';
2121
import { FormattedMessage } from '@kbn/i18n-react';
2222
import { AssistantIcon } from '@kbn/ai-assistant-icon';
2323
import { noop } from 'lodash';
2424
import { ConnectorSelectorInline } from '@kbn/elastic-assistant';
2525
import { css } from '@emotion/react';
2626
import { isEmpty } from 'lodash/fp';
27+
import { AnonymizationSettingsManagement } from '@kbn/elastic-assistant/impl/data_anonymization/settings/anonymization_settings_management';
2728
import { useAgentBuilderAvailability } from '../../../../agent_builder/hooks/use_agent_builder_availability';
2829
import { ENTITY_PROMPT } from '../../../../agent_builder/components/prompts';
2930
import { NewAgentBuilderAttachment } from '../../../../agent_builder/components/new_agent_builder_attachment';
@@ -78,6 +79,10 @@ export const EntityHighlightsSettings: React.FC<EntityHighlightsSettingsProps> =
7879
[entityIdentifier, assistantResult?.replacements]
7980
);
8081

82+
const [isAnonymizationModalVisible, setIsAnonymizationModalVisible] = useState(false);
83+
const closeAnonymizationModal = useCallback(() => setIsAnonymizationModalVisible(false), []);
84+
const showAnonymizationModal = useCallback(() => setIsAnonymizationModalVisible(true), []);
85+
8186
const getPromptContext = useCallback(
8287
async () =>
8388
`### The following entity is under investigation:\nType: ${entityType}\nIdentifier: ${`\`${anonymizedEntityIdentifier}\``}\n#### Context:\n\`\`\`json\n${
@@ -128,18 +133,44 @@ export const EntityHighlightsSettings: React.FC<EntityHighlightsSettingsProps> =
128133
>
129134
<EuiFlexGroup direction="row" gutterSize="s" alignItems="center">
130135
<EuiFlexItem grow={false}>
131-
<EuiSwitch
132-
label={i18n.translate(
133-
'xpack.securitySolution.flyout.entityDetails.highlights.showAnonymizedValues',
134-
{
135-
defaultMessage: 'Show anonymized values',
136-
}
137-
)}
138-
checked={showAnonymizedValues}
139-
onChange={onChangeShowAnonymizedValues}
140-
compressed
141-
disabled={!selectedConversationHasAnonymizedValues}
142-
/>
136+
<EuiFlexGroup
137+
alignItems="center"
138+
data-test-subj="anonymizationGroup"
139+
gutterSize="s"
140+
responsive={false}
141+
wrap={false}
142+
>
143+
<EuiFlexItem grow={false}>
144+
<EuiSwitch
145+
label={i18n.translate(
146+
'xpack.securitySolution.flyout.entityDetails.highlights.showAnonymizedValues',
147+
{
148+
defaultMessage: 'Show anonymized values',
149+
}
150+
)}
151+
checked={showAnonymizedValues}
152+
onChange={onChangeShowAnonymizedValues}
153+
compressed
154+
disabled={!selectedConversationHasAnonymizedValues}
155+
/>
156+
</EuiFlexItem>
157+
158+
<EuiFlexItem grow={false}>
159+
<EuiButtonIcon
160+
aria-label={i18n.translate(
161+
'xpack.securitySolution.flyout.entityDetails.highlights.anonymizationArialLabel',
162+
{
163+
defaultMessage: 'Anonymization',
164+
}
165+
)}
166+
data-test-subj="anonymizationSettings"
167+
iconType="gear"
168+
onClick={showAnonymizationModal}
169+
size="s"
170+
color="text"
171+
/>
172+
</EuiFlexItem>
173+
</EuiFlexGroup>
143174
</EuiFlexItem>
144175
</EuiFlexGroup>
145176
</EuiContextMenuItem>
@@ -189,6 +220,10 @@ export const EntityHighlightsSettings: React.FC<EntityHighlightsSettingsProps> =
189220
)
190221
)}
191222

223+
{isAnonymizationModalVisible && (
224+
<AnonymizationSettingsManagement modalMode onClose={closeAnonymizationModal} />
225+
)}
226+
192227
<EuiContextMenuItem
193228
aria-label={i18n.translate(
194229
'xpack.securitySolution.flyout.entityDetails.highlights.connectorSelectorAriaLabel',
@@ -218,6 +253,9 @@ export const EntityHighlightsSettings: React.FC<EntityHighlightsSettingsProps> =
218253
isAgentBuilderEnabled,
219254
isLoading,
220255
assistantResult,
256+
showAnonymizationModal,
257+
closeAnonymizationModal,
258+
isAnonymizationModalVisible,
221259
]
222260
);
223261

0 commit comments

Comments
 (0)