From f67f5f0929c3f191ce57b1ebd79f15c798adcb9c Mon Sep 17 00:00:00 2001 From: Cee Chen <549407+cee-chen@users.noreply.github.com> Date: Fri, 2 Feb 2024 09:52:02 -0800 Subject: [PATCH] [EuiBasicTable][EuiInMemoryTable] Remove deprecated internal `setSelection` class methods (#7491) --- changelogs/upcoming/7491.md | 3 ++ .../basic_table/basic_table.test.tsx | 29 ------------------- src/components/basic_table/basic_table.tsx | 7 ----- .../basic_table/in_memory_table.tsx | 10 ------- 4 files changed, 3 insertions(+), 46 deletions(-) create mode 100644 changelogs/upcoming/7491.md diff --git a/changelogs/upcoming/7491.md b/changelogs/upcoming/7491.md new file mode 100644 index 00000000000..85a4d9a776d --- /dev/null +++ b/changelogs/upcoming/7491.md @@ -0,0 +1,3 @@ +**Breaking changes** + +- Removed deprecated internal `setSelection` ref method from `EuiInMemoryTable` and `EuiBasicTable`. Use the new controlled `selection.selected` prop API instead. diff --git a/src/components/basic_table/basic_table.test.tsx b/src/components/basic_table/basic_table.test.tsx index 3828a0c34ce..bf9513474ff 100644 --- a/src/components/basic_table/basic_table.test.tsx +++ b/src/components/basic_table/basic_table.test.tsx @@ -7,7 +7,6 @@ */ import React from 'react'; -import { act } from '@testing-library/react'; import { render, screen } from '../../test/rtl'; import { requiredProps } from '../../test'; import { shouldRenderCustomStyles } from '../../test/internal'; @@ -463,34 +462,6 @@ describe('EuiBasicTable', () => { expect(onSelectionChange).toHaveBeenCalledWith([]); expect(container.querySelectorAll('[checked]')).toHaveLength(0); }); - - // TODO: Delete this test once deprecated API is removed - test('deprecated setSelection ref API', () => { - const props = { - items: basicItems, - columns: basicColumns, - itemId: 'id', - selection: { - onSelectionChange: () => {}, - }, - }; - - let classRef: EuiBasicTable | null; - render( - { - classRef = ref; - }} - /> - ); - expect(getCheckboxAt(1).checked).toBeFalsy(); - - act(() => { - classRef!.setSelection([basicItems[0]]); - }); - expect(getCheckboxAt(1).checked).toBeTruthy(); - }); }); test('footers', () => { diff --git a/src/components/basic_table/basic_table.tsx b/src/components/basic_table/basic_table.tsx index c917a890afb..18ef806dbf6 100644 --- a/src/components/basic_table/basic_table.tsx +++ b/src/components/basic_table/basic_table.tsx @@ -417,13 +417,6 @@ export class EuiBasicTable extends Component< } } - /** - * @deprecated Use `selection.selected` instead to declaratively control table selection - */ - setSelection(newSelection: T[]) { - this.changeSelection(newSelection); - } - buildCriteria(props: EuiBasicTableProps): Criteria { const criteria: Criteria = {}; if (hasPagination(props)) { diff --git a/src/components/basic_table/in_memory_table.tsx b/src/components/basic_table/in_memory_table.tsx index 833cb8e1de8..a1c63ff2d25 100644 --- a/src/components/basic_table/in_memory_table.tsx +++ b/src/components/basic_table/in_memory_table.tsx @@ -303,7 +303,6 @@ export class EuiInMemoryTable extends Component< tableLayout: 'fixed', searchFormat: 'eql', }; - tableRef: React.RefObject; static getDerivedStateFromProps( nextProps: EuiInMemoryTableProps, @@ -424,14 +423,6 @@ export class EuiInMemoryTable extends Component< allowNeutralSort: allowNeutralSort !== false, showPerPageOptions, }; - - this.tableRef = React.createRef(); - } - - setSelection(newSelection: T[]) { - if (this.tableRef.current) { - this.tableRef.current.setSelection(newSelection); - } } onTableChange = ({ page, sort }: Criteria) => { @@ -749,7 +740,6 @@ export class EuiInMemoryTable extends Component< const table = ( // @ts-ignore complex relationship between pagination's existence and criteria, the code logic ensures this is correctly maintained