From 4b01c38840ace386f74361a07cc372ce674e5a3f Mon Sep 17 00:00:00 2001 From: Marc Baumbach Date: Fri, 18 Oct 2019 11:39:14 -0400 Subject: [PATCH] Fix for the plural resource name when totalItemsCount is greater than 1 (#2301) --- UNRELEASED.md | 1 + src/components/ResourceList/ResourceList.tsx | 3 ++- .../ResourceList/tests/ResourceList.test.tsx | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/UNRELEASED.md b/UNRELEASED.md index 865796c2cfc..9fcfed0e8dc 100644 --- a/UNRELEASED.md +++ b/UNRELEASED.md @@ -20,6 +20,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f - Fixed `PositionedOverlay` incorrectly calculating `Topbar.UserMenu` `Popover` width ([#1692](https://github.com/Shopify/polaris-react/pull/1692)) - Fixed `recolor-icon` Sass mixin to properly scope `$secondary-color` to the child `svg` ([#2298](https://github.com/Shopify/polaris-react/pull/2298)) - Fixed a regression with the positioning of the `Popover` component ([#2305](https://github.com/Shopify/polaris-react/pull/2305)) +- Fixed an issue with the `ResourceList` component where the plural resource name was not used for `totalItemsCount` ([#2299](https://github.com/Shopify/polaris-react/issues/2299)) - Fixed Stack Item proportion when shrinking ([#2319](https://github.com/Shopify/polaris-react/pull/2319)) - Fixed animation of `Collapsible` with children having margins ([#1980](https://github.com/Shopify/polaris-react/pull/1980)) diff --git a/src/components/ResourceList/ResourceList.tsx b/src/components/ResourceList/ResourceList.tsx index bcf360e283f..652e962a63c 100644 --- a/src/components/ResourceList/ResourceList.tsx +++ b/src/components/ResourceList/ResourceList.tsx @@ -184,7 +184,8 @@ class ResourceList extends React.Component { const itemsCount = items.length; const resource = - itemsCount === 1 && !loading + !loading && + ((!totalItemsCount && itemsCount === 1) || totalItemsCount === 1) ? resourceName.singular : resourceName.plural; diff --git a/src/components/ResourceList/tests/ResourceList.test.tsx b/src/components/ResourceList/tests/ResourceList.test.tsx index 090af2139f2..46d29090b29 100644 --- a/src/components/ResourceList/tests/ResourceList.test.tsx +++ b/src/components/ResourceList/tests/ResourceList.test.tsx @@ -244,6 +244,22 @@ describe('', () => { 'Showing 2 of 5 products', ); }); + + it('prints number of items shown of totalItemsCount plural when totalItemsCount is provided and items is one resource', () => { + const resourceList = mountWithAppProvider( + , + ); + + expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe( + 'Showing 1 of 5 products', + ); + }); }); describe('bulkActionsAccessibilityLabel', () => {