-
Notifications
You must be signed in to change notification settings - Fork 530
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
feat: Implement transformItems
API
#3042
Conversation
Deploy preview for algolia-instantsearch ready! Built with commit 7c10a17 https://deploy-preview-3042--algolia-instantsearch.netlify.com |
c49dfb2
to
cfcc2c0
Compare
Ready for review @algolia/instantsearch-for-websites. I can cherry pick my commits to create several PRs if it makes it easier. |
16ec292
to
c2bddd2
Compare
c2bddd2
to
63840dc
Compare
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.
Look goods. I have some questions on the hits/infiniteHits implementations. Also could you remove sinon from the test files you've modified? That'd be awesome :)
@@ -192,7 +194,7 @@ The first one will be picked, you should probably set only one default value` | |||
); | |||
}, | |||
|
|||
_transformItems({ hitsPerPage }) { | |||
_normalizeItems({ hitsPerPage }) { |
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 good move 👍
src/connectors/hits/connectHits.js
Outdated
if (widgetParams.escapeHits && results.hits && results.hits.length > 0) { | ||
results.hits = escapeHits(results.hits); | ||
if (results.hits && results.hits.length > 0) { | ||
if (typeof widgetParams.transformItems === 'function') { |
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.
Why not provide a default implementation (identity) like in other widget and remove this if statement? Also I'd suggest to test the type sooner at the initialization.
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.
Glad you caught that. I wasn't sure if I should have updated the code flow of the connector or should have adapted my code on the existing flow.
) { | ||
results.hits = escapeHits(results.hits); | ||
if (results.hits && results.hits.length > 0) { | ||
if (typeof widgetParams.transformItems === 'function') { |
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.
Same remarks than in the hits connector.
}); | ||
|
||
const helper = jsHelper({}, '', widget.getConfiguration({})); | ||
helper.search = sinon.stub(); |
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.
When we touch a test file that is still using sinon, we try to take the opportunity to replace it with Jest mocks. Can you do that? 🙏
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.
For sure! I initially didn't want to edit too much code as it was intended to be merged on the yet-to-be consequent feat/3.0
branch.
Tests have been migrated to Jest but rely on #3045. |
merged :) |
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.
Good work! Thanks for taking the time to remove sinon. I think we could do better in the usage of jest but that's fine for now.
This adds support for the
transformItems
option on widgets.How
The implementation was made at the connector level for the following reasons:
transformItems
API in all flavors (since the connectors are/will be shared across InstantSearch libraries)How to review
Each commit is a widget implementation. Click on the commit and add your review there.
See commits →
Supported widgets
These widgets have been selected based on whether they contain items and based on the current React InstantSearch API. Let me know if this list should be updated.
See all InstantSearch.js widgets →
React InstantSearch widgets implementing
transformItems
Closes #2949