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

Fetch all authors from REST API and make dropdown scrollable #813

Merged
merged 14 commits into from
Apr 1, 2020

Conversation

ndev1991
Copy link
Contributor

Issue #756

Add scrollbar inside dropdown and set the max-height.
Screen Shot 2020-03-26 at 2 10 41 PM

@github-actions
Copy link
Contributor

github-actions bot commented Mar 26, 2020

Size Change: +330 B (0%)

Total Size: 511 kB

Filename Size Change
assets/js/edit-story.js 440 kB +330 B (0%)
ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 3.01 kB 0 B
assets/css/stories-dashboard.css 206 B 0 B
assets/js/stories-dashboard.js 68.2 kB 0 B

compressed-size-action

@barklund
Copy link
Contributor

I think the larger issue here is, that only 10 users are loaded from the db. All db users should be loaded and selectable in the dropdown.

CC @spacedmonkey

@spacedmonkey
Copy link
Contributor

I think the issue here is that, the REST API only returns 10 by default. The api maxes out at 100. As to get all users, we would have to pagination through all users.

@ndev1991 ndev1991 self-assigned this Mar 27, 2020
@ndev1991 ndev1991 changed the title Dropdown scrollbar GetAllUsers for Authors using WP v2 REST API, Add Dropdown scrollbar Mar 27, 2020
@spacedmonkey
Copy link
Contributor

Now we have loading from multiple api request, it take a look time for the api requests to load. Should we check if users is not empty on this line now?

@spacedmonkey
Copy link
Contributor

spacedmonkey commented Mar 27, 2020

Screenshot from 2020-03-27 17-32-07
Shouldn't this dropdown be wider?
I am looking at this in chrome and firefox on linux.

@ndev1991
Copy link
Contributor Author

Now we have loading from multiple api request, it take a look time for the api requests to load. Should we check if users is not empty on this line now?

I think users is null at the beginning and updated when there is values. And also we have checking users like && users &&.

@spacedmonkey
Copy link
Contributor

There is already a check, but I am seeing an empty dropdown for a bit.

@ndev1991
Copy link
Contributor Author

There is already a check, but I am seeing an empty dropdown for a bit.

Okay. Then we may need that to dropdown.

@spacedmonkey
Copy link
Contributor

Should be check if see if not not null users and length is more than 0?

@ndev1991
Copy link
Contributor Author

Should be check if see if not not null users and length is more than 0?

Yes, basically we have checking point for users not null for that part. And we will need to add length check to dropdown I think.

@ndev1991
Copy link
Contributor Author

Should be check if see if not not null users and length is more than 0?

Yes, basically we have checking point for users not null for that part. And we will need to add length check to dropdown I think.

hmm... that maybe doesn't make sense. It would be good to add length check after && users &&

@ndev1991
Copy link
Contributor Author

@spacedmonkey basically if we add that beside users check in then the author line with dropdown will appear after all the users loaded. And if we add that to dropdown then the author line shows and the correct value set for dropdown after users fully loaded. What do you think about this? Which would be the expected behavior for this?

@spacedmonkey
Copy link
Contributor

@spacedmonkey basically if we add that beside users check in then the author line with dropdown will appear after all the users loaded. And if we add that to dropdown then the author line shows and the correct value set for dropdown after users fully loaded. What do you think about this? Which would be the expected behavior for this?

The user dropdown loads after in gutenberg. The alternative here to a dropdown that doesn't work at all. The best UX would be only load the users when the dropdown is clicked, as they may never use the dropdown at all. But that is more work.

CC @pbakaus @swissspidy What do you think? Hide the author dropdown until all users have loaded or user something and have a possibly none functioning dropdown for a while.

@pbakaus
Copy link
Contributor

pbakaus commented Mar 28, 2020

@spacedmonkey basically if we add that beside users check in then the author line with dropdown will appear after all the users loaded. And if we add that to dropdown then the author line shows and the correct value set for dropdown after users fully loaded. What do you think about this? Which would be the expected behavior for this?

The user dropdown loads after in gutenberg. The alternative here to a dropdown that doesn't work at all. The best UX would be only load the users when the dropdown is clicked, as they may never use the dropdown at all. But that is more work.

CC @pbakaus @swissspidy What do you think? Hide the author dropdown until all users have loaded or user something and have a possibly none functioning dropdown for a while.

I would definitely recommend loading it async (not on demand when clicking the dropdown, but also not in the critical path of the editor).

So:

  1. on load, show a placeholder for the dropdown ("Loading..", reserving the same space so it doesn't jump around of course)
  2. After the editor is fully initialized, start loading the authors
  3. Replace placeholder with dropdown.

Relatedly, bonus points for loading the entire JS for this async, and not have a single bundle for everything.

@spacedmonkey
Copy link
Contributor

@ndev1991 Did you try passing -1 to the api?

See this comment. WordPress/gutenberg#21212 (comment)

@ndev1991
Copy link
Contributor Author

@ndev1991 Did you try passing -1 to the api?

See this comment. WordPress/gutenberg#21212 (comment)

@spacedmonkey yes. It's same with 100. Returns 100 users at a time when using -1

@merapi merapi linked an issue Mar 31, 2020 that may be closed by this pull request
Copy link
Contributor

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

LGTM

@swissspidy
Copy link
Collaborator

Just to clarify: passing -1 didn't work, despite the fetchAllMiddleware effectively doing the same thing as this PR? 🤔

@ndev1991
Copy link
Contributor Author

ndev1991 commented Apr 1, 2020

Just to clarify: passing -1 didn't work, despite the fetchAllMiddleware effectively doing the same thing as this PR? 🤔

@swissspidy Yes, passing -1 didn't work. It's same as per_page=100. But not tested fetchAllMiddleware

@swissspidy
Copy link
Collaborator

@ndev1991 Please test this again. The following code automatically resulted in multiple HTTP requests being made, loading all users on the site:

const getAllUsers = useCallback(() => {
    return apiFetch({ path: addQueryArgs(users, { per_page: '-1' })});
  }, [users]);

Copy link
Collaborator

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

In my testing this just worked for me:

const getAllUsers = useCallback(() => {
  return apiFetch({ path: addQueryArgs(users, { per_page: '-1' })});
}, [users]);

Because api-fetch automatically handles this for us.

@ndev1991
Copy link
Contributor Author

ndev1991 commented Apr 1, 2020

In my testing this just worked for me:

const getAllUsers = useCallback(() => {
  return apiFetch({ path: addQueryArgs(users, { per_page: '-1' })});
}, [users]);

Because api-fetch automatically handles this for us.

@swissspidy yes it's working. I didn't see it makes multiple http request to fetch all the users.
Updated the code and pushed! Thanks

@ndev1991 ndev1991 requested a review from swissspidy April 1, 2020 18:03
@swissspidy swissspidy changed the title GetAllUsers for Authors using WP v2 REST API, Add Dropdown scrollbar Fetch all authors from REST API and make dropdown scrollable Apr 1, 2020
@swissspidy swissspidy merged commit 8ef4a54 into master Apr 1, 2020
@swissspidy swissspidy deleted the dropdown-scrollbar branch April 1, 2020 19:10
@swissspidy swissspidy added the Type: Bug Something isn't working label Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Author dropdown does not scroll.
6 participants