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
Pagination
- Fix missing @currentPageSize
argument in the "Compact" variant with SizeSelector
#1724
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
853dc22
to
fbe43b3
Compare
e85222c
to
a398995
Compare
…ntPageSize` and handle controlled/uncontrolled changes
…ency with the “Numbered” implementation
… `Compact` variant with `SizeSelector`
a398995
to
e41e778
Compare
e41e778
to
65ebe6d
Compare
While working on this ticket, I had a meeting with @andrew-hashicorp to discuss some possible issues with using a "page size" in the context of a cursor-based pagination. Here are the findings, for future reference. The problemUsing the "page size" in a cursor-based pagination can lead to increased complexity and, more importantly, potential UX/usability issues. For example when the cursor is The solutionWe could not find an "easy" and obvious solution. @andrew-hashicorp has implemented some workaround but "the tradeoff is that it requires an additional nextPage or prevPage API request, so at worst you need to fetch 2x max pageSize." This is part of the nature of how cursor-based pagination works, and it's hard to reconcile what a user would expect with how the intrinsic logic works. I imagine there may be implementations out in the wild the we could use as reference (eg this document is very detailed: https://jsonapi.org/profiles/ethanresnick/cursor-pagination/ but doesn't explain how this issue is handled, also this done explains in detail how cursor-pagination works: https://engage.so/blog/a-deep-dive-into-offset-and-cursor-based-pagination-in-mongodb/). ConclusionWith @andrew-hashicorp we have agreed that the implementation in this PR (in which on page change we pass But. I think one of the problems is that the logic of handling the cursor-based pagination is handled (partially) client-side, in our products, while many of the examples I've found online delegate the entire logic to the server (they just act as mediator, sending the In any case, I'll discuss this issue with the rest of the HDS engineering team, and we'll come up with a decision if move forward this PR or not. |
@didoo and @andrew-hashicorp I think the solution you’ve come up with here is totally appropriate. In my opinion, cursor-based pagination has benefits (and in some cases is the appropriate choice) but is intrinsically unintuitive. I would encourage any team facing this dilemma to ask themselves “can we instead invest our energy in implementing search/filtering that is so good that users only need use the pagination controls as a last resort?”. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great write up @didoo ! 😃 🙌
💯 Totally agree with @jgwhite's comments WRT the inherent awkwardness of cursor based pagination, and a strong preference for search/filtration UX and API capabilities.
End of the day, nobody really wants to page through a large set of results, and IMO we're going to get diminishing returns on our efforts to make such a pagination UX ideal.
Obviating the need to solve problem(s) with that interaction by employing search/filtration seems like a good thing for application teams to consider by default, only resorting to cursor pagination for edge cases.
@heatherlarsen see Jamie/Jesse comments above. Do you think we could add this as "guidance" in the |
I agree with this approach. In HCP Consul we are clearing page tokens on filter changes but not currently on page size changes. It works in that nothing errors, but as you mentioned above, it doesn't always end up with the expected UX. I am in favour of your suggestion, as it provides a more reliable/expected UX with regards to cursor pagination. |
Just to add further detail to @didoo's excellent summary, pretty much everything works as expected except for the case of staying at the "top" of the page when changing the page size after going to a previous page (which, as a user, is what I would expect). This is because on a previous page, you don't have access to a token that will display the first item if a different page size is selected and is just a result of how cursor-based pagination works. For example: I have a list of 20 items, numbered 1-20.
This is where the limitation of cursor-based pagination appears - I have no token that references What I do have access to:
So the only way to obtain a token that references Each change in How the server can help here is by providing certain additional metadata (i.e. how JSON API does it) - this will provide a token that contains the exact reference to each item in question and will provide the client the complete information to form a proper request without needing to fire off an additional request to see the next or previous page. Alternately a non-JSON API spec method would be to provide an API endpoint that returns the next/prev tokens without the actual data in order to facilitate the workaround without sending the unnecessary 1 result. |
@didoo Someone on the team will need to spend a bit more time thinking through this from a usability perspective, but a ticket to track that work would be great. Thanks! |
📌 Summary
While working on #1700 I completely forgot that the status of the
SizeSelector
for thePagination::Compact
needs to be handled too, depending if the component is "controlled" or not (same as for theNumbered
variant).Context: https://github.com/hashicorp/design-system/pull/1700/files#r1357503235
🛠️ Detailed description
In this PR I have:
Pagination
to expose@currentPageSize
and handle controlled/uncontrolled changesshowLabels
getter to simple tracked variable (for consistency with the “Numbered” implementationPagination
hasRouting
toisControlled
for consistency with theTabs
component (HDS-2648)Pagination
showcase relevant use case and demo for theCompact
variant withSizeSelector
Pagination
👉 👉 👉 Previews:
🔗 External links
Jira tickets:
👀 Component checklist
yarn test:a11y --filter="COMPONENT-NAME"
)💬 Please consider using conventional comments when reviewing this PR.