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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed missing i18n token `EuiFilePicker`'s default prompt, and improved i18n string for `euiFilePicker.filesSelected` ([#5063](https://github.com/elastic/eui/pull/5063))
- Fixed `EuiDataGrid` sort button text pluralization ([#5043](https://github.com/elastic/eui/pull/5043))
- Fixed styles of `EuiButtonIcon` when passing `disabled` prop ([#5060](https://github.com/elastic/eui/pull/5060))
- Fixed `EuiDataGrid` not clearing cell styles when column position changes ([#5068](https://github.com/elastic/eui/issues/5068))

**Theme: Amsterdam**

Expand Down
6 changes: 6 additions & 0 deletions src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ export class EuiDataGridCell extends Component<
return false;
}

componentDidUpdate(prevProps: EuiDataGridCellProps) {
if (this.props.columnId !== prevProps.columnId) {
this.setCellProps({});
}
}
Comment on lines +254 to +258
Copy link
Contributor Author

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.

Copy link
Contributor

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.


setCellProps = (cellProps: HTMLAttributes<HTMLDivElement>) => {
this.setState({ cellProps });
};
Expand Down
44 changes: 43 additions & 1 deletion src/components/datagrid/data_grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,48 @@ describe('EuiDataGrid', () => {
['1-ColumnB', '1-ColumnA'],
]);
});

it('resets cell props on column reorder', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 setCellProps in renderCellValue). I'm not sure if there's any DRYing out I should be doing between the 2 reorder unit tests - happy to do so if requested.

I also ran this test on master and can confirm it fails there but passes on this branch.

Copy link
Contributor

Choose a reason for hiding this comment

The 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', () => {
Expand Down Expand Up @@ -2171,7 +2213,7 @@ describe('EuiDataGrid', () => {
});
});

describe('rowHeighsOptions', () => {
describe('rowHeightsOptions', () => {
it('all row heights options applied correctly', async () => {
const component = mount(
<EuiDataGrid
Expand Down