-
Notifications
You must be signed in to change notification settings - Fork 386
fix(localizecount): allow localized string for count in MenuSelect #657
Conversation
Deploy preview ready! Built with commit e1890a6 |
@@ -27,6 +27,12 @@ import MenuSelectComponent from '../components/MenuSelect.js'; | |||
* > | |||
* <MenuSelect | |||
* attributeName="category" | |||
* transformItems={items => | |||
* items.map(item => { | |||
* item.count = (item.count + 1000).toLocaleString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this documentation is needed, it might be confusing why you're adding 1000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @Haroenv, the examples in the documentation try to be the most minimal possible. For more elaborate example we have Storybook. No need to demonstrate the usage of transform Items on the documentation page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the input. I'll remove it and push the commit.
stories/MenuSelect.stories.js
Outdated
defaultRefinement={text('defaultSelectedItem', 'Bathroom')} | ||
transformItems={items => | ||
items.map(item => { | ||
item.count = (item.count + 1000).toLocaleString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid to modify an object inside a map, try to always return a new object. Prefer something like:
items.map(({ count, ...item }) => ({
...item,
count: count.toLocaleString()
}));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update the PR. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! 🎉
<a name="4.3.0-beta.0"></a> # [4.3.0-beta.0](v4.2.0...v4.3.0-beta.0) (2017-11-27) ### Bug Fixes * **babelrc:** add a key for each env development, production, es ([#547](#547)) ([fa9528d](fa9528d)) * **localizecount:** allow localized string for count in MenuSelect ([#657](#657)) ([67ebd34](67ebd34)) * **react-router-example:** Properly update search query when using browser navigation ([#604](#604)) ([9ee6600](9ee6600)) ### Features * **refreshcache:** add prop refresh to InstantSearch instance ([#619](#619)) ([19f6de0](19f6de0))
Summary
MenuSelect prop-types only allow for type
number
foritem.count
. This makes it impossible totransformItems
in the widget so that the count is localized, because.toLocaleString()
returns a string which causes prop validation to fail.Result
packages/react-instantsearch/src/components/MenuSelect.js
Changed MenuSelect
items
>item.count
prop-type to accept string as well as number usingPropTypes.oneOfType([...])
.Require-chaining w/
oneOfType
keeps the prop mandatory regardless of type. See prop-types docs.stories/MenuSelect.stories.js
Added
with localized count
MenuSelect story to Storybook to demonstrate concept.packages/react-instantsearch/src/widgets/MenuSelect.js
Added localize count
transformItems
demonstration to MenuSelect @example docs.