Skip to content

feat: paginating Users page #4792

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

Merged
merged 34 commits into from
Oct 28, 2022
Merged

feat: paginating Users page #4792

merged 34 commits into from
Oct 28, 2022

Conversation

presleyp
Copy link
Contributor

The users page doesn't have a count endpoint yet, so the pagination widget doesn't show page numbers.

I also updated a helper function in api.ts to be more widely usable and used it in all paginated endpoints.

Screen Shot 2022-10-27 at 1 14 15 PM

@presleyp presleyp requested a review from a team as a code owner October 27, 2022 18:15
@presleyp presleyp requested review from BrunoQuaresma and removed request for a team October 27, 2022 18:15
@presleyp presleyp changed the title feat: pagination Users page feat: paginating Users page Oct 27, 2022

export const usersMachine = createMachine(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of this diff is just because I used the visualizer and it reformatted, so I'll comment where it's relevant

states: {
startingPagination: {
entry: "assignPaginationRef",
always: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

start in this state to spawn the pagination machine, then go to gettingUsers. Since we always go there on mount, we don't need the useEffect kicking it off. The other thing the useEffect did was respond to filter changes, but we send events for that now.

target: "updatingUserRoles",
actions: "assignUserIdToUpdateRoles",
},
UPDATE_PAGE: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

UPDATE_PAGE and UPDATE_FILTER are new. UPDATE_FILTER sends RESET_PAGE to the pagination machine, which sends UPDATE_PAGE to this machine.

// when it is mocked. This happen in the UsersPage tests inside of the
// "shows a success message and refresh the page" test case.
getUsers: (context) => {
const { offset, limit } = getPaginationData(context.paginationRef)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sending pagination data in the api call

})
},
}),
assignPaginationRef: assign({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These last two actions are new. Sorry about all the noise!

@BrunoQuaresma
Copy link
Collaborator

While doing some QA I noticed the pagination is being displayed during the loading phase.

Screen.Recording.2022-10-27.at.17.06.01.mov

@BrunoQuaresma
Copy link
Collaborator

I'm able to go next when there are no more results.
Screen Shot 2022-10-27 at 17 07 50
Screen Shot 2022-10-27 at 17 07 37

Since we don't have the count endpoint for the users. I think we could check if the current size is "lower" than 25 (I'm guessing it is the number of items on each page).

@presleyp
Copy link
Contributor Author

I'm able to go next when there are no more results. Screen Shot 2022-10-27 at 17 07 50 Screen Shot 2022-10-27 at 17 07 37

Since we don't have the count endpoint for the users. I think we could check if the current size is "lower" than 25 (I'm guessing it is the number of items on each page).

Yeah, I was just going to fix that by adding the count endpoint next. It's always possible you have exactly 25 records so sometimes we'll enable the next button when we shouldn't.

@presleyp
Copy link
Contributor Author

While doing some QA I noticed the pagination is being displayed during the loading phase.

Screen.Recording.2022-10-27.at.17.06.01.mov

Makes sense, because I'm letting it show when the count is undefined. This makes me think we might want the pagination controls to just show all the time. I like having them available before the count is loaded both because it enables me to break up this work and because, if we don't end up changing our strategy for fetching the count, it means we don't block page usage on waiting for the count to come back (it's an expensive query when the number of records is large).

@BrunoQuaresma
Copy link
Collaborator

BrunoQuaresma commented Oct 27, 2022

IMO, the pagination only should be visible when the table is visible since the pagination is kinda an extension of the table controls.

@presleyp
Copy link
Contributor Author

IMO, the pagination only should be visible when the table is visible since the pagination is kinda an extension of the table controls.

Yeah, that makes sense, but right now since we don't have the count yet, nothing stops you from paging forward too far to an empty page, so we have to show the controls in that case. Once the endpoint is done, I might be able to change it, but it depends on other decisions (like how we handle navigating to a page with no entries and whether we want count to remain a separate endpoint). I think I'll just make the widget always show for now so at least it doesn't look bad.

@presleyp presleyp merged commit 506a81e into main Oct 28, 2022
@presleyp presleyp deleted the paginate-users/presleyp branch October 28, 2022 19:43
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants