-
Notifications
You must be signed in to change notification settings - Fork 858
[EuiDataGrid] Fix cell props not clearing state on column reorder #5068
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
Changes from all commits
262ed15
69f815a
605850b
318dcd5
dddeb3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1467,6 +1467,48 @@ describe('EuiDataGrid', () => { | |
| ['1-ColumnB', '1-ColumnA'], | ||
| ]); | ||
| }); | ||
|
|
||
| it('resets cell props on column reorder', () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chandlerprall requested a unit test for this in Slack! This is mostly a direct copy/paste of the above column order test in terms of setup (but with 1 less row and I also ran this test on master and can confirm it fails there but passes on this branch.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm in favor of verbose testing 👍 |
||
| const columnVisibility = { | ||
| visibleColumns: ['ColumnA', 'ColumnB'], | ||
| setVisibleColumns: (visibleColumns: string[]) => { | ||
| columnVisibility.visibleColumns = visibleColumns; | ||
| component.setProps({ columnVisibility }); | ||
| }, | ||
| }; | ||
|
|
||
| const component = mount( | ||
| <EuiDataGrid | ||
| aria-labelledby="#test" | ||
| columns={[{ id: 'ColumnA' }, { id: 'ColumnB' }]} | ||
| columnVisibility={columnVisibility} | ||
| rowCount={1} | ||
| renderCellValue={({ rowIndex, columnId, setCellProps }) => { | ||
| useEffect(() => { | ||
| if (columnId === 'ColumnB') { | ||
| setCellProps({ style: { color: 'blue' } }); | ||
| } | ||
| }, [columnId, rowIndex, setCellProps]); | ||
|
|
||
| return `${rowIndex}-${columnId}`; | ||
| }} | ||
| /> | ||
| ); | ||
|
|
||
| const getCellColorAt = (index: number) => | ||
| component | ||
| .find('[data-test-subj="dataGridRowCell"]') | ||
| .at(index) | ||
| .prop('style')?.color; | ||
|
|
||
| expect(getCellColorAt(0)).toEqual(undefined); | ||
| expect(getCellColorAt(1)).toEqual('blue'); | ||
|
|
||
| moveColumnToIndex(component, 'B', 0); | ||
|
|
||
| expect(getCellColorAt(0)).toEqual('blue'); | ||
| expect(getCellColorAt(1)).toEqual(undefined); | ||
| }); | ||
| }); | ||
|
|
||
| describe('column sorting', () => { | ||
|
|
@@ -2171,7 +2213,7 @@ describe('EuiDataGrid', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('rowHeighsOptions', () => { | ||
| describe('rowHeightsOptions', () => { | ||
| it('all row heights options applied correctly', async () => { | ||
| const component = mount( | ||
| <EuiDataGrid | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you have a preferred/cleaner approach of solving this issue! I'm not in love with this or anything, although it seemed like the most straightforward solution - but I could be definitely missing something or an edge case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. @chandlerprall can chime in if he has other thoughts, though.