Browse Source

CLDC-2627 Update scheme table styling and labels (#1972)

* Update scheme table styling and labels

* Order schemes alphabeticlly only

* Wrap scheme names

* Refactor and udpate scopes

* indentation

* Break scheme name
pull/1959/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
75c4fb218d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/organisations_controller.rb
  2. 2
      app/controllers/schemes_controller.rb
  3. 9
      app/frontend/styles/_table-group.scss
  4. 11
      app/models/scheme.rb
  5. 2
      app/views/organisations/schemes.html.erb
  6. 8
      app/views/schemes/_scheme_list.html.erb
  7. 2
      app/views/schemes/index.html.erb
  8. 4
      spec/features/schemes_spec.rb
  9. 22
      spec/requests/organisations_controller_spec.rb
  10. 24
      spec/requests/schemes_controller_spec.rb

2
app/controllers/organisations_controller.rb

@ -23,7 +23,7 @@ class OrganisationsController < ApplicationController
def schemes
all_schemes = Scheme.where(owning_organisation: [@organisation] + @organisation.parent_organisations)
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_completion.order_by_service_name)
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_service_name)
@searched = search_term.presence
@total_count = all_schemes.size
@filter_type = "schemes"

2
app/controllers/schemes_controller.rb

@ -15,7 +15,7 @@ class SchemesController < ApplicationController
redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
all_schemes = Scheme.all
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_completion.order_by_service_name)
@pagy, @schemes = pagy(filter_manager.filtered_schemes(all_schemes, search_term, session_filters).order_by_service_name)
@searched = search_term.presence
@total_count = all_schemes.size
@filter_type = "schemes"

9
app/frontend/styles/_table-group.scss

