Skip to content

Commit 023e5f7

Browse files
andrew-goldsteinkibanamachine
authored andcommitted
[Security Solution] Restores Alerts table local storage persistence and the Remove Column action (#114742)
## [Security Solution] Restores Alerts table local storage persistence and the Remove Column action This PR implements the following changes summarized below to address <#113090>, as proposed [here](#113090 (comment)): - Configures the `Columns` popover to be consistent with `Discover` - Changes the `Hide column` action to `Remove column`, to be consistent with `Discover` - Persists updates to the `Columns` popover order in `local storage` - Restores the feature to persist column widths in `local storage` ### Configures the `Columns` popover to be consistent with `Discover` - We now pass `false` to the `allowHide` [EuiDataGrid API](https://elastic.github.io/eui/#/tabular-content/data-grid): ![allow_hide](https://user-images.githubusercontent.com/4459398/136114714-02f25b97-86af-47e5-9adc-1177d5a2c715.png) This makes all `EuiDataGrid`-based views in the Security Solution consistent with `Discover`'s use of the `EuiDataGrid` `Columns` popover. In `7.15`, the `Columns` popover includes the _hide column_ toggle, as shown in the screenshot below: ![alerts_columns_popover_7_15](https://user-images.githubusercontent.com/4459398/136112441-455ddbeb-dea3-4837-81ad-32d6c82c11fe.png) _Above: The `Columns` popover in the `7.15` `Alerts` table_ The `Columns` popover in `Discover`'s `EuiDataGrid`-based table does not display the hide column toggle, as shown the screenshot below: ![columns_popover_discover](https://user-images.githubusercontent.com/4459398/136112856-7e42c822-2260-4759-ac78-5bea63a171c7.png) _Above: The `EuiDataGrid` `Columns` popover in `Discover`, in `master`_ Passing `false` to the `allowHide` [EuiDataGrid API](https://elastic.github.io/eui/#/tabular-content/data-grid) API makes the `Columns` popover in all `EuiDataGrid`-based views in the Security Solution consistent with `Discover`, as illustrated by the screenshot below: ![alerts_columns_popover_no_hide](https://user-images.githubusercontent.com/4459398/136112980-d4219fbd-1443-4612-8cdb-b97bee8b97ef.png) _Above: The `Columns` popover is now consistent with `Discover`_ ## Changes the `Hide column` action to `Remove column`, to be consistent with `Discover` - The `Hide column` action shown in the `7.15` alerts table is changed to `Remove column`, making it consistent with `Discover`'s use of `EuiDataGrid` In `7.15`, the `Alerts` table has a `Hide column` action, as shown in the screenshot below: ![hide_column](https://user-images.githubusercontent.com/4459398/136115681-9e0da144-a981-4352-8092-9368d74cd153.png) _Above: The `Hide Column` action in the `7.15` `Alerts` table_ In `7.15`, clicking the `Hide Column` action shown in the screenshot above hides the column, but does not remove it. In `7.15`, columns may only be removed by un-checking them in the `Fields` browser, or by un-toggling them in the Alerts / Events details popover. Both of those methods require multiple clicks, and require uses to re-find the field in the modal or popover before it may be toggled for removal. In `Discover`, users don't hide columns. In `Discover`, users directly remove columns by clicking the `Remove column` action, shown in the screenshot below: ![discover_remove_column](https://user-images.githubusercontent.com/4459398/136114295-f018a561-f9ee-4ce4-a9c6-0fcd7f71e67b.png) _Above: The `Remove column` action in `Discover`'s use of `EuiDataGrid` in `master`_ All `EuiDataGrid`-based views in the Security Solution were made consistent with `Discover` by replacing the `Hide column` action with `Remove column`, per the screenshot below: ![remove_column_after](https://user-images.githubusercontent.com/4459398/137047582-3c4d6cb0-ac12-4c50-9c34-0c4ef5536550.png) _Above: The `Remove column` action in the Alerts table_ Note: the `Remove column` action shown above appears as the last item in the popover because it's specified via the `EuiDataGrid` `EuiDataGridColumnActions` > `additonal` API, which appends additonal actions to the end of popover, after the built-in actions: ![additional](https://user-images.githubusercontent.com/4459398/137047825-625002b3-5cd6-4b3e-87da-e76dbaf2a827.png) ## Persists updates to the `Columns` popover order in `local storage` - Persist column order updates to `local storage` when users update the order of columns via the `Columns` popover The following PR <#110685> restored partial support for persisting columns across page refreshes via `local storage`, but the Redux store was not updated when users sort columns via the `Columns` popover, an shown in the animated gif below: ![ordering_via_columns](https://user-images.githubusercontent.com/4459398/136119497-65f76f49-091c-4a45-b8d3-1e5ef80ccbb2.gif) _Above: Ordering via the `Columns` popover is not persisted to `local storage` in `7.15`_ This PR utilizes the `setVisibleColumns` [EuiDataGrid API](https://elastic.github.io/eui/#/tabular-content/data-grid) API as a callback to update Redux when the columns are sorted, which will in-turn update `local storage` to persist the new order across page refreshes: ![setVisibleColumns](https://user-images.githubusercontent.com/4459398/136117249-628bb147-a860-4ccf-811a-0e57a99296fb.png) ## Restores the feature to persist column widths in `local storage` In previous releases, resized column widths were peristed in `local storage` to persist across page refreshes, as documented in <#110524> : ``` { "detections-page":{ "id":"detections-page", "activeTab":"query", "prevActiveTab":"query", "columns":[ { "category":"base", "columnHeaderType":"not-filtered", "description":"Date/time when the event originated. This is the date/time extracted from the event, typically representing when the event was generated by the source. If the event source has no original timestamp, this value is typically populated by the first time the event was received by the pipeline. Required field for all events.", "example":"2016-05-23T08:05:34.853Z", "id":"@timestamp", "type":"date", "aggregatable":true, "width":190 }, { "category":"cloud", "columnHeaderType":"not-filtered", "description":"The cloud account or organization id used to identify different entities in a multi-tenant environment. Examples: AWS account id, Google Cloud ORG Id, or other unique identifier.", "example":"666777888999", "id":"cloud.account.id", "type":"string", "aggregatable":true, "width":180 }, { "category":"cloud", "columnHeaderType":"not-filtered", "description":"Availability zone in which this host is running.", "example":"us-east-1c", "id":"cloud.availability_zone", "type":"string", "aggregatable":true, "width":180 }, // ... } ], // ... } } ``` _Above: column widths were persisted to `local storage` in previous release, (going at least back to `7.12`)_ In this PR, we utilize the `onColumnResize` [EuiDataGrid API](https://elastic.github.io/eui/#/tabular-content/data-grid) API as a callback to update Redux when the columns are sorted via the `Columns` popover. Updating Redux will in-turn update `local storage`, so resized columns widths will persist across page refreshes: ![onColumnResize](https://user-images.githubusercontent.com/4459398/136120062-3b0bebce-9c44-47fc-9956-48fe07a30f83.png) ### Other changes The Alerts page `Trend` chart and table were updated to include the following additional `Stack by` fields (CC @paulewing): ``` process.name file.name hash.sha256 ``` per the before / after screenshots below: ![alerts-trend-before](https://user-images.githubusercontent.com/4459398/137045011-7da4530b-0259-4fd4-b903-9eee6c26d02f.png) _Above: The Alerts `Trend` Stack by fields in `7.15` (before)_ ![alerts-trend-after](https://user-images.githubusercontent.com/4459398/137045023-d0ae987c-a474-4123-a05b-a6ad2fc52922.png) _Above: The Alerts `Trend` `Stack by` fields (after the addition of the `process.name`, `file.name`, and `hash.sha256` fields)_ CC: @monina-n @paulewing
1 parent 3cb89f1 commit 023e5f7

File tree

17 files changed

+352
-19
lines changed

17 files changed

+352
-19
lines changed

x-pack/plugins/security_solution/public/detections/components/alerts_kpis/common/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const alertsStackByOptions: AlertsStackByOption[] = [
1919
{ text: 'signal.rule.name', value: 'signal.rule.name' },
2020
{ text: 'source.ip', value: 'source.ip' },
2121
{ text: 'user.name', value: 'user.name' },
22+
{ text: 'process.name', value: 'process.name' },
23+
{ text: 'file.name', value: 'file.name' },
24+
{ text: 'hash.sha256', value: 'hash.sha256' },
2225
];
2326

2427
export const DEFAULT_STACK_BY_FIELD = 'signal.rule.name';

x-pack/plugins/security_solution/public/detections/components/alerts_kpis/common/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ export type AlertsStackByField =
2121
| 'signal.rule.type'
2222
| 'signal.rule.name'
2323
| 'source.ip'
24-
| 'user.name';
24+
| 'user.name'
25+
| 'process.name'
26+
| 'file.name'
27+
| 'hash.sha256';

x-pack/plugins/security_solution/public/timelines/store/timeline/actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export const {
3737
setSelected,
3838
setTGridSelectAll,
3939
toggleDetailPanel,
40+
updateColumnOrder,
4041
updateColumns,
42+
updateColumnWidth,
4143
updateIsLoading,
4244
updateItemsPerPage,
4345
updateItemsPerPageOptions,

x-pack/plugins/security_solution/public/timelines/store/timeline/epic_local_storage.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import {
2525
removeColumn,
2626
upsertColumn,
2727
applyDeltaToColumnWidth,
28+
updateColumnOrder,
2829
updateColumns,
30+
updateColumnWidth,
2931
updateItemsPerPage,
3032
updateSort,
3133
} from './actions';
@@ -168,4 +170,35 @@ describe('epicLocalStorage', () => {
168170
);
169171
await waitFor(() => expect(addTimelineInStorageMock).toHaveBeenCalled());
170172
});
173+
174+
it('persists updates to the column order to local storage', async () => {
175+
shallow(
176+
<TestProviders store={store}>
177+
<QueryTabContentComponent {...props} />
178+
</TestProviders>
179+
);
180+
store.dispatch(
181+
updateColumnOrder({
182+
columnIds: ['event.severity', '@timestamp', 'event.category'],
183+
id: 'test',
184+
})
185+
);
186+
await waitFor(() => expect(addTimelineInStorageMock).toHaveBeenCalled());
187+
});
188+
189+
it('persists updates to the column width to local storage', async () => {
190+
shallow(
191+
<TestProviders store={store}>
192+
<QueryTabContentComponent {...props} />
193+
</TestProviders>
194+
);
195+
store.dispatch(
196+
updateColumnWidth({
197+
columnId: 'event.severity',
198+
id: 'test',
199+
width: 123,
200+
})
201+
);
202+
await waitFor(() => expect(addTimelineInStorageMock).toHaveBeenCalled());
203+
});
171204
});

