Skip to content

Commit

Permalink
Make applications table vertical on small screens
Browse files Browse the repository at this point in the history
Since #2341, we've had support for making tables use a vertical layout
on smaller viewports, similar to how the summary list reflows on smaller
viewports (the end result is something of a hybrid of table and summary
list layouts)

We already use this on the users screen. This feels like something that
would be useful on the applications screen too

I've added an optional `visually_hidden` flag on table head cells here,
which when set to `true` will result in a class that removes padding
from the header cell. The current actions column on the applications
page has a visually hidden header, so this allows us to remove the
padding from visually hidden header cells while retaining the content

Per f0a8f53, we switch to regex-based matching for some tests. The
vertical layout implementation adds some hidden text in table cells that
would otherwise break these `assert_select`s
  • Loading branch information
yndajas committed Jun 28, 2024
1 parent d6e8341 commit d1dc9ef
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 33 deletions.
23 changes: 16 additions & 7 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ $govuk-page-width: 1140px;
@import "components/contact-details";
@import "components/table";

$applications-table-actions-gap: 10px;

// TODO: move into component
.gem-c-success-alert,
.gem-c-error-alert {
Expand Down Expand Up @@ -88,15 +90,22 @@ $govuk-page-width: 1140px;
}
}

.govuk-table__actions {
display: flex;
flex-direction: column;
align-items: end;
gap: 10px;

@media (min-width: 40.0625em) {
.govuk-table__actions {
@include govuk-media-query($until: $vertical-on-smallscreen-breakpoint) {
.govuk-button, .govuk-link {
display: block;

&:not(:last-child) {
margin-bottom: $applications-table-actions-gap;
}
}
}

@include govuk-media-query($from: $vertical-on-smallscreen-breakpoint) {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
gap: $applications-table-actions-gap;
}
}
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ $table-row-even-background-colour: govuk-colour("light-grey", $legacy: "grey-4")
padding-right: 1em;
text-align: left;
word-break: initial;

&--visually-hidden {
padding-right: 0;
}
}

@include govuk-media-query($from: $vertical-on-smallscreen-breakpoint) {
Expand Down
6 changes: 4 additions & 2 deletions app/views/account/applications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
head: [
{ text: "Name" },
{ text: "Description" },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden") },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden"), visually_hidden: true },
],
rows: @applications_with_signin.map do |application|
[
Expand All @@ -43,6 +43,7 @@
},
]
end,
vertical_on_small_screen: true,
} %>

<div class="govuk-table--with-actions">
Expand All @@ -51,7 +52,7 @@
head: [
{ text: "Name" },
{ text: "Description" },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden") }
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden"), visually_hidden: true }
],
rows: @applications_without_signin.map do |application|
[
Expand All @@ -60,5 +61,6 @@
{ text: wrap_links_in_actions_markup([account_applications_grant_access_link(application)]) }
]
end,
vertical_on_small_screen: true,
} %>
</div>
3 changes: 2 additions & 1 deletion app/views/api_users/applications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
head: [
{ text: "Name" },
{ text: "Description" },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden") },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden"), visually_hidden: true },
],
rows: @applications.map do |application|
[
Expand All @@ -44,4 +44,5 @@
{ text: wrap_links_in_actions_markup([api_users_applications_permissions_link(application, @api_user)]) }
]
end,
vertical_on_small_screen: true,
} %>
5 changes: 3 additions & 2 deletions app/views/components/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
format: item[:format],
href: item[:href],
data_attributes: item[:data_attributes],
sort_direction: item[:sort_direction]
sort_direction: item[:sort_direction],
visually_hidden: item[:visually_hidden]
} %>
<% end %>
<% end %>
Expand All @@ -47,7 +48,7 @@
} %>
<% elsif vertical_on_small_screen && head.any? %>
<%= t.cell nil, { format: cell[:format] } do %>
<span class="app-c-table__duplicate-heading" aria-hidden="true">
<span class="app-c-table__duplicate-heading<%= head[cellindex][:visually_hidden] ? " app-c-table__duplicate-heading--visually-hidden" : "" %>" aria-hidden="true">
<%= head[cellindex][:text] %>
</span>
<%= cell[:text] %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/users/applications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
head: [
{ text: "Name" },
{ text: "Description" },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden") },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden"), visually_hidden: true },
],
rows: @applications_with_signin.map do |application|
[
Expand All @@ -48,14 +48,15 @@
},
]
end,
vertical_on_small_screen: true,
} %>
<%= render "components/table", {
caption: "Apps #{@user.name} does not have access to",
head: [
{ text: "Name" },
{ text: "Description" },
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden") }
{ text: content_tag(:span, "Actions", class: "govuk-visually-hidden"), visually_hidden: true }
],
rows: @applications_without_signin.map do |application|
[
Expand All @@ -64,4 +65,5 @@
{ text: wrap_links_in_actions_markup([users_applications_grant_access_link(application, @user)]) }
]
end,
vertical_on_small_screen: true,
} %>
24 changes: 12 additions & 12 deletions test/controllers/account/applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "form[action='#{account_application_signin_permission_path(application)}']"
end

