From a4a83908ae251347128d4fa5bb2b82c2b645fa34 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:48:29 +0100 Subject: [PATCH] Refactor locations/index page (#2523) --- app/helpers/tab_nav_helper.rb | 10 ++++++++- app/views/locations/index.html.erb | 34 +++++++++++------------------ spec/helpers/tab_nav_helper_spec.rb | 5 ++--- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 27542094d..6ed9fe2ab 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -7,7 +7,15 @@ module TabNavHelper [govuk_link_to(link_text, user), "User #{user.email}"].join("\n") end - def location_cell_postcode(location, link) + def location_cell_postcode(location, scheme) + link = if location.confirmed + scheme_location_path(scheme, location) + elsif location.postcode.present? + scheme_location_check_answers_path(scheme, location, route: "locations") + else + scheme_location_postcode_path(scheme, location) + end + link_text = location.postcode || "Add postcode" [govuk_link_to(link_text, link, method: :patch), "Location"].join("\n") end diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index 88b17321e..78a362332 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -16,46 +16,38 @@ <%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
- <%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id)) %> - <%= render partial: "locations/location_filters" %>

Locations

<%= render SearchComponent.new(current_user:, search_label: "Search by location name or postcode", value: @searched) %> - <%= govuk_section_break(visible: true, size: "m") %> <%= govuk_table do |table| %> <%= table.with_caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> - <%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations", filters_count: applied_filters_count(@filter_type))) %> + <%= render(SearchResultCaptionComponent.new( + searched: @searched, + count: @pagy.count, + item_label:, + total_count: @total_count, + item: "locations", + filters_count: applied_filters_count(@filter_type), + )) %> <% end %> <%= table.with_head do |head| %> <%= head.with_row do |row| %> - <% row.with_cell(header: true, text: "Postcode", html_attributes: { - scope: "col", - }) %> - <% row.with_cell(header: true, text: "Name", html_attributes: { - scope: "col", - }) %> - <% row.with_cell(header: true, text: "Location code", html_attributes: { - scope: "col", - }) %> - <% row.with_cell(header: true, text: "Status", html_attributes: { - scope: "col", - }) %> + <% row.with_cell(header: true, text: "Postcode", html_attributes: { scope: "col" }) %> + <% row.with_cell(header: true, text: "Name", html_attributes: { scope: "col" }) %> + <% row.with_cell(header: true, text: "Location code", html_attributes: { scope: "col" }) %> + <% row.with_cell(header: true, text: "Status", html_attributes: { scope: "col" }) %> <% end %> <% end %> <% @locations.each do |location| %> <%= table.with_body do |body| %> <%= body.with_row do |row| %> - <% row.with_cell(text: simple_format(location_cell_postcode(location, if location.confirmed - scheme_location_path(@scheme, location) - else - location.postcode.present? ? scheme_location_check_answers_path(@scheme, location, route: "locations") : scheme_location_postcode_path(@scheme, location) - end), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> + <% row.with_cell(text: simple_format(location_cell_postcode(location, @scheme), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.with_cell(text: location.name) %> <% row.with_cell(text: location.id) %> <% row.with_cell(text: status_tag_from_resource(location)) %> diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index 9dbf92e7a..173a58b54 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/spec/helpers/tab_nav_helper_spec.rb @@ -22,9 +22,8 @@ RSpec.describe TabNavHelper do describe "#location_cell" do it "returns the location link to the postcode with optional name" do - link = "/schemes/#{location.scheme.id}/locations/#{location.id}/edit" - expected_html = "#{location.postcode}\nLocation" - expect(location_cell_postcode(location, link)).to match(expected_html) + expected_html = "#{location.postcode}\nLocation" + expect(location_cell_postcode(location, scheme)).to match(expected_html) end end