x-pack/plugins/security_solution/public/timelines/store/timeline/epic_local_storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import {
1919
applyDeltaToColumnWidth,
2020
setExcludedRowRendererIds,
2121
updateColumns,
22+
updateColumnOrder,
23+
updateColumnWidth,
2224
updateItemsPerPage,
2325
updateSort,
2426
} from './actions';
@@ -30,6 +32,8 @@ const timelineActionTypes = [
3032
upsertColumn.type,
3133
applyDeltaToColumnWidth.type,
3234
updateColumns.type,
35+
updateColumnOrder.type,
36+
updateColumnWidth.type,
3337
updateItemsPerPage.type,
3438
updateSort.type,
3539
setExcludedRowRendererIds.type,

x-pack/plugins/timelines/public/components/t_grid/body/column_headers/column_header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ const ColumnHeaderComponent: React.FC<ColumneHeaderProps> = ({
161161
id: 0,
162162
items: [
163163
{
164-
icon: <EuiIcon type="eyeClosed" size="s" />,
165-
name: i18n.HIDE_COLUMN,
164+
icon: <EuiIcon type="cross" size="s" />,
165+
name: i18n.REMOVE_COLUMN,
166166
onClick: () => {
167167
dispatch(tGridActions.removeColumn({ id: timelineId, columnId: header.id }));
168168
handleClosePopOverTrigger();

x-pack/plugins/timelines/public/components/t_grid/body/column_headers/helpers.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe('helpers', () => {
9898
describe('getColumnHeaders', () => {
9999
// additional properties used by `EuiDataGrid`:
100100
const actions = {
101+
showHide: false,
101102
showSortAsc: true,
102103
showSortDesc: true,
103104
};

x-pack/plugins/timelines/public/components/t_grid/body/column_headers/helpers.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { allowSorting } from '../helpers';
2727
const defaultActions: EuiDataGridColumnActions = {
2828
showSortAsc: true,
2929
showSortDesc: true,
30+
showHide: false,
3031
};
3132

3233
const getAllBrowserFields = (browserFields: BrowserFields): Array<Partial<BrowserField>> =>

x-pack/plugins/timelines/public/components/t_grid/body/column_headers/translations.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export const FULL_SCREEN = i18n.translate('xpack.timelines.timeline.fullScreenBu
2323
defaultMessage: 'Full screen',
2424
});
2525

26-
export const HIDE_COLUMN = i18n.translate('xpack.timelines.timeline.hideColumnLabel', {
27-
defaultMessage: 'Hide column',
28-
});
29-
3026
export const SORT_AZ = i18n.translate('xpack.timelines.timeline.sortAZLabel', {
3127
defaultMessage: 'Sort A-Z',
3228
});

x-pack/plugins/timelines/public/components/t_grid/body/index.test.tsx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77

88
import React from 'react';
9+
import { fireEvent, render, screen } from '@testing-library/react';
910

1011
import { BodyComponent, StatefulBodyProps } from '.';
1112
import { Sort } from './sort';
13+
import { REMOVE_COLUMN } from './column_headers/translations';
1214
import { Direction } from '../../../../common/search_strategy';
1315
import { useMountAppended } from '../../utils/use_mount_appended';
1416
import { defaultHeaders, mockBrowserFields, mockTimelineData, TestProviders } from '../../../mock';
@@ -273,4 +275,57 @@ describe('Body', () => {
273275
.find((c) => c.id === 'signal.rule.risk_score')?.cellActions
274276
).toBeUndefined();
275277
});
278+
279+
test('it does NOT render switches for hiding columns in the `EuiDataGrid` `Columns` popover', async () => {
280+
render(
281+
<TestProviders>
282+
<BodyComponent {...props} />
283+
</TestProviders>
284+
);
285+
286+
// Click the `EuidDataGrid` `Columns` button to open the popover:
287+
fireEvent.click(screen.getByTestId('dataGridColumnSelectorButton'));
288+
289+
// `EuiDataGrid` renders switches for hiding in the `Columns` popover when `showColumnSelector.allowHide` is `true`
290+
const switches = await screen.queryAllByRole('switch');
291+
292+
expect(switches.length).toBe(0); // no switches are rendered, because `allowHide` is `false`
293+
});
294+
295+
test('it dispatches the `REMOVE_COLUMN` action when a user clicks `Remove column` in the column header popover', async () => {
296+
render(
297+
<TestProviders>
298+
<BodyComponent {...props} />
299+
</TestProviders>
300+
);
301+
302+
// click the `@timestamp` column header to display the popover
303+
fireEvent.click(screen.getByText('@timestamp'));
304+
305+
// click the `Remove column` action in the popover
306+
fireEvent.click(await screen.getByText(REMOVE_COLUMN));
307+
308+
expect(mockDispatch).toBeCalledWith({
309+
payload: { columnId: '@timestamp', id: 'timeline-test' },
310+
type: 'x-pack/timelines/t-grid/REMOVE_COLUMN',
311+
});
312+
});
313+
314+
test('it dispatches the `UPDATE_COLUMN_WIDTH` action when a user resizes a column', async () => {
315+
render(
316+
<TestProviders>
317+
<BodyComponent {...props} />
318+
</TestProviders>
319+
);
320+
321+
// simulate resizing the column
322+
fireEvent.mouseDown(screen.getAllByTestId('dataGridColumnResizer')[0]);
323+
fireEvent.mouseMove(screen.getAllByTestId('dataGridColumnResizer')[0]);
324+
fireEvent.mouseUp(screen.getAllByTestId('dataGridColumnResizer')[0]);
325+
326+
expect(mockDispatch).toBeCalledWith({
327+
payload: { columnId: '@timestamp', id: 'timeline-test', width: NaN },
328+
type: 'x-pack/timelines/t-grid/UPDATE_COLUMN_WIDTH',
329+
});
330+
});
276331
});

0 commit comments

Comments
 (0)