Skip to content

Commit ee61373

Browse files
[Security Solution][Alert details] do not open the SessionView detailed panel on first load (#210121)
## Summary We [recently improved](#200270) the SessionView experience when visualized within the alert details expandable flyout. One downside was that the SessionView detailed panel was opening in the flyout preview section on first load. This was intended at the time, to mimic the behavior of the SessionView rendered in place of the alerts table. This behavior is not desired in the flyout though. This PR is making a very small code change, to ensure that the detailed panel is NOT rendered on first load, but will be when users click on a row in the SessionView tree (which is a behavior that exists today). #### Previous behavior https://github.com/user-attachments/assets/ac6c0493-5d57-4dd1-bd43-bec6b025e768 #### New behavior https://github.com/user-attachments/assets/4ce48f4d-f04d-46f8-a6b1-693fe8983d20 The amount of code change was kept to a minimum. I basically added one prop to the `onSelectedProcess` callback that will differentiate user actions from automated actions. The value is `false` by default, to not change any existing logic, except on the user click event happening in the tree. #### Logic not changed when displayed in place of the alerts table https://github.com/user-attachments/assets/b54ec319-baf5-4318-a45f-405178f92888 ## How to test - turn on the `securitySolution:enableVisualizationsInFlyout` Advanced Settings ![Screenshot 2024-12-16 at 5 05 05 PM](https://github.com/user-attachments/assets/e5a937fa-7eaf-46b3-be11-d56224daf821) - generate alerts with data for session view (`yarn test:generate -n http://elastic:changeme@localhost:9200 -k http://elastic:changeme@localhost:5601`)
1 parent 9bf4ed5 commit ee61373

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

x-pack/solutions/security/plugins/session_view/public/components/process_tree/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* 2.0; you may not use this file except in compliance with the Elastic License
55
* 2.0.
66
*/
7-
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
7+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
88
import { i18n } from '@kbn/i18n';
99
import { ProcessTreeNode } from '../process_tree_node';
1010
import { BackToInvestigatedAlert } from '../back_to_investigated_alert';
@@ -52,7 +52,7 @@ export interface ProcessTreeDeps {
5252

5353
// currently selected process
5454
selectedProcess?: Process | null;
55-
onProcessSelected: (process: Process | null) => void;
55+
onProcessSelected: (process: Process | null, isManualSelection?: boolean) => void;
5656
setSearchResults?: (results: Process[]) => void;
5757

5858
// a map for alerts with updated status and process.entity_id

x-pack/solutions/security/plugins/session_view/public/components/process_tree_node/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77

88
import React, {
9-
useState,
10-
useEffect,
119
MouseEvent,
10+
ReactElement,
11+
RefObject,
1212
useCallback,
13+
useEffect,
1314
useMemo,
14-
RefObject,
15-
ReactElement,
15+
useState,
1616
} from 'react';
17-
import { EuiButton, EuiIcon, EuiToolTip, formatDate, EuiButtonIcon } from '@elastic/eui';
17+
import { EuiButton, EuiButtonIcon, EuiIcon, EuiToolTip, formatDate } from '@elastic/eui';
1818
import { i18n } from '@kbn/i18n';
1919
import { FormattedMessage } from '@kbn/i18n-react';
2020
import { chain } from 'lodash';
@@ -43,7 +43,7 @@ export interface ProcessDeps {
4343
process: Process;
4444
isSessionLeader?: boolean;
4545
depth?: number;
46-
onProcessSelected?: (process: Process) => void;
46+
onProcessSelected?: (process: Process, isManualSelection?: boolean) => void;
4747
jumpToEntityId?: string;
4848
investigatedAlertId?: string;
4949
selectedProcess?: Process | null;
@@ -57,6 +57,7 @@ export interface ProcessDeps {
5757
loadNextButton?: ReactElement | null;
5858
loadPreviousButton?: ReactElement | null;
5959
handleCollapseProcessTree?: () => void;
60+
6061
trackEvent(name: SessionViewTelemetryKey): void;
6162
}
6263

@@ -187,7 +188,9 @@ export function ProcessTreeNode({
187188
return;
188189
}
189190

190-
onProcessSelected?.(process);
191+
// we pass true here to let the parent SessionView component that the process was selected
192+
// by a user clicking on a row in the tree
193+
onProcessSelected?.(process, true);
191194

192195
if (isSessionLeader && scrollerRef.current) {
193196
scrollerRef.current.scrollTop = 0;

x-pack/solutions/security/plugins/session_view/public/components/session_view/index.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* 2.0.
66
*/
77
import { v4 as uuidv4 } from 'uuid';
8-
import React, { useState, useCallback, useEffect, useMemo, useRef } from 'react';
8+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
99
import {
10-
EuiEmptyPrompt,
1110
EuiButton,
11+
EuiButtonIcon,
12+
EuiEmptyPrompt,
13+
EuiFlexGroup,
1214
EuiFlexItem,
13-
EuiResizableContainer,
14-
EuiPanel,
1515
EuiHorizontalRule,
16-
EuiFlexGroup,
17-
EuiButtonIcon,
16+
EuiPanel,
17+
EuiResizableContainer,
1818
EuiToolTip,
1919
} from '@elastic/eui';
2020
import { FormattedMessage } from '@kbn/i18n-react';
@@ -24,17 +24,17 @@ import { SectionLoading } from '../../shared_imports';
2424
import { ProcessTree } from '../process_tree';
2525
import type { AlertStatusEventEntityIdMap, Process, ProcessEvent } from '../../../common';
2626
import type { DisplayOptionsState } from '../session_view_display_options';
27+
import { SessionViewDisplayOptions } from '../session_view_display_options';
2728
import type { SessionViewDeps, SessionViewIndices, SessionViewTelemetryKey } from '../../types';
2829
import { SessionViewDetailPanel } from '../session_view_detail_panel';
2930
import { SessionViewSearchBar } from '../session_view_search_bar';
30-
import { SessionViewDisplayOptions } from '../session_view_display_options';
3131
import { TTYPlayer } from '../tty_player';
3232
import { useStyles } from './styles';
3333
import {
3434
useFetchAlertStatus,
35-
useFetchSessionViewProcessEvents,
36-
useFetchSessionViewAlerts,
3735
useFetchGetTotalIOBytes,
36+
useFetchSessionViewAlerts,
37+
useFetchSessionViewProcessEvents,
3838
} from './hooks';
3939
import { LOCAL_STORAGE_DISPLAY_OPTIONS_KEY } from '../../../common/constants';
4040
import {
@@ -45,7 +45,7 @@ import {
4545
ELASTIC_DEFEND_DATA_SOURCE,
4646
ENDPOINT_INDEX,
4747
} from '../../methods';
48-
import { REFRESH_SESSION, TOGGLE_TTY_PLAYER, DETAIL_PANEL } from './translations';
48+
import { DETAIL_PANEL, REFRESH_SESSION, TOGGLE_TTY_PLAYER } from './translations';
4949

5050
/**
5151
* The main wrapper component for the session view.
@@ -119,12 +119,13 @@ export const SessionView = ({
119119
}, [displayOptions?.verboseMode, searchResults, searchQuery]);
120120

121121
const onProcessSelected = useCallback(
122-
(process: Process | null) => {
122+
(process: Process | null, isManualSelection = false) => {
123123
setSelectedProcess(process);
124124

125125
// used when SessionView is displayed in the expandable flyout
126126
// This refreshes the detailed panel rendered in the flyout preview panel
127-
if (openDetailsInExpandableFlyout) {
127+
// the isManualSelection prevents the detailed panel to render on first load of the SessionView component
128+
if (openDetailsInExpandableFlyout && isManualSelection) {
128129
openDetailsInExpandableFlyout(process);
129130
}
130131
},

0 commit comments

Comments
 (0)