-
Notifications
You must be signed in to change notification settings - Fork 531
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
react-instantsearch - Update all props on InstantSearch #1828
Conversation
Previously was creating a new client at each render.
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.
Awesome you nailed it clearly. This is a very good PR with new tests, fixes and a attention to detail.
Thanks!
@@ -25,6 +25,7 @@ | |||
"@kadira/storybook-addon-notes": "^1.0.1", | |||
"@kadira/storybook-addon-options": "^1.0.1", | |||
"@kadira/storybook-addons": "^1.6.1", | |||
"algoliasearch-helper": "^2.18.0", |
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.
Is this needed inside the root package.json?
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 guess not /o\
@@ -61,6 +61,11 @@ class InstantSearch extends Component { | |||
|
|||
componentWillReceiveProps(nextProps) { | |||
validateNextProps(this.props, nextProps); | |||
|
|||
if (this.props.indexName !== nextProps.indexName) { | |||
this.aisManager.updateIndex(nextProps.indexName); |
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.
💥
@@ -14,15 +14,34 @@ export default function createInstantSearch(defaultAlgoliaClient, root) { | |||
algoliaClient: PropTypes.object, | |||
appId: PropTypes.string, | |||
apiKey: PropTypes.string, | |||
children: React.PropTypes.oneOfType([ |
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.
Nice, how come we never had any warning on this one? 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.
because {...props}. We used to forward any props therefore the linter couldn't know about that.
if (nextProps.algoliaClient) { | ||
this.client = nextProps.algoliaClient; | ||
} else if (props.appId !== nextProps.appId || props.apiKey !== nextProps.apiKey) { | ||
this.client = defaultAlgoliaClient(nextProps.appId, nextProps.apiKey); |
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.
💥
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.
Just request one update or change on the helper at the root of package.json.
You can use Sadly the upgrade.sh seems bugged because when we want to quit one upgrade-interactive without making any changes we are not authorized to do so. |
Yep doing the proper package changes. :) |
@@ -41,6 +41,11 @@ export default function createInstantSearchManager({ | |||
searching: false, | |||
}); | |||
|
|||
function updateClient(client) { | |||
helper.setClient(client); | |||
search(); // Will it work? |
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.
Being curious: what this comment mean?
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.
Note for later: I should remove my own questioning.
Joke aside, I haven't done a proper and complete test on this.
Also I would be interested in your opinion here @vvo @mthuret, should we trigger a new search when the client or the indexName changes. (if not I will cry because I won't know how to test). FYI, we do trigger a new search for new values.
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.
And I won't remove the comment until I have your opinion (because GH will hide it if there is a change at this line)
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.
Yes we should trigger a new search when client and indexName are updated because both can have an impact on the result set:
- changing the index (obvious one)
- updating the client: going from logged off to logged in and having a dedicated API key that will update the result set.
Works?
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.
Just wanted to be sure because we've discussions about related topics. Fine with you @mthuret ?
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.
Yep all fine 👍
f8a82a9
to
cd643f4
Compare
Also: - fix the indexName property to be able to update it. - small refactoring to explicitely define the props of createInstantSearch - update the doc accordingly
cd643f4
to
1f89918
Compare
I think I'm done here :) Thanks for the reviews :) |
<a name="2.2.0"></a> # [2.2.0](v2.1.0...v2.2.0) (2017-01-17) ### Bug Fixes * **clear:** clearing wasn't working with too+ same type facets selected (#1820) ([a9a2364](a9a2364)) * **connectSearchBox:** handle `defaultRefinement` (#1829) ([7a730e2](7a730e2)), closes [#1826](#1826) * **Instantsearch:** Update all props on InstantSearch (#1828) ([2ed9b49](2ed9b49)) * **InstantSearch:** add specific `react-instantsearch ${version}` agent (#1844) ([a1113bc](a1113bc)) * **SFFV:** correct propTypes and add missing default values (#1845) ([a4c1b31](a4c1b31)) * **test:** add missing Snippet and Highliter snapshot ([4accce5](4accce5)) * **widgets:** replace setImmediate use with Promise use when update is needed (#1811) ([17e2497](17e2497)) ### Features * **Menu, connectMenu:** add search for facet values (#1822) ([a6c513e](a6c513e)) * **snippet:** add a snippet widget to be able to highlight snippet results (#1797) ([2aecc40](2aecc40)) * **widgets:** add transformItems to be able to sort and filter (#1809) ([ba539f0](ba539f0))
Summary
This PR aimed at letting the developers update the parameters of
<InstantSearch/>
. Doing so, we also decided to deprecate the searchParameters props and replace it with a<Configure/>
widget.Fixes #1825 #1673
Result
The tourism demo app is now GeoIP based: