diff --git a/app/components/search_component.html.erb b/app/components/search_component.html.erb index 2c10f3ed8..9c989f0f0 100644 --- a/app/components/search_component.html.erb +++ b/app/components/search_component.html.erb @@ -10,6 +10,7 @@ autocomplete: "off", class: "app-search__input" %> - <%= f.govuk_submit "Search", classes: "app-search__button govuk-button--secondary" %> + <%= f.govuk_submit "Search", classes: "app-search__button" %> + <%= govuk_button_link_to "Clear search", path(current_user), secondary: true, class: "app-search__button" %> <% end %> diff --git a/app/components/search_result_caption_component.html.erb b/app/components/search_result_caption_component.html.erb index f2a553828..0053e7ae5 100644 --- a/app/components/search_result_caption_component.html.erb +++ b/app/components/search_result_caption_component.html.erb @@ -1,6 +1,6 @@ <% if searched.present? %> - <%= count %> <%= item_label %> found matching ‘<%= searched %>’ of <%= total_count %> total <%= item %>. <%= govuk_link_to("Clear search", path) %> + <%= count %> <%= item_label %> found matching ‘<%= searched %>’ of <%= total_count %> total <%= item %>. <% else %> <%= count %> total <%= item %> <% end %> diff --git a/app/components/search_result_caption_component.rb b/app/components/search_result_caption_component.rb index 8565c125d..2aa7a5ad2 100644 --- a/app/components/search_result_caption_component.rb +++ b/app/components/search_result_caption_component.rb @@ -1,13 +1,12 @@ class SearchResultCaptionComponent < ViewComponent::Base attr_reader :searched, :count, :item_label, :total_count, :item, :path - def initialize(searched:, count:, item_label:, total_count:, item:, path:) + def initialize(searched:, count:, item_label:, total_count:, item:) @searched = searched @count = count @item_label = item_label @total_count = total_count @item = item - @path = path super end end diff --git a/app/views/locations/_location_filters.html.erb b/app/views/locations/_location_filters.html.erb index d5bdeb156..f7d3c3e96 100644 --- a/app/views/locations/_location_filters.html.erb +++ b/app/views/locations/_location_filters.html.erb @@ -23,6 +23,10 @@ category: "status", } %> + <% if request.params["search"].present? %> + <%= f.hidden_field :search, value: request.params["search"] %> + <% end %> + <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <% end %> diff --git a/app/views/locations/index.html.erb b/app/views/locations/index.html.erb index ac6e3a0df..79cad8330 100644 --- a/app/views/locations/index.html.erb +++ b/app/views/locations/index.html.erb @@ -24,7 +24,7 @@ <%= govuk_table do |table| %> <%= table.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", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched: @searched, count: @pagy.count, item_label:, total_count: @total_count, item: "locations")) %> <% end %> <%= table.head do |head| %> <%= head.row do |row| %> diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index 589fb40ba..9ce94c2e1 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -113,6 +113,10 @@ } %> <% end %> + <% if request.params["search"].present? %> + <%= f.hidden_field :search, value: request.params["search"] %> + <% end %> + <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <% end %> diff --git a/app/views/logs/_log_list.html.erb b/app/views/logs/_log_list.html.erb index 6b9e30bfc..0c97e353a 100644 --- a/app/views/logs/_log_list.html.erb +++ b/app/views/logs/_log_list.html.erb @@ -1,7 +1,7 @@

