-
Notifications
You must be signed in to change notification settings - Fork 312
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
Support customizing the template for search results in Instant Results #2959
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
felipeelia
requested changes
Sep 15, 2022
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.
@JakePT in addition to my comments, we also need to fix a conflict in theme-integration.md. Do you mind handling that? Thanks.
ps.: It would be great if we could have e2e tests checking the new filter as well. Would you be able to add it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
This implements a JavaScript hook using
@wordpress/hooks
to support developers replacing the component used to render search results in Instant Results.In #2527 I described an approach where the filter wraps the return value to filter the rendered element upon render, but in this PR I ended up taking a different approach where I am filtering the component itself. I did this for a few reasons:
Something that was also considered was the naming of JavaScript hooks. @felipeelia and I explored a few other plugins and Gutenberg itself and didn't find much consistency. What this PR proposes is
plugin.Feature.valueBeingFiltered
In this case that'selasticpress.InstantResults.Result
.The
Result
value is capitalized to reflect the fact that a React component is being filtered and those are conventionally named, and represented in JSX, capitalized. If the value of a regular function such asgetPostTypesFromForm()
were to be filtered that would useelasticpress.InstantResults.getPostTypesFromForm
.Some other things to think about are whether the namespace should be
elasticpress
orep
, to be somewhat consistent with the PHP hooks, and how to capitalize the feature names since they don't represent an actual object in JavaScript. I went withInstantResults
overinstantResults
to match the PHP class and for aesthetic reasons.Closes #2527
How to test the Change
The included documentation update includes some examples of how the filter can be used. Implementing these would confirm if things are functioning as expected.
Changelog Entry
Credits
Props @JakePT
Checklist: