feature(instant-results): add filters for labels, options, components, and config#4326
Open
faisalahammad wants to merge 1 commit into
Open
feature(instant-results): add filters for labels, options, components, and config#4326faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
…, and config - Add ep.InstantResults.filter.label JS filter for facet labels. - Add ep.InstantResults.filter.postType.options JS filter for post type options. - Add ep.InstantResults.filter.priceRange.options JS filter for price range bounds. - Add ep.InstantResults.component.didYouMean and ep.InstantResults.component.sort JS filters for components. - Add ep.InstantResults.response JS filter for the search results response. - Add ep_instant_results_config PHP filter for the front-end config object. Fixes 10up#3975
This file contains hidden or 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
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.
Summary
This PR adds more filters to the Instant Results feature so developers can customize facet labels, facet options, individual components, and the front-end configuration object. It addresses the customization gaps described in #3975.
Fixes #3975
Changes
assets/js/api-search/index.js
Before:
After:
Why: allows third-party code to modify the search results response before it is passed to the React state, with a fallback in case a filter returns a falsy value.
assets/js/instant-results/components/facets/facet.js
Before: facets received the
labelprop directly.After: the label is passed through
ep.InstantResults.filter.labelwith the facet name, type, and post types so all facet labels can be customized from one filter.Why: gives developers a single hook for changing facet labels without editing component internals.
assets/js/instant-results/components/facets/post-type-facet.js
Before:
After: reduced options are passed through
ep.InstantResults.filter.postType.optionsbefore being rendered.Why: lets developers reorder, remove, or relabel post type options.
assets/js/instant-results/components/facets/price-range-facet.js
Before: the slider min/max were taken directly from aggregations.
After: the min/max values are passed through
ep.InstantResults.filter.priceRange.optionsas{ min, max }.Why: allows the price range bounds to be adjusted by third-party code.
assets/js/instant-results/components/results/did-you-mean.js and assets/js/instant-results/components/tools/sort.js
Before: components were returned directly.
After: components are assigned to a variable and returned through
ep.InstantResults.component.didYouMeanandep.InstantResults.component.sortrespectively.Why: follows the same pattern already used for
ep.InstantResults.Resultandep.InstantResults.Paginationso components can be wrapped or replaced.includes/classes/Feature/InstantResults/InstantResults.php
Before: the localized
epInstantResultsconfig was passed directly towp_localize_script.After: the config is built into a variable, filtered through
ep_instant_results_config, and then passed towp_localize_script.Why: provides a PHP-side hook for the entire front-end configuration object.
Testing
Test 1: Facet label filter
ep.InstantResults.filter.labelto rename a taxonomy facet.Result: the facet label is updated.
Test 2: Post type options filter
ep.InstantResults.filter.postType.optionsto transform option labels.Result: the option labels reflect the filter output.
Test 3: PHP config filter
ep_instant_results_configto change a value.window.epInstantResults.Result: the modified value is present in the front-end config.
Notes
npm run lint-jspasses for the changed JS files.composer run lintreports only pre-existing failures in other test files;InstantResults.phpis clean.vendor/bin/phpunit --filter TestInstantResultspasses except for an unrelated pre-existing quote mismatch intest_requirements_status.