- <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs")) %> <% if logs&.any? %> <%= govuk_link_to "Download (CSV)", csv_download_url, type: "text/csv", class: "govuk-!-margin-right-4" %> <% if @current_user.support? %> diff --git a/app/views/organisation_relationships/_managing_agent_list.erb b/app/views/organisation_relationships/_managing_agent_list.erb index 65195033c..050827eaf 100644 --- a/app/views/organisation_relationships/_managing_agent_list.erb +++ b/app/views/organisation_relationships/_managing_agent_list.erb @@ -1,7 +1,7 @@
<%= govuk_table do |table| %> <%= 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: "agents", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "agents")) %> <% end %> <% @managing_agents.each do |managing_agent| %> <%= table.body do |body| %> diff --git a/app/views/organisation_relationships/_stock_owner_list.erb b/app/views/organisation_relationships/_stock_owner_list.erb index 0120c553b..12ea2cd7d 100644 --- a/app/views/organisation_relationships/_stock_owner_list.erb +++ b/app/views/organisation_relationships/_stock_owner_list.erb @@ -1,7 +1,7 @@
<%= govuk_table do |table| %> <%= 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: "stock owners", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "stock owners")) %> <% end %> <% @stock_owners.each do |stock_owner| %> <%= table.body do |body| %> diff --git a/app/views/organisations/_organisation_list.html.erb b/app/views/organisations/_organisation_list.html.erb index 6a68433be..d93915de8 100644 --- a/app/views/organisations/_organisation_list.html.erb +++ b/app/views/organisations/_organisation_list.html.erb @@ -1,7 +1,7 @@
<%= govuk_table do |table| %> <%= 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: "organisations", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "organisations")) %> <% end %> <%= table.head do |head| %> <%= head.row do |row| %> diff --git a/app/views/schemes/_scheme_filters.html.erb b/app/views/schemes/_scheme_filters.html.erb index e723f7469..80bd85cc8 100644 --- a/app/views/schemes/_scheme_filters.html.erb +++ b/app/views/schemes/_scheme_filters.html.erb @@ -43,6 +43,10 @@ } %> <% end %> + <% if request.params["search"].present? %> + <%= f.hidden_field :search, value: request.params["search"] %> + <% end %> + <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <% end %>
diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb index eefa10589..3ca1e5f81 100644 --- a/app/views/schemes/_scheme_list.html.erb +++ b/app/views/schemes/_scheme_list.html.erb @@ -1,7 +1,7 @@
<%= govuk_table do |table| %> <%= 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: "schemes", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "schemes")) %> <% end %> <%= table.head do |head| %> <%= head.row do |row| %> diff --git a/app/views/users/_user_filters.html.erb b/app/views/users/_user_filters.html.erb index 41280b3ae..c805cd60a 100644 --- a/app/views/users/_user_filters.html.erb +++ b/app/views/users/_user_filters.html.erb @@ -22,6 +22,11 @@ label: "Status", category: "status", } %> + + <% if request.params["search"].present? %> + <%= f.hidden_field :search, value: request.params["search"] %> + <% end %> + <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <% end %>
diff --git a/app/views/users/_user_list.html.erb b/app/views/users/_user_list.html.erb index 100f45929..c21e74f62 100644 --- a/app/views/users/_user_list.html.erb +++ b/app/views/users/_user_list.html.erb @@ -1,7 +1,7 @@
<%= govuk_table do |table| %> <%= 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: "users", path: request.path)) %> + <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "users")) %> <% if current_user.support? %> <% query = searched.present? ? "?search=#{searched}" : nil %> <%= govuk_link_to "Download (CSV)", "#{request.path}.csv#{query}", type: "text/csv" %> diff --git a/spec/components/search_result_caption_component_spec.rb b/spec/components/search_result_caption_component_spec.rb index ed4934633..2f1a55282 100644 --- a/spec/components/search_result_caption_component_spec.rb +++ b/spec/components/search_result_caption_component_spec.rb @@ -6,11 +6,10 @@ RSpec.describe SearchResultCaptionComponent, type: :component do let(:item_label) { "user" } let(:total_count) { 3 } let(:item) { "schemes" } - let(:path) { "path" } it "renders table caption including the search results and total" do result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) - expect(result.to_html).to eq("\n #{count} #{item_label} found matching ‘#{searched}’ of #{total_count} total #{item}. Clear search\n\n") + expect(result.to_html).to eq("\n #{count} #{item_label} found matching ‘#{searched}’ of #{total_count} total #{item}.\n") end context "when no search results are found" do diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index 872174ca4..5790ed1f6 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -79,7 +79,7 @@ RSpec.describe "Lettings Log Features" do context "when no filters are selected" do it "displays the filters component with no clear button" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs") end end @@ -97,7 +97,7 @@ RSpec.describe "Lettings Log Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("5 filters applied") - expect(page).to have_content("Clear") + expect(page).to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs") end context "when clearing the filters" do @@ -107,7 +107,7 @@ RSpec.describe "Lettings Log Features" do it "clears the filters and displays the filter component as before" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs") end end end diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index 9c3fb721e..9e12082a7 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -108,7 +108,7 @@ RSpec.describe "Sales Log Features" do context "when no filters are selected" do it "displays the filters component with no clear button" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=sales_logs") end end @@ -122,7 +122,7 @@ RSpec.describe "Sales Log Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("3 filters applied") - expect(page).to have_content("Clear") + expect(page).to have_link("Clear", href: "/clear-filters?filter_type=sales_logs") end context "when clearing the filters" do @@ -132,7 +132,7 @@ RSpec.describe "Sales Log Features" do it "clears the filters and displays the filter component as before" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=sales_logs") end end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index b293171d6..02003e313 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -68,7 +68,7 @@ RSpec.describe "Schemes scheme Features" do context "when no filters are selected" do it "displays the filters component with no clear button" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=schemes") end end @@ -81,7 +81,7 @@ RSpec.describe "Schemes scheme Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_content("Clear") + expect(page).to have_link("Clear", href: "/clear-filters?filter_type=schemes") end context "when clearing the filters" do @@ -91,7 +91,7 @@ RSpec.describe "Schemes scheme Features" do it "clears the filters and displays the filter component as before" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=schemes") end end end @@ -292,7 +292,7 @@ RSpec.describe "Schemes scheme Features" do context "when no filters are selected" do it "displays the filters component with no clear button" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/) end end @@ -305,7 +305,7 @@ RSpec.describe "Schemes scheme Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_content("Clear") + expect(page).to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/) end context "when clearing the filters" do @@ -315,7 +315,7 @@ RSpec.describe "Schemes scheme Features" do it "clears the filters and displays the filter component as before" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/) end end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index d657ea3dc..39327a75a 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -233,7 +233,7 @@ RSpec.describe "User Features" do context "when no filters are selected" do it "displays the filters component with no clear button" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users") end end @@ -246,7 +246,7 @@ RSpec.describe "User Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_content("Clear") + expect(page).to have_link("Clear", href: "/clear-filters?filter_type=users") end context "when clearing the filters" do @@ -256,7 +256,7 @@ RSpec.describe "User Features" do it "clears the filters and displays the filter component as before" do expect(page).to have_content("No filters applied") - expect(page).not_to have_content("Clear") + expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users") end end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index cbc5a7f49..36ee01437 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -784,6 +784,11 @@ RSpec.describe OrganisationsController, type: :request do expect(page).to have_title("#{organisation.name} (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") end + it "has search term in the search box" do + get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {} + expect(page).to have_field("search", with: log_to_search.id.to_s) + end + it "shows lettings logs matching the id" do get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {} expect(page).to have_link(log_to_search.id.to_s)