Skip to content

Commit

Permalink
[EuiInMemoryTable] Error appears in console related to prop `sorting.…
Browse files Browse the repository at this point in the history
…sort.direction` (#4138)

* [EuiInMemoryTable] Error appears in console related to prop `sorting.sort.direction`

Closes #4137

* Add descrition to CHANGELOG

* Replace columnField with type guard for field and create a unit test for that case

Co-authored-by: Chandler Prall <[email protected]>
  • Loading branch information
DianaDerevyankina and chandlerprall authored Nov 4, 2020
1 parent fa35276 commit 018cb98
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `30.2.0`.
**Bug fixes**

- Fixed a condition in `EuiInMemoryTable` to avoid mistaken assignment of `sortName` ([#4138](https://github.com/elastic/eui/pull/4138))

## [`30.2.0`](https://github.com/elastic/eui/tree/v30.2.0)

Expand Down
27 changes: 27 additions & 0 deletions src/components/basic_table/in_memory_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,33 @@ describe('EuiInMemoryTable', () => {
expect(component).toMatchSnapshot();
});

test('pagination with actions column and sorting set to true', async () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
items: [
{ id: '1', name: 'name1' },
{ id: '2', name: 'name2' },
{ id: '3', name: 'name3' },
{ id: '4', name: 'name4' },
],
columns: [
{
name: 'Actions',
actions: [],
},
],
sorting: true,
pagination: {
pageSizeOptions: [2, 4, 6],
},
};
const component = mount(<EuiInMemoryTable {...props} />);

component
.find('EuiButtonEmpty[data-test-subj="pagination-button-1"]')
.simulate('click');
});

test('onTableChange callback', () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
Expand Down
5 changes: 4 additions & 1 deletion src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ export class EuiInMemoryTable<T> extends Component<
// map back to `name` if this is the case
for (let i = 0; i < this.props.columns.length; i++) {
const column = this.props.columns[i];
if ((column as EuiTableFieldDataColumnType<T>).field === sortName) {
if (
'field' in column &&
(column as EuiTableFieldDataColumnType<T>).field === sortName
) {
sortName = column.name as keyof T;
break;
}
Expand Down

0 comments on commit 018cb98

Please sign in to comment.