Skip to content
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 @@ -6,7 +6,7 @@
*/

import type { SecurityAppStore } from '../../../../common/store/types';
import { TableId, dataTableActions } from '@kbn/securitysolution-data-table';
import { dataTableActions, TableId } from '@kbn/securitysolution-data-table';
import type { CellActionExecutionContext } from '@kbn/cell-actions';

import { createToggleColumnCellActionFactory } from './toggle_column';
Expand Down Expand Up @@ -79,6 +79,7 @@ describe('createToggleColumnCellActionFactory', () => {
afterEach(() => {
mockToggleColumn.mockClear();
});

it('should remove column', async () => {
await toggleColumnAction.execute(context);
expect(mockDispatch).toHaveBeenCalledWith(
Expand Down Expand Up @@ -108,32 +109,46 @@ describe('createToggleColumnCellActionFactory', () => {
);
});

it('should call toggleColumn on the visible alerts table to add a column in alert', async () => {
const name = 'fake-field-name';
await toggleColumnAction.execute({
...context,
data: [{ ...context.data[0], field: { ...context.data[0].field, name } }],
metadata: {
scopeId: TableId.alertsOnAlertsPage,
alertsTableRef: {
current: { toggleColumn: mockToggleColumn } as unknown as AlertsTableImperativeApi,
[
TableId.alertsOnAlertsPage,
TableId.alertsOnCasePage,
TableId.alertsOnRuleDetailsPage,
TableId.alertsRiskInputs,
].forEach((scopeId) => {
it(`should call toggleColumn on the visible alerts table to add a column in alert for TableId ${scopeId}`, async () => {
const name = 'fake-field-name';
await toggleColumnAction.execute({
...context,
data: [{ ...context.data[0], field: { ...context.data[0].field, name } }],
metadata: {
scopeId,
alertsTableRef: {
current: { toggleColumn: mockToggleColumn } as unknown as AlertsTableImperativeApi,
},
},
},
});
expect(mockToggleColumn).toHaveBeenCalledWith(name);
});
expect(mockToggleColumn).toHaveBeenCalledWith(name);
});

it('should call toggleColumn on the visible alerts table to remove a column in alert', async () => {
await toggleColumnAction.execute({
...context,
metadata: {
scopeId: TableId.alertsOnAlertsPage,
alertsTableRef: {
current: { toggleColumn: mockToggleColumn } as unknown as AlertsTableImperativeApi,
[
TableId.alertsOnAlertsPage,
TableId.alertsOnCasePage,
TableId.alertsOnRuleDetailsPage,
TableId.alertsRiskInputs,
].forEach((scopeId) => {
it(`should call toggleColumn on the visible alerts table to remove a column in alert for TableId ${scopeId}`, async () => {
await toggleColumnAction.execute({
...context,
metadata: {
scopeId: TableId.alertsOnAlertsPage,
alertsTableRef: {
current: { toggleColumn: mockToggleColumn } as unknown as AlertsTableImperativeApi,
},
},
},
});
expect(mockToggleColumn).toHaveBeenCalledWith(fieldName);
});
expect(mockToggleColumn).toHaveBeenCalledWith(fieldName);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import { i18n } from '@kbn/i18n';
import { createCellActionFactory, type CellActionTemplate } from '@kbn/cell-actions/actions';
import { type CellActionTemplate, createCellActionFactory } from '@kbn/cell-actions/actions';
import {
dataTableSelectors,
defaultColumnHeaderType,
tableDefaults,
dataTableSelectors,
TableId,
} from '@kbn/securitysolution-data-table';
import { fieldHasCellActions } from '../../utils';
import type { SecurityAppStore } from '../../../../common/store';
Expand Down Expand Up @@ -69,11 +68,12 @@ export const createToggleColumnCellActionFactory = createCellActionFactory(
}

// When the flyout was initiated from an alerts table, use its toggleColumn action
if (metadata.alertsTableRef?.current && scopeId === TableId.alertsOnAlertsPage) {
// We can safely do this now as we do not have a page with multiple alerts tables. If that were the case we'd have problem with the ref
if (metadata.alertsTableRef?.current) {
metadata.alertsTableRef.current.toggleColumn(field.name);
return;
}

// Otherwise, use the store to dispatch the action, either for Timeline or the events table in the Explore pages
const selector = isTimelineScope(scopeId)
? timelineSelectors.getTimelineByIdSelector()
: dataTableSelectors.getTableByIdSelector();
Expand Down