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 pagination to publication page #2299

Merged
merged 5 commits into from
Aug 29, 2024
Merged

Conversation

mtaylorgds
Copy link
Contributor

@mtaylorgds mtaylorgds commented Aug 23, 2024

Add pagination controls underneath the publications table on the root path of Mainstream Publisher.

image

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Update the `FilteredEditionsPresenter` class to support paginating the
 result returned by the `#editions` method.

If no page is specified then the first page of results will be returned.

Update the tests to make it clearer when reading when the result has
 been converted to an array.
Add backend support for paginating the results used for the publications
 page. This consists of a "page" parameter that can be submitted to the
 controller, which will pass the value through to the
 `FilteredEditionsPresenter`.

Adding pagination controls to the UI will follow in a subsequent commit.
Add a hard-coded sort order to the editions returned by the
 `FilteredEditionsPresenter`, from most-recently updated->least recently
 updated (this is the same as the default sort order of the legacy page
 that is being replaced).

Does not provide a means of changing the sort order for now.

Update a test that isn't testing the order of results to be
 order-agnostic.
@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch from 573b26d to 4d98e3b Compare August 23, 2024 15:45
@mtaylorgds mtaylorgds marked this pull request as ready for review August 23, 2024 15:46
@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch 6 times, most recently from 22a3036 to af83b7d Compare August 27, 2024 10:36
.govuk-pagination__item.govuk-pagination__item--current {
color: #ffffff;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should only really need the .govuk-pagination__item--current class name here: given the naming system it doesn't need to be nested in or extending any other class.

Also we should use the govuk-colour("white") variable to set the colour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Think I'd literally just use

.govuk-pagination__item--current {
  color: govuk-colour("white");
}

Should be specific enough since --current is extending govuk-pagination__item

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I've made that change now.

@davidtrussler
Copy link
Contributor

I've just made one small comment in the CSS. Otherwise it all looks good.

I'm still a bit concerned about implementing a pagination that is slightly different to Whitehall in behaviour and appearance and feel we really ought to be extending that component for use here. But maybe that's something for the future if necessary.

@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch from af83b7d to a828ede Compare August 27, 2024 16:08
@mtaylorgds
Copy link
Contributor Author

I've just made one small comment in the CSS. Otherwise it all looks good.

I've pushed the change you suggested.

I'm still a bit concerned about implementing a pagination that is slightly different to Whitehall in behaviour and appearance and feel we really ought to be extending that component for use here. But maybe that's something for the future if necessary.

It's not a component per se in Whitehall, it still uses the same external library (Kaminari) for pagination, it just uses a helper to generate a "pagination_hash". I don't really understand the Whitehall code, which is partially why I'm reticent to reuse it here—I don't understand what value it provides over what I've done here, which is simple styling changes.

@davidtrussler
Copy link
Contributor

I've just made one small comment in the CSS. Otherwise it all looks good.

I've pushed the change you suggested.

I'm still a bit concerned about implementing a pagination that is slightly different to Whitehall in behaviour and appearance and feel we really ought to be extending that component for use here. But maybe that's something for the future if necessary.

It's not a component per se in Whitehall, it still uses the same external library (Kaminari) for pagination, it just uses a helper to generate a "pagination_hash". I don't really understand the Whitehall code, which is partially why I'm reticent to reuse it here—I don't understand what value it provides over what I've done here, which is simple styling changes.

Yes, I was just looking at it as well. Given there isn't a design for pagination I agree with your point here. 👍

@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch 3 times, most recently from 83ee341 to 4dc2694 Compare August 28, 2024 08:06
Add (unstyled) pagination controls to the publications page. Styling to
 follow.

Use capybara minitest assertions for improved failure readability when
 asserting on page content (vs the plain old minitest assertions used in
 other integration tests).
@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch from 4dc2694 to 879e274 Compare August 28, 2024 08:19
@mtaylorgds
Copy link
Contributor Author

@davidtrussler Have updated some integration tests to turn the publications page toggle off if they navigate to that page, as some of the tests were failing depending on what order the tests were being run in.

@davidtrussler
Copy link
Contributor

I wonder if we should check this from a Design POV before merging. I realise it's not styled exactly as Whitehall but it feels a little less elegant than that pagination on smaller viewports. It's still perfectly functional though so could be a future iteration if required.

Publisher Whitehall
Screenshot 2024-08-28 at 12 58 30 Screenshot 2024-08-28 at 12 58 59

per_page: number of items to fetch per page
remote: data-remote
-%>
<span class="govuk-pagination__prev">
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using <span> elements for each of the items here is slightly problematic. If possible these should be <li> elements.

Also at smaller sizes the govuk-pagination__prev and govuk-pagination__next classes add some slightly awkward padding when used for the first and last items as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've copied the implementation from Whitehall, so this now works identically to that and uses li elements.

@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch 2 times, most recently from 9fbf365 to c748368 Compare August 28, 2024 15:31
Copy the way Whitehall Publisher overrides Kaminari's partials to style
 its pagination components. It would be good for the
 govuk_publishing_components gem to have a pagination control which both
 apps could use, but implementing that would take some time so we will
 create a new ticket for this.
@mtaylorgds mtaylorgds force-pushed the publications-page/pagination branch from c748368 to 827341b Compare August 28, 2024 15:52
Copy link
Contributor

@davidtrussler davidtrussler left a comment

Choose a reason for hiding this comment

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

Looks great! 👍
Also noted the ticket for creating the new component. 🙂

@mtaylorgds mtaylorgds merged commit ef3a72c into main Aug 29, 2024
13 checks passed
@mtaylorgds mtaylorgds deleted the publications-page/pagination branch August 29, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants