Skip to content

Commit

Permalink
[Security Solution] Fix broken columns reset in alerts table (elastic…
Browse files Browse the repository at this point in the history
…#177986)

## Summary

This fixes elastic#173241
  • Loading branch information
lgestc authored Mar 7, 2024
1 parent d21bfbf commit b21fd49
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,42 @@ describe('useColumn', () => {
);
});
});

describe('onResetColumns', () => {
test('should restore visible columns defaults', () => {
const localStorageAlertsTable = getStorageAlertsTableByDefaultColumns(defaultColumns);
const { result } = renderHook<UseColumnsArgs, UseColumnsResp>(() =>
useColumns({
defaultColumns,
featureIds,
id,
storageAlertsTable: localStorageAlertsTable,
storage,
})
);

expect(result.current.visibleColumns).toEqual([
'event.action',
'@timestamp',
'kibana.alert.duration.us',
'kibana.alert.reason',
]);

act(() => {
result.current.onToggleColumn(defaultColumns[0].id);
});
expect(result.current.visibleColumns).not.toContain(['event.action']);

act(() => {
result.current.onResetColumns();
});

expect(result.current.visibleColumns).toEqual([
'event.action',
'@timestamp',
'kibana.alert.duration.us',
'kibana.alert.reason',
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,9 @@ export const useColumns = ({

const onResetColumns = useCallback(() => {
const populatedDefaultColumns = populateColumns(defaultColumns, browserFields, defaultColumns);
setColumnsAndSave(
populatedDefaultColumns,
populatedDefaultColumns.map((pdc) => pdc.id)
);
const newVisibleColumns = populatedDefaultColumns.map((pdc) => pdc.id);
setVisibleColumns(newVisibleColumns);
setColumnsAndSave(populatedDefaultColumns, newVisibleColumns);
}, [browserFields, defaultColumns, setColumnsAndSave]);

const onColumnResize = useCallback(
Expand Down

0 comments on commit b21fd49

Please sign in to comment.