Skip to content

Commit

Permalink
Merge pull request #2207 from openedx/master
Browse files Browse the repository at this point in the history
sync: master to alpha
  • Loading branch information
edx-requirements-bot authored and PKulkoRaccoonGang committed Aug 1, 2024
2 parents be04271 + e2f6727 commit 7b40355
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 7b40355

Please sign in to comment.