From 4171c9b8229e497a79c3ad0ced5e035944f2c159 Mon Sep 17 00:00:00 2001 From: Julian Gernun <17549662+jcger@users.noreply.github.com> Date: Wed, 3 May 2023 17:30:14 +0200 Subject: [PATCH] [RAM] Alerts Table breaking when adding first column in fields browser (#156557) Fixes https://github.com/elastic/kibana/issues/156001 --- .../hooks/use_columns/toggle_column.test.tsx | 17 +++++++++++++++++ .../hooks/use_columns/toggle_column.ts | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.test.tsx index cf3e774d2d7173..df1f2b79c5eb00 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.test.tsx @@ -47,4 +47,21 @@ describe('toggleColumn', () => { ] `); }); + + it('adds a column even if no column is currently shown', async () => { + expect( + toggleColumn({ + column: { id: '_id', schema: 'string' }, + columns: [], + defaultColumns: [], + }) + ).toMatchInlineSnapshot(` + Array [ + Object { + "id": "_id", + "schema": "string", + }, + ] + `); + }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.ts b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.ts index 8769fc956365e8..dd783991be409a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/hooks/use_columns/toggle_column.ts @@ -33,6 +33,10 @@ const insert = ({ return [...columns.slice(0, defaultIndex), column, ...columns.slice(defaultIndex)]; } + if (columns.length === 0) { + return [column]; + } + // if the column isn't shown and it's not part of the default config // push it into the second position. Behaviour copied by t_grid, security // does this to insert right after the timestamp column