From e2f67271dc799445878de38206437999dab9dd96 Mon Sep 17 00:00:00 2001
From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com>
Date: Fri, 21 Apr 2023 14:27:28 +0300
Subject: [PATCH] fix: fixed incorrect label in Select All button (#2020)
* fix: fixed incorrect label in Select All button
* refactor: added tests
* refactor: added second test
---
src/DataTable/selection/BaseSelectionStatus.jsx | 8 ++++++--
.../selection/tests/SelectionStatus.test.jsx | 11 +++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/DataTable/selection/BaseSelectionStatus.jsx b/src/DataTable/selection/BaseSelectionStatus.jsx
index 6d8a43610c..806d220585 100644
--- a/src/DataTable/selection/BaseSelectionStatus.jsx
+++ b/src/DataTable/selection/BaseSelectionStatus.jsx
@@ -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 || (
)}
diff --git a/src/DataTable/selection/tests/SelectionStatus.test.jsx b/src/DataTable/selection/tests/SelectionStatus.test.jsx
index 5d655ba1e0..f1b1a6e3ec 100644
--- a/src/DataTable/selection/tests/SelectionStatus.test.jsx
+++ b/src/DataTable/selection/tests/SelectionStatus.test.jsx
@@ -15,6 +15,7 @@ const instance = {
page: [1, 2, 3, 4],
toggleAllRowsSelected: () => {},
itemCount: 101,
+ filteredRows: [...new Array(27)],
state: {
selectedRowIds: {
1: true,
@@ -70,6 +71,16 @@ describe('', () => {
expect(toggleAllRowsSpy).toHaveBeenCalledTimes(1);
expect(toggleAllRowsSpy).toHaveBeenCalledWith(true);
});
+ it('updates select all button text after applying filters', () => {
+ const wrapper = mount();
+ 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();
+ 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,