Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SecuritySolution] Fix issue of disappearing columns in the alerts table #197043

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<AlertsTableWithProviders
{...tableProps}
toolbarVisibility={{
showColumnSelector: true,
}}
initialBulkActionsState={{
...defaultBulkActionsState,
rowSelection: new Map(),
}}
/>
);

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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ const AlertsTable: React.FunctionComponent<AlertsTableProps> = memo((props: Aler
rowSelection: bulkActionsState.rowSelection,
alerts,
isLoading,
columnIds: visibleColumns,
columnIds: columns.map((column) => column.id),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a test to ensure it doesn't happen again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I asked for help from your team on this above:

@elastic/response-ops Got any ideas on how to best add unit tests for this?

Testing this isn't straight forward, at least not to me since I'm not familiar with the whole testing architecture around the alerts table. I would greatly appreciate your input here :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed the message.

Maybe a test that updates the browserField prop using rtl's rerender method in x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_table/alerts_table.test.tsx ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcger Wdyt about 25b3a21 ?

onToggleColumn,
onResetColumns,
browserFields,
Expand All @@ -431,7 +431,7 @@ const AlertsTable: React.FunctionComponent<AlertsTableProps> = memo((props: Aler
alertsCount,
bulkActionsState,
isLoading,
visibleColumns,
columns,
onToggleColumn,
onResetColumns,
browserFields,
Expand Down