From bb60ea610770fde70de34b3b2a2584d6b1836caa Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:57:03 +1100 Subject: [PATCH] [8.16] [SecuritySolution] Fix issue of disappearing columns in the alerts table (#197043) (#197624) # Backport This will backport the following commits from `main` to `8.16`: - [[SecuritySolution] Fix issue of disappearing columns in the alerts table (#197043)](https://github.com/elastic/kibana/pull/197043) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Jan Monschke --- .../alerts_table/alerts_table.test.tsx | 36 +++++++++++++++++++ .../sections/alerts_table/alerts_table.tsx | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.test.tsx index d410e8ee9d43e..bcd9026992d15 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.test.tsx @@ -694,6 +694,42 @@ describe('AlertsTable', () => { expect(await screen.findByTestId(TEST_ID.FIELD_BROWSER_CUSTOM_CREATE_BTN)).toBeVisible(); }); + + it('The column state is synced correctly between the column selector and the field selector', async () => { + const columnToHide = tableProps.columns[0]; + render( + + ); + + const fieldBrowserBtn = await screen.findByTestId(TEST_ID.FIELD_BROWSER_BTN); + const columnSelectorBtn = await screen.findByTestId('dataGridColumnSelectorButton'); + + // Open the column visibility selector and hide the column + fireEvent.click(columnSelectorBtn); + const columnVisibilityToggle = await screen.findByTestId( + `dataGridColumnSelectorToggleColumnVisibility-${columnToHide.id}` + ); + fireEvent.click(columnVisibilityToggle); + + // Open the field browser + fireEvent.click(fieldBrowserBtn); + expect(await screen.findByTestId(TEST_ID.FIELD_BROWSER)).toBeVisible(); + + // The column should be checked in the field browser, independent of its visibility status + const columnCheckbox: HTMLInputElement = await screen.findByTestId( + `field-${columnToHide.id}-checkbox` + ); + expect(columnCheckbox).toBeChecked(); + }); }); describe('cases column', () => { diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.tsx index 617b0f9c70a0a..61c65eded27b5 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.tsx @@ -413,7 +413,7 @@ const AlertsTable: React.FunctionComponent = memo((props: Aler rowSelection: bulkActionsState.rowSelection, alerts, isLoading, - columnIds: visibleColumns, + columnIds: columns.map((column) => column.id), onToggleColumn, onResetColumns, browserFields, @@ -431,7 +431,7 @@ const AlertsTable: React.FunctionComponent = memo((props: Aler alertsCount, bulkActionsState, isLoading, - visibleColumns, + columns, onToggleColumn, onResetColumns, browserFields,