From 018cb984a90f3b1d3a104b8e477962db3ef02306 Mon Sep 17 00:00:00 2001 From: Diana Derevyankina <54894989+DziyanaDzeraviankina@users.noreply.github.com> Date: Wed, 4 Nov 2020 20:03:34 +0300 Subject: [PATCH] [EuiInMemoryTable] Error appears in console related to prop `sorting.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 --- CHANGELOG.md | 4 ++- .../basic_table/in_memory_table.test.tsx | 27 +++++++++++++++++++ .../basic_table/in_memory_table.tsx | 5 +++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e8f6411028..92ec1c78652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/components/basic_table/in_memory_table.test.tsx b/src/components/basic_table/in_memory_table.test.tsx index 0c2512c5ae8..fe66b22edbb 100644 --- a/src/components/basic_table/in_memory_table.test.tsx +++ b/src/components/basic_table/in_memory_table.test.tsx @@ -978,6 +978,33 @@ describe('EuiInMemoryTable', () => { expect(component).toMatchSnapshot(); }); + test('pagination with actions column and sorting set to true', async () => { + const props: EuiInMemoryTableProps = { + ...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(); + + component + .find('EuiButtonEmpty[data-test-subj="pagination-button-1"]') + .simulate('click'); + }); + test('onTableChange callback', () => { const props: EuiInMemoryTableProps = { ...requiredProps, diff --git a/src/components/basic_table/in_memory_table.tsx b/src/components/basic_table/in_memory_table.tsx index 2c11b8f0495..6c7cc1bc2bc 100644 --- a/src/components/basic_table/in_memory_table.tsx +++ b/src/components/basic_table/in_memory_table.tsx @@ -416,7 +416,10 @@ export class EuiInMemoryTable 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).field === sortName) { + if ( + 'field' in column && + (column as EuiTableFieldDataColumnType).field === sortName + ) { sortName = column.name as keyof T; break; }