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 loading indicator to combo box control author selector #68927

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Jan 28, 2025

This PR is a rework of the effort in #27865 - see that ticket for additional details.

Testing instructions

  1. Create a large number of editors (see below for command).
  2. Load a page in the editor
  3. Open DevTools and throttle network connections to a 3G speed to slow down the rest API responses
  4. Click the author to edit, then try typing in part of a user name

Expected results:

  • A spinner is shown while the search callback executes
  • the "No items found' string only shows when the search completes (and no items are found)

Helpful wp-cli commands for testing:

Generate many users to test searching: wp user generate --role=editor --count=100
Delete test users: wp user delete $(wp user list --role=editor --field=ID) --reassign=2

Screencasts

Before changes (trunk)

before2.mp4

Add spinner

(note message "No items found" shows during search callback)

spinner-only.mp4

Final PR

(including removal of "No items found" during load)

after.mp4

@adamsilverstein
Copy link
Member Author

adamsilverstein commented Jan 28, 2025

Note: the drop-down shows "No items found." during the search, a bug clearly visible currently (before this PR) when throttling the search callback.

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. [Package] Components /packages/components labels Jan 29, 2025
@adamsilverstein adamsilverstein marked this pull request as ready for review January 29, 2025 14:30
@adamsilverstein adamsilverstein requested review from Mamaduka and removed request for ajitbohra January 29, 2025 14:30
Copy link

github-actions bot commented Jan 29, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: adamsilverstein <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: ciampo <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@adamsilverstein
Copy link
Member Author

I updated the PR to avoid showing "No items found" string while the results are still loading.

