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

Add fetchInitialResults prop to ContentSearch #124

Merged

Conversation

xipasduarte
Copy link
Contributor

@xipasduarte xipasduarte commented Jul 8, 2022

Description of the Change

This new prop allows control over initial state for the queries in ContentSearch. It
will trigger a fetch when mounting the component and cache the response for display by focusing the search field, making the user aware of what they might be selecting from.

A new state was added to keep track if the search field is focused. This allows for better control of the results area display. To keep previous expectations the default value is false.

Then, on the ContentPicker component extend the same prop with a default value of true to enhance UX.

Closes #43

Alternate Designs

Another alternative was considered for the UX on ContentPicker, but the logic is fairly simple to fix if want to. See the issue for more details.

Possible Drawbacks

I thought about adding an option for the user to specify if they want this fetch to happen on every item count and the effect it would have. I believe that this other prop could be added later without any drawbacks. The only issue might be from a UX stand point, if it becomes preferable to have fetchInitialResults for all item counts in ContentPicker.

Verification Process

  • Manual testing using block example/hello-world which has a post picker following the expected scenarios:
    • When the search field is focused with fetchInitialResults = true the results of the query should be displayed.
    • When the search field is focused with fetchInitialResults = false the current behavior should occur, with fetch.
    • When the ContentPicker is used it should fetch initial results when no items exist content.length === 0. Otherwise the current behavior is expected.
  • By making fetchInitialResults = false as a default the current working logic is kept for ContentSearch.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Added - New prop to ContentSearch to indicate that results should be fetched when on mount (fetchInitialResults).
Added - Initial fetch for ContentPicker. It should fetch results if no items were selected yet.

Credits

This new prop allows initial results to be fetched when mounting ContentSearch. These results will display when focusing the search field, making the user aware of what they might be selecting from.

To keep previous expectations the default value is false on ContentSearch.
Props @helen for detailing an initial approach to solve this UX problem at #43.

This new prop allows control over the focus state on ContentSearch. It
will trigger a fetch just by focusing the search field, making the user
aware of what they might be selecting from.

To keep previous expectations the default value is `false`.
This makes the ContentSearch provide results when focusing the search
field for all pickers without any selected items.
@Antonio-Laguna
Copy link
Member

Hey @xipasduarte, firstly I want to thank you for taking the time for both, opening a PR and also taking the time to go over and clean some code! Thanks!

I'm not sure if Helen's intention was to actually perform the query on focus or rather show some results on focus.

I've recently participated in a project which has over 200,000 published articles in which any search took over 10 seconds which makes me wary of adding this behavior since based on payload size and network conditions, the UI can look unresponsive for no apparent reason.

While I understand this is very much an edge case, I'd say this should just prompt the search on mount so results are ready for whenever the user decides to focus the input, it just gets the results. (this would mean a rename on the new prop). I think it's kind of safe to assume that, if the block is selected (so this component is mounted), you're likely to perform actions that might lead to a search that would benefit from this new prop and behavior.

What are your thoughts on this?

Also interested to know about the opinions of @fabiankaegy and @tlovett1 on this!

Thanks again!

@xipasduarte
Copy link
Contributor Author

Hi @Antonio-Laguna, I'm happy to help and hope I can keep at it 🙂.

I agree that there is an expectation of using the component once it is selected. We also have a focus on the search field when adding the block, which enforces this expectation. So, regardless of the edge case, I think it's a great idea to "warm up" with the initial results rather than fetching on focus.

Any suggestion for the prop rename? Maybe something like fetchInitialResults?

I'll leave some time for others to give feedback before going forward with any changes. I'm going to just test and see if the presence of the search field, even if empty, is affecting the performance of the query. I expected this would be like fetching the first page of any post type archive, but if there are issues we can remove the query arg search and benefit in the edge cases.

@Antonio-Laguna
Copy link
Member

@xipasduarte I think fetchInitialResults is a good name!

This is a new approach to the solution where the results may be
prefetched to display when focusing. This is only valid once the
component mounts.
@xipasduarte
Copy link
Contributor Author

I made the changes to consider fetchInitialResults as the new prop and the expected behavior.

From what I could gather the first fetch will be an empty search field, so this means it is analogous to the first page of the archive and should be fast. (If anyone has a particularly hard example, please run these with it to double check.) Given this, should we expose this prop in the ContentPicker as well? I don't see a lot of harm in doing so, just an added option to consider. As a default it should be true to offer the best UX (which is fetching in most cases).

@xipasduarte xipasduarte changed the title Add fetchOnFocus prop to ContentSearch Add fetchInitialResults prop to ContentSearch Aug 5, 2022
@Antonio-Laguna
Copy link
Member

Hey @xipasduarte ! Thanks for doing this again! I've flagged a minor typo but other than that it's looking good! I agree with it being added to ContentPicker as well. Most props end up being in both. Also agree with being true as it's mostly harmless in these scenarios and enhances UX as you state!

Extende the prop from `ContentSearch` to be controllable by the
`ContentPicker` interface. Set the default value to `true` to enhance
UX.
@xipasduarte
Copy link
Contributor Author

@Antonio-Laguna I've made the correction and extended the fetchInitialResults prop to the ContentPicker componente. I also had a look on the description to make things more in line with what we ended up doing.

Is it possible to enable the tests to run so as to see if everything passes?

Let me know if anything else needs a little more work 🙂

Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

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

Thank you @xipasduarte for your patience on this and for working on it in the first place. I just tested this and made one small update to not have it enabled by default. Besides that this is ready to go and approved from my end :)

@fabiankaegy fabiankaegy disabled auto-merge May 24, 2023 11:55
@fabiankaegy fabiankaegy merged commit 978b866 into 10up:develop May 24, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content Picker: Support showing an initial set of results on focus
3 participants