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

react-instantsearch - Update all props on InstantSearch #1828

Merged
merged 3 commits into from
Jan 16, 2017

Conversation

bobylito
Copy link
Contributor

@bobylito bobylito commented Jan 12, 2017

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:

screenshot 2017-01-12 15 29 54

Alexandre Stanislawski added 2 commits January 11, 2017 10:35
@bobylito bobylito changed the title IS v2 - Update all props on InstantSearch react-instantsearch - Update all props on InstantSearch Jan 12, 2017
@algobot
Copy link
Contributor

algobot commented Jan 12, 2017

By analyzing the blame information on this pull request, we identified @vvo, @mthuret and @Morhaus to be potential reviewers

Copy link
Contributor

@vvo vvo left a 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",
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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([
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

Copy link
Contributor

@vvo vvo left a 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.

@vvo
Copy link
Contributor

vvo commented Jan 12, 2017

You can use cd packages/react-instantsearch && yarn upgrade-interactive to ensure we have the latest helper at the right place.

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.

@bobylito
Copy link
Contributor Author

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?
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep all fine 👍

@bobylito bobylito force-pushed the fix/update-all-props branch from f8a82a9 to cd643f4 Compare January 12, 2017 16:06
Also:
 - fix the indexName property to be able to update it.
 - small refactoring to explicitely define the props of
createInstantSearch
 - update the doc accordingly
@bobylito bobylito force-pushed the fix/update-all-props branch from cd643f4 to 1f89918 Compare January 13, 2017 08:25
@bobylito
Copy link
Contributor Author

I think I'm done here :) Thanks for the reviews :)

@bobylito bobylito merged commit 2ed9b49 into v2 Jan 16, 2017
@bobylito bobylito deleted the fix/update-all-props branch January 16, 2017 09:52
vvo pushed a commit that referenced this pull request Jan 17, 2017
<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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants