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 paginator presenter #924

Merged
merged 9 commits into from
Apr 22, 2024
Merged

Add paginator presenter #924

merged 9 commits into from
Apr 22, 2024

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-4445

Part of a series of changes to migrate the legacy view bill runs page into this project

The legacy view bill runs page has a custom pagination control. We understand why, the pagination component didn't exist in the design system at the time it was built. But now we have the component there is no need to migrate the custom one.

One of the key reasons to look at migrating the bill runs page is because we have other pages that need updating that also use a form of custom pagination. If we can crack how to implement the GOV.UK component we have a solution for all of them.

This PaginatorPresenter we're adding will build the 'object' that has to be passed to govukPagination() in the nunjucks view. There are several scenarios it has to consider, for example

  • when there are not enough results to warrant pagination
  • whether to show the previous or next controls
  • when to show the ellipsis to highlight skipped pages

To do this all it needs are

  • the total number of records for the thing being paginated
  • how many results to show per page
  • what page of results is selected

The presenter we've built is intended to be used by all pages that need the component, not just bill runs. Because of this, we've tried to ensure the testing and documentation cover all possible scenarios.

https://eaflood.atlassian.net/browse/WATER-4445

> Part of a series of changes to migrate the legacy view bill runs page into this project

The legacy view bill runs page has its own custom pagination control. We understand why, the [pagination component](https://design-system.service.gov.uk/components/pagination/) didn't exist in the design system at the time. But now we have the component there is no need to migrate the custom one built. We wouldn't want to!

One of the key reasons to look at migrating the bill runs page is because we have other pages that need updating that also use some form of custom pagination. If we can crack how to implement the GOV.UK component we have a solution for all of them.

This `PaginatorPresenter` we're adding will build the 'object' that has to be passed to `govukPagination()` in the view. There are a number of scenarios it has to consider, for example

- when there are not enough results to warrant pagination
- whether to show the previous or next controls
- when to show the ellipsis to highlight skipped pages

To do this all it needs are

- the total number of records for the thing being paginated
- how many results to show per page
- what page of results is selected

The presenter we've built is intended to be used by all pages that need the component, not just bill runs. Because of this we've tried to make sure the testing and documentation covers all possible scenarios.
@Cruikshanks Cruikshanks added the enhancement New feature or request label Apr 18, 2024
@Cruikshanks Cruikshanks self-assigned this Apr 18, 2024
@Cruikshanks Cruikshanks marked this pull request as ready for review April 19, 2024 16:10
const component = { items }

if (selectedPageNumber !== 1) {
component.previous = { href: `/system/bill-runs?page=${selectedPageNumber - 1}` }
Copy link
Contributor

Choose a reason for hiding this comment

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

More of a question really. If the intention is to reuse this presenter on other pages that require this component, should we be hardcoding the URL /system/bill-runs? I guess currently it's fine as it is the only page that uses this presenter. But is it worth setting up the URL as an additional parameter now, or is that something to do if/when we need to?

Copy link
Member Author

Choose a reason for hiding this comment

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

🎯 Brilliant spot. Yes, I should be making this a param.

Jozzey
Jozzey previously approved these changes Apr 22, 2024
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

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

Just a comment to do with as you please 😁 Looks very good 👍🏼

Default is now 25 plus there was a typo in the example.
Thanks to a great spot by @Jozzey we realised that the paginator, though intended for reuse, had hard code the links to be `/system/bill-runs`.

If other pages are to be able to reuse it that path must be provided as an arg.

This change updates the presenter. The tests will fail but we wanted to confirm that before fixing them.
@Cruikshanks Cruikshanks dismissed stale reviews from Jozzey and robertparkinson via 0033599 April 22, 2024 12:24
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

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

@Cruikshanks Cruikshanks merged commit ce7950f into main Apr 22, 2024
6 checks passed
@Cruikshanks Cruikshanks deleted the add-paginator-presenter branch April 22, 2024 15:16
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

Successfully merging this pull request may close these issues.

3 participants