From 75c4fb218d3631197feb96553f1b6aa8bb5e822d Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:09:21 +0100 Subject: [PATCH] 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 --- app/controllers/organisations_controller.rb | 2 +- app/controllers/schemes_controller.rb | 2 +- app/frontend/styles/_table-group.scss | 9 ++++--- app/models/scheme.rb | 11 +++++---- app/views/organisations/schemes.html.erb | 2 +- app/views/schemes/_scheme_list.html.erb | 8 ++++--- app/views/schemes/index.html.erb | 2 +- spec/features/schemes_spec.rb | 4 ++-- .../requests/organisations_controller_spec.rb | 22 ++++++++++------- spec/requests/schemes_controller_spec.rb | 24 ++++++++++++------- 10 files changed, 50 insertions(+), 36 deletions(-) diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index a45b4a66f..ff64c6136 100644 --- a/app/controllers/organisations_controller.rb +++ b/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" diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 3b1c5dc8a..8cf824af9 100644 --- a/app/controllers/schemes_controller.rb +++ b/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" diff --git a/app/frontend/styles/_table-group.scss b/app/frontend/styles/_table-group.scss index c5ca328f3..03ba07d2b 100644 --- a/app/frontend/styles/_table-group.scss +++ b/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"); diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 19a6491fd..63632b55f 100644 --- a/app/models/scheme.rb +++ b/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 diff --git a/app/views/organisations/schemes.html.erb b/app/views/organisations/schemes.html.erb index 20fc40886..37bc7ba44 100644 --- a/app/views/organisations/schemes.html.erb +++ b/app/views/organisations/schemes.html.erb @@ -23,7 +23,7 @@ ) %> <%= render partial: "schemes/scheme_filters" %>
- <%= 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) %>
diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb index 43e03cd65..eefa10589 100644 --- a/app/views/schemes/_scheme_list.html.erb +++ b/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)) %> diff --git a/app/views/schemes/index.html.erb b/app/views/schemes/index.html.erb index a1c2041ff..4f3218e7a 100644 --- a/app/views/schemes/index.html.erb +++ b/app/views/schemes/index.html.erb @@ -11,7 +11,7 @@
<%= render partial: "schemes/scheme_filters" %>
- <%= 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) %>
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 569a7af03..b293171d6 100644 --- a/spec/features/schemes_spec.rb +++ b/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 diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 91eb591e7..f4b802f2e 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/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 diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 9579fb2a4..61fcd207d 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/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