Browse Source

Update to GOV.UK Frontend 4.2.0; use `govukPagination` component (#697)

* Update govuk-frontend to v4.2.0

* Update govuk-components to v3.1.1

* Replace pagination component with govuk_pagination

* Update pagination tests

* Remove pagy dependency
Pagy is bundled with the govuk-components gem
pull/698/head
Paul Robert Lloyd 3 years ago committed by GitHub
parent
commit
1620531e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      Gemfile
  2. 41
      Gemfile.lock
  3. 8
      app/frontend/application.js
  4. 8
      app/frontend/controllers/govukfrontend_controller.js
  5. 134
      app/frontend/styles/_pagination.scss
  6. 1
      app/frontend/styles/application.scss
  7. 39
      app/views/pagy/_nav.html.erb
  8. 4
      package.json
  9. 4
      spec/requests/case_logs_controller_spec.rb
  10. 4
      spec/requests/organisations_controller_spec.rb
  11. 12
      spec/requests/schemes_controller_spec.rb
  12. 2094
      yarn.lock

3
Gemfile

@ -55,8 +55,7 @@ gem "redis"
# Receive exceptions and configure alerts # Receive exceptions and configure alerts
gem "sentry-rails" gem "sentry-rails"
gem "sentry-ruby" gem "sentry-ruby"
# Pagination # Possessives in strings
gem "pagy"
gem "possessive" gem "possessive"
group :development, :test do group :development, :test do

41
Gemfile.lock

@ -93,8 +93,8 @@ GEM
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2) ast (2.4.2)
aws-eventstream (1.2.0) aws-eventstream (1.2.0)
aws-partitions (1.598.0) aws-partitions (1.601.0)
aws-sdk-core (3.131.1) aws-sdk-core (3.131.2)
aws-eventstream (~> 1, >= 1.0.2) aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0) aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1) aws-sigv4 (~> 1.1)
@ -153,7 +153,7 @@ GEM
dotenv (= 2.7.6) dotenv (= 2.7.6)
railties (>= 3.2) railties (>= 3.2)
encryptor (3.0.0) encryptor (3.0.0)
erb_lint (0.1.1) erb_lint (0.1.3)
activesupport activesupport
better_html (~> 1.0.7) better_html (~> 1.0.7)
html_tokenizer html_tokenizer
@ -173,28 +173,30 @@ GEM
ffi (1.15.5) ffi (1.15.5)
globalid (1.0.0) globalid (1.0.0)
activesupport (>= 5.0) activesupport (>= 5.0)
govuk-components (3.0.6) govuk-components (3.1.2)
actionpack (>= 6.1)
activemodel (>= 6.1) activemodel (>= 6.1)
html-attributes-utils (~> 0.9.0) html-attributes-utils (~> 0.9, >= 0.9.2)
pagy (~> 5.10.1)
railties (>= 6.1) railties (>= 6.1)
view_component (~> 2.49.1) view_component (~> 2.56.2)
govuk_design_system_formbuilder (3.0.3) govuk_design_system_formbuilder (3.1.0)
actionview (>= 6.1) actionview (>= 6.1)
activemodel (>= 6.1) activemodel (>= 6.1)
activesupport (>= 6.1) activesupport (>= 6.1)
html-attributes-utils (~> 0.9.0) html-attributes-utils (~> 0.9, >= 0.9.2)
govuk_markdown (1.0.0) govuk_markdown (1.0.0)
activesupport activesupport
redcarpet redcarpet
hashdiff (1.0.1) hashdiff (1.0.1)
html-attributes-utils (0.9.0) html-attributes-utils (0.9.2)
activesupport (>= 6.1.4.4) activesupport (>= 6.1.4.4)
html_tokenizer (0.0.7) html_tokenizer (0.0.7)
i18n (1.10.0) i18n (1.10.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
iniparse (1.5.0) iniparse (1.5.0)
jmespath (1.6.1) jmespath (1.6.1)
jsbundling-rails (1.0.2) jsbundling-rails (1.0.3)
railties (>= 6.0.0) railties (>= 6.0.0)
json-schema (3.0.0) json-schema (3.0.0)
addressable (>= 2.8) addressable (>= 2.8)
@ -211,7 +213,7 @@ GEM
matrix (0.4.2) matrix (0.4.2)
method_source (1.0.0) method_source (1.0.0)
mini_mime (1.1.2) mini_mime (1.1.2)
minitest (5.15.0) minitest (5.16.1)
msgpack (1.5.2) msgpack (1.5.2)
net-imap (0.2.3) net-imap (0.2.3)
digest digest
@ -252,7 +254,7 @@ GEM
parallel (1.22.1) parallel (1.22.1)
parser (3.1.2.0) parser (3.1.2.0)
ast (~> 2.4.1) ast (~> 2.4.1)
pg (1.3.5) pg (1.4.1)
possessive (1.0.1) possessive (1.0.1)
postcodes_io (0.4.0) postcodes_io (0.4.0)
excon (~> 0.39) excon (~> 0.39)
@ -276,8 +278,8 @@ GEM
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rack-mini-profiler (2.3.4) rack-mini-profiler (2.3.4)
rack (>= 1.2.0) rack (>= 1.2.0)
rack-test (1.1.0) rack-test (2.0.1)
rack (>= 1.0, < 3) rack (>= 1.3)
rails (7.0.3) rails (7.0.3)
actioncable (= 7.0.3) actioncable (= 7.0.3)
actionmailbox (= 7.0.3) actionmailbox (= 7.0.3)
@ -311,7 +313,7 @@ GEM
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
redcarpet (3.5.1) redcarpet (3.5.1)
redis (4.6.0) redis (4.7.0)
regexp_parser (2.5.0) regexp_parser (2.5.0)
request_store (1.5.1) request_store (1.5.1)
rack (>= 1.4) rack (>= 1.4)
@ -371,7 +373,7 @@ GEM
ruby-progressbar (1.11.0) ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5) ruby2_keywords (0.0.5)
rubyzip (2.3.2) rubyzip (2.3.2)
selenium-webdriver (4.2.1) selenium-webdriver (4.3.0)
childprocess (>= 0.5, < 5.0) childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5) rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0) rubyzip (>= 1.2.2, < 3.0)
@ -399,9 +401,9 @@ GEM
timeout (0.3.0) timeout (0.3.0)
tzinfo (2.0.4) tzinfo (2.0.4)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
uk_postcode (2.1.7) uk_postcode (2.1.8)
unicode-display_width (2.1.0) unicode-display_width (2.2.0)
view_component (2.49.1) view_component (2.56.2)
activesupport (>= 5.0.0, < 8.0) activesupport (>= 5.0.0, < 8.0)
method_source (~> 1.0) method_source (~> 1.0)
warden (1.2.9) warden (1.2.9)
@ -450,7 +452,6 @@ DEPENDENCIES
listen (~> 3.3) listen (~> 3.3)
notifications-ruby-client notifications-ruby-client
overcommit (>= 0.37.0) overcommit (>= 0.37.0)
pagy
paper_trail paper_trail
paper_trail-globalid paper_trail-globalid
pg (~> 1.1) pg (~> 1.1)

