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

[Feature Request]: Support for cases where pagesCount cannot be set in Pagination component #123

Closed
2 tasks done
rktyt opened this issue Aug 5, 2022 · 2 comments
Closed
2 tasks done
Labels
enhancement New feature or request

Comments

@rktyt
Copy link

rktyt commented Aug 5, 2022

Description

Difficult to use Pagination when listing users in AWS Cognito.

Reason:
Some services are not easy to obtain total data counts.
(See detail: https://stackoverflow.com/questions/69316247/aws-cognito-user-pool-total-users-count-and-querying

This is not limited to AWS services, only prev, next information may be provided.
So it would be good to have only PREV, NEXT links.

Code of Conduct

@rktyt rktyt added the enhancement New feature or request label Aug 5, 2022
@timogasda
Copy link
Member

Hello,
if you cannot determine your number of pages (pagesCount) from the beginning, you can use open-ended pagination with the openEnd property of Pagination, see the open-ended pagination example. You can also find some usage guidelines in the pagination article: https://cloudscape.design/components/pagination/?tabId=usage.

In practice, you can combine the utilities from our collection hooks with the openEnd property.

Let's imagine you have a custom hook that handles your data fetching from the server and tells you when you have reached the end of your collection (called useData). This could look something like this:

function OpenEndedPagination() {
  const [pageIndex, setPageIndex] = useState(1);

  const { items: allItems, hasMoreData } = useData(pageIndex);

  const { collectionProps, paginationProps, items } = useCollection(allItems, {
    pagination: { pageSize: PAGE_SIZE }
  });

  return <Pagination
    {...paginationProps}
    openEnd={hasMoreData}
    onNextPageClick={({ detail: { requestedPageIndex } }) => {
      setPageIndex(requestedPageIndex);
    }}
  />
}

Full example: https://codesandbox.io/s/fervent-water-plebul?file=/src/App.js

Hope that helps! :)

@rktyt
Copy link
Author

rktyt commented Aug 15, 2022

Thanks!
I assumed that the pagesCount property was not available in this case because it was a required field.

@rktyt rktyt closed this as completed Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants