From b04a8b6a74c14912d05f50de3875727dc8e74d73 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 19 Oct 2022 10:48:43 +0100 Subject: [PATCH] feat: add correct search behaviour, refactor and update linking --- app/components/search_component.rb | 2 ++ app/controllers/housing_providers_controller.rb | 4 ++-- app/controllers/organisations_controller.rb | 5 +++-- app/helpers/navigation_items_helper.rb | 2 +- .../housing_providers/_housing_provider_list.html.erb | 6 +++--- app/views/housing_providers/index.html.erb | 6 +++--- app/views/organisations/housing_providers.html.erb | 7 +++---- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/components/search_component.rb b/app/components/search_component.rb index 035500b54..23b5ea65e 100644 --- a/app/components/search_component.rb +++ b/app/components/search_component.rb @@ -15,6 +15,8 @@ class SearchComponent < ViewComponent::Base request.path elsif request.path.include?("organisations") && request.path.include?("schemes") request.path + elsif request.path.include?("organisations") && request.path.include?("housing-providers") + request.path elsif request.path.include?("users") user_path(current_user) elsif request.path.include?("organisations") diff --git a/app/controllers/housing_providers_controller.rb b/app/controllers/housing_providers_controller.rb index edfe40ff2..b3a014ada 100644 --- a/app/controllers/housing_providers_controller.rb +++ b/app/controllers/housing_providers_controller.rb @@ -4,7 +4,7 @@ class HousingProvidersController < ApplicationController def index housing_providers = - Organisation.joins(:child_organisations) + Organisation.joins(:child_organisation_relationships) .where(organisation_relationships: { child_organisation_id: current_user.organisation_id, relationship_type: OrganisationRelationship.relationship_types[:owning], @@ -12,7 +12,7 @@ class HousingProvidersController < ApplicationController .order(:name) respond_to do |format| format.html do - @pagy, @organisations = pagy(filtered_collection(housing_providers, search_term)) + @pagy, @housing_providers = pagy(filtered_collection(housing_providers, search_term)) @searched = search_term.presence @total_count = housing_providers.size render "housing_providers/index" diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 1d00dd31b..ccc3f65b3 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -137,15 +137,16 @@ class OrganisationsController < ApplicationController def housing_providers housing_providers = - Organisation.joins(:child_organisations) + Organisation.joins(:child_organisation_relationships) .where(organisation_relationships: { child_organisation_id: @organisation.id, relationship_type: OrganisationRelationship.relationship_types[:owning], }) .order(:name) + unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) respond_to do |format| format.html do - @pagy, @organisations = pagy(filtered_collection(housing_providers, search_term)) + @pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) @searched = search_term.presence @total_count = housing_providers.size render "housing_providers", layout: "application" diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 961a94cc0..b908c8a5b 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -24,7 +24,7 @@ module NavigationItemsHelper FeatureToggle.sales_log_enabled? ? NavigationItem.new("Sales logs", sales_logs_path, sales_logs_current?(path)) : nil, NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), - NavigationItem.new("Housing providers", "/housing-providers", housing_providers_current?(path)), + NavigationItem.new("Housing providers", housing_providers_path, housing_providers_current?(path)), ].compact end end diff --git a/app/views/housing_providers/_housing_provider_list.html.erb b/app/views/housing_providers/_housing_provider_list.html.erb index 68a40c16b..b2bb9ba75 100644 --- a/app/views/housing_providers/_housing_provider_list.html.erb +++ b/app/views/housing_providers/_housing_provider_list.html.erb @@ -3,15 +3,15 @@ <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %> <% end %> - <% @organisations.each do |organisation| %> + <% @housing_providers.each do |housing_provider| %> <%= table.body do |body| %> <%= body.row do |row| %> - <% row.cell(text: organisation.name) %> + <% row.cell(text: housing_provider.name) %> <% if current_user.data_coordinator? || current_user.support? %> <% row.cell(html_attributes: { scope: "row", }) do %> - <%= govuk_link_to("Remove", "housing-providers/#{organisation.id}") %> + <%= govuk_link_to("Remove", "housing-providers/#{housing_provider.id}") %> <% end %> <% end %> <% end %> diff --git a/app/views/housing_providers/index.html.erb b/app/views/housing_providers/index.html.erb index 50a2d3d95..3c7e007e5 100644 --- a/app/views/housing_providers/index.html.erb +++ b/app/views/housing_providers/index.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "organisation") %> +<% item_label = format_label(@pagy.count, "housing provider") %> <% title = "Housing Providers" %> <% content_for :title, title %> @@ -20,8 +20,8 @@ <%= govuk_section_break(visible: true, size: "m") %> - <%= render partial: "housing_providers/housing_provider_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> - <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> + <%= render partial: "housing_providers/housing_provider_list", locals: { housing_providers: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> <% end %> diff --git a/app/views/organisations/housing_providers.html.erb b/app/views/organisations/housing_providers.html.erb index 9a1a3d538..242da0466 100644 --- a/app/views/organisations/housing_providers.html.erb +++ b/app/views/organisations/housing_providers.html.erb @@ -1,4 +1,4 @@ -<% item_label = format_label(@pagy.count, "organisation") %> +<% item_label = format_label(@pagy.count, "housing provider") %> <% title = "Housing Providers" %> <% content_for :title, title %> @@ -22,12 +22,11 @@ <%= govuk_button_link_to "Add a housing provider", new_housing_provider_path(organisation_id: @organisation.id), html: { method: :get } %> <% end %> - <% if @total_count != 0 %> <%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> <%= govuk_section_break(visible: true, size: "m") %> - <%= render partial: "housing_providers/housing_provider_list", locals: { organisations: @organisations, title: "Organisations", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> - <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "organisations" } %> + <%= render partial: "housing_providers/housing_provider_list", locals: { housing_providers: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> + <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> <% end %>