8
app/frontend/application.js

@ -12,12 +12,12 @@ import 'custom-event-polyfill'
import 'intersection-observer' import 'intersection-observer'
// //
import GOVUKFrontend from 'govuk-frontend' import { initAll as GOVUKFrontend } from 'govuk-frontend'
import GOVUKPrototypeComponents from 'govuk-prototype-components' import { initAll as GOVUKPrototypeComponents } from 'govuk-prototype-components'
import './styles/application.scss' import './styles/application.scss'
import './controllers' import './controllers'
require.context('govuk-frontend/govuk/assets') require.context('govuk-frontend/govuk/assets')
GOVUKFrontend.initAll() GOVUKFrontend()
GOVUKPrototypeComponents.initAll() GOVUKPrototypeComponents()

8
app/frontend/controllers/govukfrontend_controller.js

@ -1,10 +1,10 @@
import GOVUKFrontend from 'govuk-frontend' import { initAll as GOVUKFrontend } from 'govuk-frontend'
import GOVUKPrototypeComponents from 'govuk-prototype-components' import { initAll as GOVUKPrototypeComponents } from 'govuk-prototype-components'
import { Controller } from '@hotwired/stimulus' import { Controller } from '@hotwired/stimulus'
export default class extends Controller { export default class extends Controller {
connect () { connect () {
GOVUKFrontend.initAll() GOVUKFrontend()
GOVUKPrototypeComponents.initAll() GOVUKPrototypeComponents()
} }
} }

134
app/frontend/styles/_pagination.scss