@adamsilverstein adamsilverstein changed the title Add loading indicator to author selector Add loading indicator to combo box control author selector Jan 29, 2025
@@ -44,13 +45,14 @@ export default function PostAuthorCombobox() {
<ComboboxControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Author' ) }
label={ __( 'Authorz' ) }
Copy link
Member

Choose a reason for hiding this comment

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

Typo?

Copy link
Member Author

Choose a reason for hiding this comment

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

ha, this was me trying to get my build working and not seeing changes. will revert!

@@ -157,7 +158,7 @@ export function SuggestionsList<
);
/* eslint-enable jsx-a11y/click-events-have-key-events */
} ) }
{ suggestions.length === 0 && (
{ suggestions.length === 0 && ! isLoading && (
Copy link
Member

Choose a reason for hiding this comment

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

The SuggestionsList component is shared, which is why we're passing the isLoading prop, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

right

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks, @adamsilverstein!

My suggestion is to limit new loading state changes to the ComboboxControl. The FormTokenField component is a bit tricky, as input and tokens can wrap on multiple lines. So, I'm not sure if the spinner suffix design will work for it.

Do you mind including a screenshot or screencast in the PR description?

Hopefully, the v2 design will account for the loading state of #64086.

cc @WordPress/gutenberg-components

@adamsilverstein
Copy link
Member Author

My suggestion is to limit new loading state changes to the ComboboxControl. The FormTokenField component is a bit tricky, as input and tokens can wrap on multiple lines. So, I'm not sure if the spinner suffix design will work for it.

Thanks for the review.

I will add some screenshots/screencasts to show what this change does (when I am back at my desk Friday). I can also take a look at other consumers of the component to make sure they are unaffected. The main goal of the change here is to avoid showing "No items found" string while the (author) search is underway. Since it isn't directly related to adding a spinner, I can break it out into a follow up PR and we can explore the issue separately.

@Mamaduka
Copy link
Member

I think it's okay to change the SuggestionsList here, but let's avoid adding the isLoading prop to the FormTokenField. This way we can focus only on ComboboxControl improvements.

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Finally, I would also suggest

packages/components/src/combobox-control/index.tsx Outdated Show resolved Hide resolved
options={ authorOptions }
value={ authorId }
onFilterValueChange={ debounce( handleKeydown, 300 ) }
onChange={ handleSelect }
allowReset={ false }
hideLabelFromVision
isLoading={ isLoading }
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference would we to focus this PR solely on the ComboboxControl component.

We should add a Storybook example here to allow for easy testing of the component in isolation.

In a separate, follow-up PR, we could then tweak the post author combobox to use the new prop

Copy link
Member Author

Choose a reason for hiding this comment

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

The entire point of this PR is to improve the author selector - changing only the combobox won't actually change anything, shouldn't we aim for PRs that actually improve things?

I can look into adding to the storybook, would this just be a variation with the isLoading prop?

Copy link
Contributor

Choose a reason for hiding this comment

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

The @wordpress/component package is not only used in the Gutenberg repository, but it's also used by third-party developers. Therefore, we usually try to keep changes to the "library" separate from changes to the Gutenberg app (hence why I suggest testing the changes in isolation in Storybook).

Having smaller and more focused PRs is also easier to review, and understand for a future developer stumbling upon it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Having smaller and more focused PRs is also easier to review, and understand for a future developer stumbling upon it.

I understand the principal, however this entire PR is currently less than 35 lines modified so I think is already easy to review and understand! Given the testing instructions I provided, I feel having the PR do something makes it easier to test and understand.

That said, I sense that you feel strongly about this and I will defer to your more recent experience building here. I will split the combobox and author changes into separate PRs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I created a follow up PR with just the Comobox changes here:

#68990

This is a follow up PR to introduce the post author changes:

#68991

Let's continue the conversation on those PRs.

packages/components/src/combobox-control/types.ts Outdated Show resolved Hide resolved
@@ -126,6 +127,7 @@ function ComboboxControl( props: ComboboxControlProps ) {
help,
allowReset = true,
className,
isLoading = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this prop won't affect existing usages, although I wonder if it's a good idea, API-wise.

The component doesn't have a canonical example of how to use it with asynchronously loaded options, and I wonder if adding this prop will improve the DevX (related to #55574) — @WordPress/gutenberg-components what do you think?

If we want to encourage this pattern, we should at least add a Storybook example about it?

Copy link
Member Author

@adamsilverstein adamsilverstein Jan 31, 2025

Choose a reason for hiding this comment

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

I wonder if adding this prop will improve the DevX

Not sure about DevX, this change is about improving User Experience. As is, the combobox selector provides a poor UX when the internet connection is slow or unreliable. The user has no way of knowing that a search is underway during the async search. This shortcoming was overlooked when we originally built the component and I feel this more of a bug than an enhancement.

@adamsilverstein
Copy link
Member Author

I think it's okay to change the SuggestionsList here, but let's avoid adding the isLoading prop to the FormTokenField. This way we can focus only on ComboboxControl improvements.

I will remove these changes for now and we can consider adding them in a follow up PR.

I have included screencasts above so you can see why I added this change in the first place.

@adamsilverstein
Copy link
Member Author

I think it's okay to change the SuggestionsList here, but let's avoid adding the isLoading prop to the FormTokenField. This way we can focus only on ComboboxControl improvements.

Reverted in fd97afc

@adamsilverstein
Copy link
Member Author

@ciampo - In 3a357c4 I added the !isLoading conditional so the suggestion list only shows when the component isn't loading data, what do you think? I will add a screencast to show how this works.

@@ -112,13 +113,20 @@ If the control is clicked, the dropdown will expand regardless of this prop.
- Required: No
- Default: `true`

### placeholder
#### placeholder
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏


If passed, the combobox input will show a placeholder string if no values are present.

- Type: `string`
- Required: No

#### isLoading

If true, the dropdown will show a loading indicator.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's match the same description as the one from types.ts

Copy link
Member Author

Choose a reason for hiding this comment

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

matched

@adamsilverstein
Copy link
Member Author

Closing in favor of #68991 and #68990

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Design Feedback Needs general design feedback. [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants