Skip to content

Commit fea61a7

Browse files
[8.19] [Security Solution] Fix hover actions when data view manager is enabled (#225561) (#225933)
# Backport This will backport the following commits from `main` to `8.19`: - [[Security Solution] Fix hover actions when data view manager is enabled (#225561)](#225561) <!--- Backport version: 10.0.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"christineweng","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-27T17:56:28Z","message":"[Security Solution] Fix hover actions when data view manager is enabled (#225561)\n\n## Summary\n\nFollow up of #224812, fixing hover\nactions in other places: kpi charts in alerts page and event table in\nexplore pages.\n\nEnable `newDataViewPickerEnabled`\n\n\n![image](https://github.com/user-attachments/assets/0402aa29-cf09-4813-8e39-ac1af898d969)","sha":"00ca52da3a9a95bf5938d7d76413a35d1e65190f","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat Hunting:Investigations","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[Security Solution] Fix hover actions when data view manager is enabled","number":225561,"url":"https://github.com/elastic/kibana/pull/225561","mergeCommit":{"message":"[Security Solution] Fix hover actions when data view manager is enabled (#225561)\n\n## Summary\n\nFollow up of #224812, fixing hover\nactions in other places: kpi charts in alerts page and event table in\nexplore pages.\n\nEnable `newDataViewPickerEnabled`\n\n\n![image](https://github.com/user-attachments/assets/0402aa29-cf09-4813-8e39-ac1af898d969)","sha":"00ca52da3a9a95bf5938d7d76413a35d1e65190f"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/225694","number":225694,"state":"MERGED","mergeCommit":{"sha":"47e270c08bbf9ce20121d8cf25a6d2417701d235","message":"[9.1] [Security Solution] Fix hover actions when data view manager is enabled (#225561) (#225694)\n\n# Backport\n\nThis will backport the following commits from `main` to `9.1`:\n- [[Security Solution] Fix hover actions when data view manager is\nenabled (#225561)](https://github.com/elastic/kibana/pull/225561)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by: christineweng <[email protected]>"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/225561","number":225561,"mergeCommit":{"message":"[Security Solution] Fix hover actions when data view manager is enabled (#225561)\n\n## Summary\n\nFollow up of #224812, fixing hover\nactions in other places: kpi charts in alerts page and event table in\nexplore pages.\n\nEnable `newDataViewPickerEnabled`\n\n\n![image](https://github.com/user-attachments/assets/0402aa29-cf09-4813-8e39-ac1af898d969)","sha":"00ca52da3a9a95bf5938d7d76413a35d1e65190f"}}]}] BACKPORT-->
1 parent 8ae2af7 commit fea61a7

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

x-pack/solutions/security/plugins/security_solution/public/common/components/cell_actions/index.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import { SecurityCellActionsTrigger } from '../../../app/actions/constants';
1111
import { CellActionsMode, SecurityCellActions } from '.';
1212
import { CellActions } from '@kbn/cell-actions';
1313

14+
jest.mock('../../../data_view_manager/hooks/use_data_view', () => ({
15+
useDataView: jest.fn(() => ({
16+
dataView: { id: 'security-default-dataview-id', fields: { getByName: jest.fn() } },
17+
})),
18+
}));
19+
20+
jest.mock('../../hooks/use_experimental_features', () => ({
21+
useIsExperimentalFeatureEnabled: jest.fn(() => false),
22+
}));
23+
1424
const MockCellActions = CellActions as jest.Mocked<typeof CellActions>;
1525
jest.mock('@kbn/cell-actions', () => ({
1626
...jest.requireActual('@kbn/cell-actions'),

x-pack/solutions/security/plugins/security_solution/public/common/components/cell_actions/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { SecurityCellActionsTrigger, SecurityCellActionType } from '../../../app
1919
import { SourcererScopeName } from '../../../sourcerer/store/model';
2020
import { useGetFieldSpec } from '../../hooks/use_get_field_spec';
2121
import { useDataViewId } from '../../hooks/use_data_view_id';
22+
import { useIsExperimentalFeatureEnabled } from '../../hooks/use_experimental_features';
23+
import { useDataView } from '../../../data_view_manager/hooks/use_data_view';
2224

2325
// bridge exports for convenience
2426
export * from '@kbn/cell-actions';
@@ -64,8 +66,13 @@ export const SecurityCellActions: React.FC<SecurityCellActionsProps> = ({
6466
children,
6567
...props
6668
}) => {
67-
const getFieldSpec = useGetFieldSpec(sourcererScopeId);
68-
const dataViewId = useDataViewId(sourcererScopeId);
69+
const oldGetFieldSpec = useGetFieldSpec(sourcererScopeId);
70+
const oldDataViewId = useDataViewId(sourcererScopeId);
71+
72+
const newDataViewPickerEnabled = useIsExperimentalFeatureEnabled('newDataViewPickerEnabled');
73+
const { dataView: experimentalDataView } = useDataView(sourcererScopeId);
74+
const dataViewId = newDataViewPickerEnabled ? experimentalDataView?.id : oldDataViewId;
75+
6976
// Make a dependency key to prevent unnecessary re-renders when data object is defined inline
7077
// It is necessary because the data object is an array or an object and useMemo would always re-render
7178
const dependencyKey = JSON.stringify(data);
@@ -74,12 +81,14 @@ export const SecurityCellActions: React.FC<SecurityCellActionsProps> = ({
7481
() =>
7582
(Array.isArray(data) ? data : [data])
7683
.map(({ field, value }) => ({
77-
field: getFieldSpec(field),
84+
field: newDataViewPickerEnabled
85+
? experimentalDataView?.fields?.getByName(field)?.toSpec()
86+
: oldGetFieldSpec(field),
7887
value,
7988
}))
8089
.filter((item): item is CellActionsData => !!item.field),
8190
// eslint-disable-next-line react-hooks/exhaustive-deps -- Use the dependencyKey to prevent unnecessary re-renders
82-
[dependencyKey, getFieldSpec]
91+
[dependencyKey, oldGetFieldSpec, newDataViewPickerEnabled, experimentalDataView?.fields]
8392
);
8493

8594
const metadataWithDataView = useMemo(() => ({ ...metadata, dataViewId }), [dataViewId, metadata]);

x-pack/solutions/security/plugins/security_solution/public/common/components/events_viewer/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import type { EuiTheme } from '@kbn/kibana-react-plugin/common';
3636
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
3737
import type { RunTimeMappings } from '@kbn/timelines-plugin/common/search_strategy';
3838
import { useDataViewSpec } from '../../../data_view_manager/hooks/use_data_view_spec';
39+
import { useDataView } from '../../../data_view_manager/hooks/use_data_view';
3940
import { InspectButton } from '../inspect';
4041
import type {
4142
ControlColumnProps,
@@ -156,9 +157,12 @@ const StatefulEventsViewerComponent: React.FC<EventsViewerProps & PropsFromRedux
156157
sourcererDataView: oldSourcererDataView,
157158
loading: oldIsLoadingIndexPattern,
158159
} = useSourcererDataView(sourcererScope);
160+
const oldGetFieldSpec = useGetFieldSpec(sourcererScope);
159161

160162
const newDataViewPickerEnabled = useIsExperimentalFeatureEnabled('newDataViewPickerEnabled');
161163
const { dataViewSpec, status } = useDataViewSpec(sourcererScope);
164+
const { dataView: experimentalDataView } = useDataView(sourcererScope);
165+
162166
const experimentalSelectedPatterns = useSelectedPatterns(sourcererScope);
163167
const experimentalBrowserFields = useBrowserFields(sourcererScope);
164168
const selectedPatterns = newDataViewPickerEnabled
@@ -172,7 +176,13 @@ const StatefulEventsViewerComponent: React.FC<EventsViewerProps & PropsFromRedux
172176
const selectedDataViewId = newDataViewPickerEnabled ? dataViewSpec.id : oldDataViewId;
173177
const browserFields = newDataViewPickerEnabled ? experimentalBrowserFields : oldBrowserFields;
174178

175-
const getFieldSpec = useGetFieldSpec(sourcererScope);
179+
const experimentalGetFieldSpec = useCallback(
180+
(fieldName: string) => {
181+
return experimentalDataView?.fields?.getByName(fieldName)?.toSpec();
182+
},
183+
[experimentalDataView?.fields]
184+
);
185+
const getFieldSpec = newDataViewPickerEnabled ? experimentalGetFieldSpec : oldGetFieldSpec;
176186

177187
const editorActionsRef = useRef<FieldEditorActions>(null);
178188
useEffect(() => {

x-pack/solutions/security/plugins/security_solution/public/detections/hooks/trigger_actions_alert_table/use_cell_actions.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const useCellActionsOptions = (
3030
>
3131
) => {
3232
const newDataViewPickerEnabled = useIsExperimentalFeatureEnabled('newDataViewPickerEnabled');
33-
const experimentalDataView = useDataView(SourcererScopeName.detections);
33+
const { dataView: experimentalDataView } = useDataView(SourcererScopeName.detections);
3434

3535
const {
3636
columns = [],
@@ -39,9 +39,9 @@ export const useCellActionsOptions = (
3939
pageSize = 0,
4040
dataGridRef,
4141
} = context ?? {};
42-
const getFieldSpec = useGetFieldSpec(SourcererScopeName.detections);
42+
const oldGetFieldSpec = useGetFieldSpec(SourcererScopeName.detections);
4343
const oldDataViewId = useDataViewId(SourcererScopeName.detections);
44-
const dataViewId = newDataViewPickerEnabled ? experimentalDataView?.dataView?.id : oldDataViewId;
44+
const dataViewId = newDataViewPickerEnabled ? experimentalDataView?.id : oldDataViewId;
4545

4646
const cellActionsMetadata = useMemo(
4747
() => ({ scopeId: tableId, dataViewId }),
@@ -52,15 +52,15 @@ export const useCellActionsOptions = (
5252
columns.map(
5353
(column) =>
5454
(newDataViewPickerEnabled
55-
? experimentalDataView.dataView?.fields?.getByName(column.id)?.toSpec()
56-
: getFieldSpec(column.id)) ?? {
55+
? experimentalDataView?.fields?.getByName(column.id)?.toSpec()
56+
: oldGetFieldSpec(column.id)) ?? {
5757
name: '',
5858
type: '', // When type is an empty string all cell actions are incompatible
5959
aggregatable: false,
6060
searchable: false,
6161
}
6262
),
63-
[columns, experimentalDataView.dataView?.fields, getFieldSpec, newDataViewPickerEnabled]
63+
[columns, experimentalDataView?.fields, oldGetFieldSpec, newDataViewPickerEnabled]
6464
);
6565

6666
/**

0 commit comments

Comments
 (0)