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

Decouple Instant Results from the Modal #3159

Merged
merged 59 commits into from
Jan 20, 2023
Merged

Decouple Instant Results from the Modal #3159

merged 59 commits into from
Jan 20, 2023

Conversation

JakePT
Copy link
Contributor

@JakePT JakePT commented Nov 25, 2022

Description of the Change

This change decouples Instant Results from the modal UI. This is achieved by moving the state logic out of the modal to an ApiSearchProvider provider component and providing a custom hook useApiSearch() for consuming its state and methods. The various Instant Results components have been updated to use this hook instead of the generic Context.

The provider component is not currently publicly exposed, but that's something that could be possible in a future version once its API is more stable.

The main challenge was how to handle the open/closed state of the modal, since this was coupled with the history API functionality so that back and forward could properly open and close the modal. The problem being that this open/close logic is related to the modal UI and not the rest of the state. The solution I came up with was to have a generic on/off state of the provider that the Modal UI could control and whose state it could reflect to open and close the modal, while other UI implementations could theoretically use it differently.

A side effect of some of the improvements made here is that a bug where an Instant Results request would be sent on every page load, even if the modal was never opened, has been fixed. Now an API request is only sent when the modal is opened.

Closes #2979

How to test the Change

  1. Confirm that when Instant Results is enabled and a page is loaded, no AJAX request is sent to the API until the modal is opened.
  2. There are no other user-facing changes, so the only testing required is to confirm that everything in Instant Results continues to function as expected.

Changelog Entry

Changed - Under the hood improvements to the structure of Instant Results.
Fixed - An issue where API requests for Instant Results would be sent on page load before the modal has been opened.

Credits

@JakePT

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

goaround and others added 30 commits December 15, 2020 11:41
Check if facetSearchInput exists.
Add missing );
Revert "Support multiple Facets"
Merge develop into master in prep for 3.5.5
Merge develop into master for 3.5.6 release
Add captions to WP.org screenshots
Update the trunk branch
@JakePT JakePT marked this pull request as ready for review January 19, 2023 07:21
@JakePT JakePT changed the title WIP: Decouple Instant Results from the Modal Decouple Instant Results from the Modal Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:instant-results Issues related to the Instant Results functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple Instant Results from the Modal
5 participants