@ -1,134 +0,0 @@
// https://github.com/alphagov/govuk-frontend/blob/add-pagination-prototype/src/govuk/components/pagination/_index.scss
.app-pagination {
border-top: 1px solid $govuk-border-colour;
margin-top: govuk-spacing(2);
padding-top: govuk-spacing(2);
text-align: center;
@include govuk-media-query($from: tablet) {
// Hide whitespace between elements
font-size: 0;
// Trick to remove the need for floats
text-align: justify;
&:after {
content: " ";
display: inline-block;
width: 100%;
}
}
}
.app-pagination__list {
margin: 0 govuk-spacing(-3);
padding: 0;
list-style: none;
@include govuk-media-query($from: tablet) {
display: inline-block;
margin-bottom: 0;
}
}
.app-pagination__results {
@include govuk-font(19);
margin-top: 0;
margin-bottom: govuk-spacing(4);
padding: govuk-spacing(1) 0;
@include govuk-media-query($from: tablet) {
display: inline-block;
}
}
.app-pagination__item {
@include govuk-font(19);
display: inline-block;
margin-bottom: govuk-spacing(4);
// Hide items on small screens
@include govuk-media-query($until: tablet) {
display: none;
}
}
// Only show previous, next, first, last and current items on mobile
.app-pagination__item--current,
.app-pagination__item--divider,
.app-pagination__item--prev,
.app-pagination__item--next,
.app-pagination__item:nth-child(2),
.app-pagination__item:nth-last-child(2) {
@include govuk-media-query($until: tablet) {
display: inline-block;
}
}
.app-pagination__item--current,
.app-pagination__item--divider {
box-sizing: border-box;
font-weight: bold;
min-width: govuk-spacing(8);
min-height: govuk-spacing(4);
padding: govuk-spacing(2);
text-align: center;
}
.app-pagination__item--divider {
margin: 0 govuk-spacing(-4);
padding-right: 0;
padding-left: 0;
color: $govuk-secondary-text-colour;
pointer-events: none;
}
.app-pagination__link {
@include govuk-link-common;
@include govuk-link-style-no-underline;
box-sizing: border-box;
color: $govuk-link-colour;
display: block;
min-width: govuk-spacing(8);
min-height: govuk-spacing(4);
padding: govuk-spacing(2);
text-align: center;
.app-pagination__link-label {
@include govuk-font($size: 16, $weight: "regular");
display: block;
padding-left: 32px;
text-decoration: underline;
}
&:hover .app-pagination__link-label {
@include govuk-link-hover-decoration;
}
&:focus {
box-shadow: 0 0 $govuk-focus-colour, 0 4px $govuk-focus-text-colour;
text-decoration: underline;
}
&:hover:not(:focus) {
background-color: govuk-colour("light-grey", $legacy: "grey-4");
}
}
.app-pagination__icon {
fill: currentcolor;
}
.app-pagination__item--prev .app-pagination__link,
.app-pagination__item--next .app-pagination__link {
padding: govuk-spacing(2) govuk-spacing(3);
font-weight: bold;
}
.app-pagination__item--prev .app-pagination__icon {
margin-right: govuk-spacing(2);
}
.app-pagination__item--next .app-pagination__icon {
margin-left: govuk-spacing(2);
}

1
app/frontend/styles/application.scss

@ -36,7 +36,6 @@ $govuk-breakpoints: (
@import "tag"; @import "tag";
@import "task-list"; @import "task-list";
@import "template"; @import "template";
@import "pagination";
@import "panel"; @import "panel";
@import "primary-navigation"; @import "primary-navigation";
@import "search"; @import "search";

39
app/views/pagy/_nav.html.erb

@ -1,41 +1,6 @@
<% link = pagy_link_proc(pagy) -%> <%= govuk_pagination(pagy:) %>
<% if pagy.pages > 1 %> <% if pagy.pages > 1 %>
<nav class="app-pagination" id="pagination-label" aria-label="results navigation"> <p class="govuk-body">
<ul class="app-pagination__list">
<li class="app-pagination__item app-pagination__item--prev">
<% if pagy.prev %>
<a class="app-pagination__link" href="<%= "#{request.path}?page=#{pagy.prev}" %>">
<% end %>
<span class="app-pagination__link-title">
<svg class="app-pagination__icon" xmlns="http://www.w3.org/2000/svg" height="13" width="17">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
</svg>Previous
<span class="govuk-visually-hidden">page</span>
</span></a>
</li>
<% pagy.series.each do |item| %>
<% if item == :gap %>
<li class="app-pagination__item app-pagination__item--ellipses">…</li>
<% elsif item.is_a?(String) %>
<li class="app-pagination__item app-pagination__item--current"><span class="govuk-visually-hidden">Page </span><%= item %><span class="govuk-visually-hidden"> (current page) </span></li>
<% else %>
<li class="app-pagination__item"><a class="app-pagination__link" href="<%= "#{request.path}?page=#{item}" %>"><span class="govuk-visually-hidden">Page </span><%= item %></a></li>
<% end %>
<% end %>
<li class="app-pagination__item app-pagination__item--next">
<% if pagy.next %>
<a class="app-pagination__link" href="<%= "#{request.path}?page=#{pagy.next}" %>">
<% end %>
Next <span class="govuk-visually-hidden">page</span>
<span class="app-pagination__link-title">
<svg class="app-pagination__icon" xmlns="http://www.w3.org/2000/svg" height="13" width="17">
<path d="m10.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
</svg>
</span></a>
</li>
</ul>
<p class="app_pagination__results">
Showing <b><%= pagy.from %></b> to <b><%= pagy.to %></b> of <b><%= pagy.count %></b> <%= item_name %> Showing <b><%= pagy.from %></b> to <b><%= pagy.to %></b> of <b><%= pagy.count %></b> <%= item_name %>
</p> </p>
</nav>
<% end %> <% end %>

4
package.json

@ -20,8 +20,8 @@
"css-loader": "^6.7.1", "css-loader": "^6.7.1",
"custom-event-polyfill": "^1.0.7", "custom-event-polyfill": "^1.0.7",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
"govuk-frontend": "4.0.1", "govuk-frontend": "4.2.0",
"govuk-prototype-components": "^0.1.5", "govuk-prototype-components": "^0.4.0",
"html5shiv": "^3.7.3", "html5shiv": "^3.7.3",
"intersection-observer": "^0.12.0", "intersection-observer": "^0.12.0",
"mini-css-extract-plugin": "^2.6.0", "mini-css-extract-plugin": "^2.6.0",

4
spec/requests/case_logs_controller_spec.rb

@ -548,7 +548,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).not_to have_content("Previous")
expect(page).not_to have_link("Previous") expect(page).not_to have_link("Previous")
expect(page).to have_content("Next") expect(page).to have_content("Next")
expect(page).to have_link("Next") expect(page).to have_link("Next")
@ -575,7 +575,7 @@ RSpec.describe CaseLogsController, type: :request do
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).to have_content("Previous")
expect(page).to have_link("Previous") expect(page).to have_link("Previous")
expect(page).to have_content("Next") expect(page).not_to have_content("Next")
expect(page).not_to have_link("Next") expect(page).not_to have_link("Next")
end end

