From 62c45ee45a6e622cca5dda5ab0f79fb28a9eba0c Mon Sep 17 00:00:00 2001 From: Diana Derevyankina Date: Thu, 15 Oct 2020 11:38:13 +0300 Subject: [PATCH 1/3] [EuiInMemoryTable] Error appears in console related to prop `sorting.sort.direction` Closes #4137 --- src/components/basic_table/in_memory_table.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/basic_table/in_memory_table.tsx b/src/components/basic_table/in_memory_table.tsx index 4f21e6ac37e..babde889835 100644 --- a/src/components/basic_table/in_memory_table.tsx +++ b/src/components/basic_table/in_memory_table.tsx @@ -410,7 +410,8 @@ 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) { + const columnField = (column as EuiTableFieldDataColumnType).field; + if (columnField && columnField === sortName) { sortName = column.name as keyof T; break; } From 79349c8c395dd9db76e7e54071b0af1238f942eb Mon Sep 17 00:00:00 2001 From: Diana Derevyankina Date: Thu, 15 Oct 2020 13:53:49 +0300 Subject: [PATCH 2/3] Add descrition to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52e4b5db794..18d4fcea647 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed custom color render of `EuiIcon` app (two-tone) icons ([#4104](https://github.com/elastic/eui/pull/4104)) - Changed `iconType` prop to be `required` in `EuiButtonIcon` ([#4106](https://github.com/elastic/eui/pull/4106)) +- Fixed a condition in `EuiInMemoryTable` to avoid mistaken assignment of `sortName` ([#4138](https://github.com/elastic/eui/pull/4138)) ## [`29.4.0`](https://github.com/elastic/eui/tree/v29.4.0) From aa3b4afa9c2b537b483f93a02af11c2e824be0fc Mon Sep 17 00:00:00 2001 From: Diana Derevyankina Date: Tue, 3 Nov 2020 20:07:24 +0300 Subject: [PATCH 3/3] Replace columnField with type guard for field and create a unit test for that case --- .../basic_table/in_memory_table.test.tsx | 27 +++++++++++++++++++ .../basic_table/in_memory_table.tsx | 6 +++-- 2 files changed, 31 insertions(+), 2 deletions(-) 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 affbd0a4779..6c7cc1bc2bc 100644 --- a/src/components/basic_table/in_memory_table.tsx +++ b/src/components/basic_table/in_memory_table.tsx @@ -416,8 +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]; - const columnField = (column as EuiTableFieldDataColumnType).field; - if (columnField && columnField === sortName) { + if ( + 'field' in column && + (column as EuiTableFieldDataColumnType).field === sortName + ) { sortName = column.name as keyof T; break; }