Skip to content

Commit

Permalink
[EuiBasicTable][EuiInMemoryTable] Remove deprecated internal `setSele…
Browse files Browse the repository at this point in the history
…ction` class methods (#7491)
  • Loading branch information
cee-chen authored Feb 2, 2024
1 parent 3a257ad commit f67f5f0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 46 deletions.
3 changes: 3 additions & 0 deletions changelogs/upcoming/7491.md
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 0 additions & 29 deletions src/components/basic_table/basic_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
<EuiBasicTable
{...props}
ref={(ref) => {
classRef = ref;
}}
/>
);
expect(getCheckboxAt(1).checked).toBeFalsy();

act(() => {
classRef!.setSelection([basicItems[0]]);
});
expect(getCheckboxAt(1).checked).toBeTruthy();
});
});

test('footers', () => {
Expand Down
7 changes: 0 additions & 7 deletions src/components/basic_table/basic_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,6 @@ export class EuiBasicTable<T extends object = any> extends Component<
}
}

/**
* @deprecated Use `selection.selected` instead to declaratively control table selection
*/
setSelection(newSelection: T[]) {
this.changeSelection(newSelection);
}

buildCriteria(props: EuiBasicTableProps<T>): Criteria<T> {
const criteria: Criteria<T> = {};
if (hasPagination(props)) {
Expand Down
10 changes: 0 additions & 10 deletions src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ export class EuiInMemoryTable<T extends object = object> extends Component<
tableLayout: 'fixed',
searchFormat: 'eql',
};
tableRef: React.RefObject<EuiBasicTable>;

static getDerivedStateFromProps<T extends object>(
nextProps: EuiInMemoryTableProps<T>,
Expand Down Expand Up @@ -424,14 +423,6 @@ export class EuiInMemoryTable<T extends object = object> extends Component<
allowNeutralSort: allowNeutralSort !== false,
showPerPageOptions,
};

this.tableRef = React.createRef<EuiBasicTable>();
}

setSelection(newSelection: T[]) {
if (this.tableRef.current) {
this.tableRef.current.setSelection(newSelection);
}
}

onTableChange = ({ page, sort }: Criteria<T>) => {
Expand Down Expand Up @@ -749,7 +740,6 @@ export class EuiInMemoryTable<T extends object = object> extends Component<
const table = (
// @ts-ignore complex relationship between pagination's existence and criteria, the code logic ensures this is correctly maintained
<EuiBasicTable
ref={this.tableRef}
items={items}
itemId={itemId}
rowProps={rowProps}
Expand Down

0 comments on commit f67f5f0

Please sign in to comment.