4
spec/requests/organisations_controller_spec.rb

@ -874,7 +874,7 @@ RSpec.describe OrganisationsController, type: :request do
context "when on the first page" do context "when on the first page" do
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).not_to have_content("Previous")
expect(page).not_to have_link("Previous") expect(page).not_to have_link("Previous")
expect(page).to have_content("Next") expect(page).to have_content("Next")
expect(page).to have_link("Next") expect(page).to have_link("Next")
@ -901,7 +901,7 @@ RSpec.describe OrganisationsController, type: :request do
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).to have_content("Previous")
expect(page).to have_link("Previous") expect(page).to have_link("Previous")
expect(page).to have_content("Next") expect(page).not_to have_content("Next")
expect(page).not_to have_link("Next") expect(page).not_to have_link("Next")
end end

12
spec/requests/schemes_controller_spec.rb

@ -102,7 +102,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).not_to have_content("Previous")
expect(page).not_to have_link("Previous") expect(page).not_to have_link("Previous")
expect(page).to have_content("Next") expect(page).to have_content("Next")
expect(page).to have_link("Next") expect(page).to have_link("Next")
@ -121,7 +121,7 @@ RSpec.describe SchemesController, type: :request do
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).to have_content("Previous")
expect(page).to have_link("Previous") expect(page).to have_link("Previous")
expect(page).to have_content("Next") expect(page).not_to have_content("Next")
expect(page).not_to have_link("Next") expect(page).not_to have_link("Next")
end end
@ -334,7 +334,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).not_to have_content("Previous")
expect(page).not_to have_link("Previous") expect(page).not_to have_link("Previous")
expect(page).to have_content("Next") expect(page).to have_content("Next")
expect(page).to have_link("Next") expect(page).to have_link("Next")
@ -358,7 +358,7 @@ RSpec.describe SchemesController, type: :request do
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).to have_content("Previous")
expect(page).to have_link("Previous") expect(page).to have_link("Previous")
expect(page).to have_content("Next") expect(page).not_to have_content("Next")
expect(page).not_to have_link("Next") expect(page).not_to have_link("Next")
end end
end end
@ -416,7 +416,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).not_to have_content("Previous")
expect(page).not_to have_link("Previous") expect(page).not_to have_link("Previous")
expect(page).to have_content("Next") expect(page).to have_content("Next")
expect(page).to have_link("Next") expect(page).to have_link("Next")
@ -440,7 +440,7 @@ RSpec.describe SchemesController, type: :request do
it "has pagination links" do it "has pagination links" do
expect(page).to have_content("Previous") expect(page).to have_content("Previous")
expect(page).to have_link("Previous") expect(page).to have_link("Previous")
expect(page).to have_content("Next") expect(page).not_to have_content("Next")
expect(page).not_to have_link("Next") expect(page).not_to have_link("Next")
end end
end end

2094
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save