Expand All @@ -46,7 +46,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{delete_account_application_signin_permission_path(application)}']"
end

Expand All @@ -57,7 +57,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{edit_account_application_permissions_path(application)}']"
end

Expand All @@ -68,7 +68,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{edit_account_application_permissions_path(application)}']", count: 0
end

Expand All @@ -78,7 +78,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "retired-app-name", count: 0
assert_select "tr td", text: /retired-app-name/, count: 0
end

should "not display an API-only application" do
Expand All @@ -87,7 +87,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "api-only-app-name", count: 0
assert_select "tr td", text: /api-only-app-name/, count: 0
end
end

Expand All @@ -102,7 +102,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "form[action='#{account_application_signin_permission_path(@application)}']", count: 0
end

Expand All @@ -116,7 +116,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{delete_account_application_signin_permission_path(@application)}']"
end

Expand All @@ -127,7 +127,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{edit_account_application_permissions_path(@application)}']"
end

Expand All @@ -136,7 +136,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{edit_account_application_permissions_path(@application)}']", count: 0
end

Expand All @@ -150,7 +150,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{delete_account_application_signin_permission_path(@application)}']", count: 0
end

Expand All @@ -159,7 +159,7 @@ class Account::ApplicationsControllerTest < ActionController::TestCase

get :index

assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
assert_select "a[href='#{account_application_permissions_path(@application)}']"
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api_users/applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ApiUsers::ApplicationsControllerTest < ActionController::TestCase
get :index, params: { api_user_id: api_user }

assert_select "table:has( > caption[text()='Apps #{api_user.name} has access to'])" do
assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
end
end

Expand All @@ -54,7 +54,7 @@ class ApiUsers::ApplicationsControllerTest < ActionController::TestCase

get :index, params: { api_user_id: api_user }

assert_select "tr td", text: "revoked-app-name", count: 0
assert_select "tr td", text: /revoked-app-name/, count: 0
end

should "not display a retired application" do
Expand All @@ -70,7 +70,7 @@ class ApiUsers::ApplicationsControllerTest < ActionController::TestCase

get :index, params: { api_user_id: api_user }

assert_select "tr td", text: "retired-app-name", count: 0
assert_select "tr td", text: /retired-app-name/, count: 0
end

should "display a flash message showing the permissions the user has" do
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/users/applications_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Users::ApplicationsControllerTest < ActionController::TestCase
get :index, params: { user_id: user }

assert_select "table:has( > caption[text()='Apps #{user.name} has access to'])" do
assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
end
end

Expand All @@ -94,7 +94,7 @@ class Users::ApplicationsControllerTest < ActionController::TestCase
get :index, params: { user_id: user }

assert_select "table:has( > caption[text()='Apps #{user.name} does not have access to'])" do
assert_select "tr td", text: "app-name"
assert_select "tr td", text: /app-name/
end
end

Expand Down Expand Up @@ -232,7 +232,7 @@ class Users::ApplicationsControllerTest < ActionController::TestCase

get :index, params: { user_id: user }

assert_select "tr td", text: "retired-app-name", count: 0
assert_select "tr td", text: /retired-app-name/, count: 0
end

should "not display an API-only application" do
Expand All @@ -247,7 +247,7 @@ class Users::ApplicationsControllerTest < ActionController::TestCase

get :index, params: { user_id: user }

assert_select "tr td", text: "api-only-app-name", count: 0
assert_select "tr td", text: /api-only-app-name/, count: 0
end
end

Expand Down

0 comments on commit d1dc9ef

Please sign in to comment.