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

[ResourceList] Fix for the plural resource name when totalItemsCount is greater than 1 #2301

Merged
merged 2 commits into from
Oct 18, 2019
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 UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
3 changes: 2 additions & 1 deletion src/components/ResourceList/ResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class ResourceList extends React.Component<CombinedProps, State> {

const itemsCount = items.length;
const resource =
itemsCount === 1 && !loading
!loading &&
((!totalItemsCount && itemsCount === 1) || totalItemsCount === 1)
? resourceName.singular
: resourceName.plural;

Expand Down
16 changes: 16 additions & 0 deletions src/components/ResourceList/tests/ResourceList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ describe('<ResourceList />', () => {
'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(
<ResourceList
items={singleItemNoID}
renderItem={renderItem}
resourceName={{singular: 'product', plural: 'products'}}
showHeader
totalItemsCount={5}
/>,
);

expect(findByTestID(resourceList, 'headerTitleWrapper').text()).toBe(
'Showing 1 of 5 products',
);
});
});

describe('bulkActionsAccessibilityLabel', () => {
Expand Down