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

sync: master to alpha #2207

Merged
merged 1 commit into from
Apr 21, 2023
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
8 changes: 6 additions & 2 deletions src/DataTable/selection/BaseSelectionStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ function BaseSelectionStatus({
allSelectedText,
selectedText,
}) {
const { itemCount, isPaginated, state } = useContext(DataTableContext);
const {
itemCount, filteredRows, isPaginated, state,
} = useContext(DataTableContext);
const hasAppliedFilters = state?.filters?.length > 0;
const isAllRowsSelected = numSelectedRows === itemCount;
const filteredItems = filteredRows?.length || itemCount;

const intlAllSelectedText = allSelectedText || (
<FormattedMessage
id="pgn.DataTable.BaseSelectionStatus.allSelectedText"
Expand Down Expand Up @@ -65,7 +69,7 @@ function BaseSelectionStatus({
id="pgn.DataTable.BaseSelectionStatus.selectAllText"
defaultMessage="Select all {itemCount}"
description="A label for select all button."
values={{ itemCount }}
values={{ itemCount: filteredItems }}
/>
)}
</Button>
Expand Down
11 changes: 11 additions & 0 deletions src/DataTable/selection/tests/SelectionStatus.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const instance = {
page: [1, 2, 3, 4],
toggleAllRowsSelected: () => {},
itemCount: 101,
filteredRows: [...new Array(27)],
state: {
selectedRowIds: {
1: true,
Expand Down Expand Up @@ -70,6 +71,16 @@ describe('<SelectionStatus />', () => {
expect(toggleAllRowsSpy).toHaveBeenCalledTimes(1);
expect(toggleAllRowsSpy).toHaveBeenCalledWith(true);
});
it('updates select all button text after applying filters', () => {
const wrapper = mount(<SelectionStatusWrapper value={{ ...instance }} />);
const button = wrapper.find(`button.${SELECT_ALL_TEST_ID}`);
expect(button.text()).toContain('Select all 27');
});
it('updates select all text if filters value is empty', () => {
const wrapper = mount(<SelectionStatusWrapper value={{ ...instance, filteredRows: 0 }} />);
const button = wrapper.find(`button.${SELECT_ALL_TEST_ID}`);
expect(button.text()).toContain('Select all 101');
});
it('does not render the clear selection button if there are no selected rows', () => {
const value = {
...instance,
Expand Down