Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BD-46] fix: fixed the Select all button in the DataTable component #2929

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/DataTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function DataTable({

const enhancedInstance = {
...instance,
manualFilters,
itemCount,
numBreakoutFilters,
bulkActions,
Expand Down
4 changes: 2 additions & 2 deletions src/DataTable/selection/BaseSelectionStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ function BaseSelectionStatus({
}) {
const {
itemCount, filteredRows, isPaginated, state,
isSelectable, maxSelectedRows,
isSelectable, maxSelectedRows, manualFilters,
} = useContext(DataTableContext);
const hasAppliedFilters = state?.filters?.length > 0;
const isAllRowsSelected = numSelectedRows === itemCount;
const filteredItems = filteredRows?.length || itemCount;
const filteredItems = manualFilters ? itemCount : (filteredRows?.length || itemCount);
const hasMaxSelectedRows = isSelectable && maxSelectedRows;

const intlAllSelectedText = allSelectedText || (
Expand Down
31 changes: 31 additions & 0 deletions src/DataTable/tests/DataTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IntlProvider } from 'react-intl';

import DataTable from '..';
import DataTableContext from '../DataTableContext';
import { TextFilter } from '../..';
import { SELECT_ALL_TEST_ID } from '../selection/data/constants';

const additionalColumns = [
{
Expand Down Expand Up @@ -198,6 +200,35 @@ describe('<DataTable />', () => {

expect(spinner).toBeTruthy();
});
it('displays the total number of items when applying filter and selecting all items', async () => {
const propsWithSelection = {
...props,
isSelectable: true,
isFilterable: true,
manualFilters: true,
defaultColumnValues: { Filter: TextFilter },
isPaginated: true,
initialState: { pageSize: 3, pageIndex: 0 },
pageCount: 3,
fetchData: jest.fn(),
};

render(<DataTableWrapper {...propsWithSelection} />);
const filtersButton = screen.getByRole('button', { name: 'Filters' });

await userEvent.click(filtersButton);

const searchFormControl = screen.getByPlaceholderText('Search coat color');
await userEvent.type(searchFormControl, 'brown tabby');

const selectAllCheckBox = screen.getByTitle('Toggle All Current Page Rows Selected');
await userEvent.click(selectAllCheckBox);

const selectAllButton = screen.getByTestId(SELECT_ALL_TEST_ID);
// A filtered array is returned from the backend,
// and the element counter displays its length.
expect(selectAllButton).toHaveTextContent('Select all 7');
});

describe('[legacy] controlled table selections', () => {
it('passes initial controlledTableSelections to context', async () => {
Expand Down