@ -9,11 +9,6 @@
margin-bottom: -1px;
}
.govuk-table__header,
.govuk-table__cell {
white-space: nowrap;
}
&::-webkit-scrollbar {
height: govuk-spacing(1);
width: govuk-spacing(1);
@ -28,6 +23,10 @@
}
}
.scheme-name-cell {
word-break: break-all;
}
.app-table-group:focus {
box-shadow: 0 0 0 #{$govuk-focus-width * 2} $govuk-focus-colour;
outline: $govuk-focus-width solid govuk-colour("black");

11
app/models/scheme.rb

@ -8,17 +8,18 @@ class Scheme < ApplicationRecord
scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { left_joins(:locations).where("REPLACE(locations.postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }
scope :search_by_location_name, ->(name) { left_joins(:locations).where("locations.name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE REPLACE(locations.postcode, ' ', '') ILIKE ?)", "%#{postcode.delete(' ')}%") }
scope :search_by_location_name, ->(name) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE locations.name ILIKE ?)", "%#{name}%") }
scope :search_by, lambda { |param|
search_by_postcode(param)
.or(search_by_service_name(param))
.or(search_by_location_name(param))
.or(filter_by_id(param)).distinct
.or(filter_by_id(param))
}
scope :order_by_completion, -> { order("schemes.confirmed ASC NULLS FIRST") }
scope :order_by_service_name, -> { order(service_name: :asc) }
scope :order_by_service_name, lambda {
order("lower(service_name) ASC")
}
scope :filter_by_owning_organisation, ->(owning_organisation, _user = nil) { where(owning_organisation:) }
scope :filter_by_status, lambda { |statuses, _user = nil|
filtered_records = all

2
app/views/organisations/schemes.html.erb

@ -23,7 +23,7 @@
) %>
<%= render partial: "schemes/scheme_filters" %>
<div class="app-filter-layout__content">
<%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %>
<%= render SearchComponent.new(current_user:, search_label: "Search by postcode, scheme name, scheme code or location name", value: @searched) %>
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m">

8
app/views/schemes/_scheme_list.html.erb

@ -5,8 +5,9 @@
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Scheme", html_attributes: { scope: "col" }) %>
<% row.cell(header: true, text: "Code", html_attributes: { scope: "col" }) %>
<% row.cell(header: true, text: "Scheme", html_attributes: { scope: "col", class: "govuk-!-width-one-quarter" }) %>
<% row.cell(header: true, text: "Stock owner", html_attributes: { scope: "col" }) %>
<% row.cell(header: true, text: "Scheme code", html_attributes: { scope: "col" }) %>
<% row.cell(header: true, text: "Locations", html_attributes: { scope: "col" }) %>
<% row.cell(header: true, text: "Status", html_attributes: { scope: "col" }) %>
<% end %>
@ -14,7 +15,8 @@
<% @schemes.each do |scheme| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: simple_format(scheme_cell(scheme), { class: "govuk-!-font-weight-bold scheme-name-cell" }, wrapper_tag: "div")) %>
<% row.cell(text: scheme.owning_organisation&.name) %>
<% row.cell(text: scheme.id_to_display) %>
<% row.cell(text: scheme.locations&.count) %>
<% row.cell(text: status_tag_from_resource(scheme)) %>

2
app/views/schemes/index.html.erb

@ -11,7 +11,7 @@
<div class="app-filter-layout" data-controller="filter-layout">
<%= render partial: "schemes/scheme_filters" %>
<div class="app-filter-layout__content">
<%= render SearchComponent.new(current_user:, search_label: "Search by scheme name, code, postcode or location name", value: @searched) %>
<%= render SearchComponent.new(current_user:, search_label: "Search by postcode, scheme name, scheme code or location name", value: @searched) %>
<hr class="govuk-section-break govuk-section-break--visible govuk-section-break--m">

4
spec/features/schemes_spec.rb

@ -34,7 +34,7 @@ RSpec.describe "Schemes scheme Features" do
context "when I search for a specific scheme" do
it "there is a search bar with a message and search button for schemes" do
expect(page).to have_field("search")
expect(page).to have_content("Search by scheme name, code, postcode or location name")
expect(page).to have_content("Search by postcode, scheme name, scheme code or location name")
expect(page).to have_button("Search")
end
@ -142,7 +142,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays a search bar" do
expect(page).to have_field("search")
expect(page).to have_content("Search by scheme name, code, postcode or location name")
expect(page).to have_content("Search by postcode, scheme name, scheme code or location name")
expect(page).to have_button("Search")
end

22
spec/requests/organisations_controller_spec.rb

@ -123,15 +123,21 @@ RSpec.describe OrganisationsController, type: :request do
end
end
it "shows incomplete schemes at the top" do
schemes[0].update!(confirmed: nil, owning_organisation: user.organisation)
schemes[2].update!(confirmed: false, owning_organisation: user.organisation)
schemes[4].update!(confirmed: false, owning_organisation: user.organisation)
it "shows schemes in alpabetical order" do
schemes[0].update!(service_name: "aaa", owning_organisation: user.organisation)
schemes[1].update!(service_name: "daa", owning_organisation: user.organisation)
schemes[2].update!(service_name: "baa", owning_organisation: user.organisation)
schemes[3].update!(service_name: "Faa", owning_organisation: user.organisation)
schemes[4].update!(service_name: "Caa", owning_organisation: user.organisation)
get "/organisations/#{organisation.id}/schemes", headers:, params: {}
expect(page.all(".govuk-tag")[1].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[2].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[3].text).to eq("Incomplete")
all_links = page.all(".govuk-link")
scheme_links = all_links.select { |link| link[:href] =~ %r{^/schemes/\d+$} }
expect(scheme_links[0][:href]).to eq("/schemes/#{schemes[0].id}")
expect(scheme_links[1][:href]).to eq("/schemes/#{schemes[2].id}")
expect(scheme_links[2][:href]).to eq("/schemes/#{schemes[4].id}")
expect(scheme_links[3][:href]).to eq("/schemes/#{schemes[1].id}")
expect(scheme_links[4][:href]).to eq("/schemes/#{schemes[3].id}")
end
context "with schemes that are not in scope for the user, i.e. that they do not belong to" do

24
spec/requests/schemes_controller_spec.rb

@ -201,15 +201,21 @@ RSpec.describe SchemesController, type: :request do
assert_select ".govuk-tag", text: /Incomplete/, count: 1
end
it "shows incomplete schemes at the top" do
schemes[0].update!(confirmed: nil)
schemes[2].update!(confirmed: false)
schemes[4].update!(confirmed: false)
get "/schemes"
expect(page.all(".govuk-tag")[1].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[2].text).to eq("Incomplete")
expect(page.all(".govuk-tag")[3].text).to eq("Incomplete")
it "shows schemes in alpabetical order" do
schemes[0].update!(service_name: "aaa")
schemes[1].update!(service_name: "daa")
schemes[2].update!(service_name: "baa")
schemes[3].update!(service_name: "Faa")
schemes[4].update!(service_name: "Caa")
get "/schemes", headers:, params: {}
all_links = page.all(".govuk-link")
scheme_links = all_links.select { |link| link[:href] =~ %r{^/schemes/\d+$} }
expect(scheme_links[0][:href]).to eq("/schemes/#{schemes[0].id}")
expect(scheme_links[1][:href]).to eq("/schemes/#{schemes[2].id}")
expect(scheme_links[2][:href]).to eq("/schemes/#{schemes[4].id}")
expect(scheme_links[3][:href]).to eq("/schemes/#{schemes[1].id}")
expect(scheme_links[4][:href]).to eq("/schemes/#{schemes[3].id}")
end
it "displays a link to check answers page if the scheme is incomplete" do

Loading…
Cancel
Save