feat(ColumnManagementModal): add support for extended columns#929
feat(ColumnManagementModal): add support for extended columns#929raswonders wants to merge 4 commits into
Conversation
karelhala
left a comment
There was a problem hiding this comment.
Nice work overall — clean generic approach, backward compatible, and well-tested. A couple of suggestions below to strengthen the test coverage and make the feature more discoverable.
| saved.forEach((col) => { | ||
| const source = EXTENDED_COLUMNS.find((aec) => aec.key === col.key); | ||
| expect(source?.dataKey).toBe(col.dataKey); | ||
| }); |
There was a problem hiding this comment.
Suggestion: Consider replacing the forEach + individual expect with a single toEqual assertion. This is more robust — it would also catch unexpected property mutations or additions on the base fields, not just verify that dataKey survived:
expect(saved).toEqual(
EXTENDED_COLUMNS.map((col) => ({
...col,
isShown: col.key === 'impact' ? !col.isShownByDefault : col.isShownByDefault
}))
);This covers the full shape of every column in one shot.
| expect(source?.dataKey).toBe(col.dataKey); | ||
| }); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Suggestion: Would be good to also add a test for enableDragDrop={true} combined with extended columns — verifying that reordering + save still preserves the extra fields. The existing drag-drop tests only use DEFAULT_COLUMNS (base type), so the combination is currently untested.
Something like:
it('should preserve extended column fields after drag-drop reorder and save', () => {
const applyColumnsMock = jest.fn();
const reorderedExtended: ExtendedColumn[] = [
EXTENDED_COLUMNS[3],
EXTENDED_COLUMNS[0],
EXTENDED_COLUMNS[2],
EXTENDED_COLUMNS[1]
];
render(
<ColumnManagementModal<ExtendedColumn>
appliedColumns={reorderedExtended}
applyColumns={applyColumnsMock}
enableDragDrop
isOpen
onClose={onClose}
/>
);
// reset + save triggers applyColumns
const resetButtons = screen.getAllByText('Reset to default');
fireEvent.click(resetButtons[resetButtons.length - 1]);
fireEvent.click(screen.getAllByText('Save').pop()!);
const saved = applyColumnsMock.mock.calls[0][0] as ExtendedColumn[];
saved.forEach((col) => {
expect(col.dataKey).toBeDefined();
});
});|
Documentation suggestion: This generic column support is a great feature for consumers — it would be worth adding a documentation example showing the generic usage pattern. Something like: interface MyColumn extends ColumnManagementModalColumn {
dataKey: string;
sortable?: boolean;
}
const columns: MyColumn[] = [
{ key: 'name', title: 'Name', isShownByDefault: true, dataKey: 'user.name', sortable: true },
{ key: 'email', title: 'Email', isShownByDefault: true, dataKey: 'user.email' },
// ...
];
<ColumnManagementModal<MyColumn>
appliedColumns={columns}
applyColumns={(updated) => {
// `updated` is MyColumn[] — dataKey, sortable, etc. are preserved
setColumns(updated);
}}
isOpen={isOpen}
onClose={handleClose}
/>Without a docs example, consumers might not discover that the component now supports generics and continue maintaining two parallel column structures (which is the exact pain point this PR fixes). Would you be open to adding this to the component's example/demo page? |
nicolethoen
left a comment
There was a problem hiding this comment.
+1 Karel's notes
LGTM otherwise
Hey,
I've extended Modal so it supports subtype of ColumnManagementModalColumn, once this is applied we'll be able to pass in our custom Column type which extends ColumnManagementModalColumn and get the same custom columns back.
What this PR do?
ColumnManagementModal now fully works with custom shape columns which are subtype of ColumnManagementModalColumn
Why we need this?
How we are fixing it?
API compatibilty concerns