Browse Source

Move clear search, pass search when filtering

pull/1999/head
Kat 3 years ago
parent
commit
dfe2475031
  1. 3
      app/components/search_component.html.erb
  2. 2
      app/components/search_result_caption_component.html.erb
  3. 3
      app/components/search_result_caption_component.rb
  4. 4
      app/views/locations/_location_filters.html.erb
  5. 2
      app/views/locations/index.html.erb
  6. 4
      app/views/logs/_log_filters.html.erb
  7. 2
      app/views/logs/_log_list.html.erb
  8. 2
      app/views/organisation_relationships/_managing_agent_list.erb
  9. 2
      app/views/organisation_relationships/_stock_owner_list.erb
  10. 2
      app/views/organisations/_organisation_list.html.erb
  11. 4
      app/views/schemes/_scheme_filters.html.erb
  12. 2
      app/views/schemes/_scheme_list.html.erb
  13. 5
      app/views/users/_user_filters.html.erb
  14. 2
      app/views/users/_user_list.html.erb
  15. 3
      spec/components/search_result_caption_component_spec.rb
  16. 6
      spec/features/lettings_log_spec.rb
  17. 6
      spec/features/sales_log_spec.rb
  18. 12
      spec/features/schemes_spec.rb
  19. 6
      spec/features/user_spec.rb
  20. 5
      spec/requests/organisations_controller_spec.rb

3
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" %>
</div>
<% end %>

2
app/components/search_result_caption_component.html.erb

@ -1,6 +1,6 @@
<span class="govuk-!-margin-right-4">
<% if searched.present? %>
<strong><%= count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total <%= item %>. <%= govuk_link_to("Clear search", path) %>
<strong><%= count %></strong> <%= item_label %> found matching ‘<%= searched %>’ of <strong><%= total_count %></strong> total <%= item %>.
<% else %>
<strong><%= count %></strong> total <%= item %>
<% end %>

3
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

4
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 %>
</div>

2
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| %>

4
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 %>
</div>

2
app/views/logs/_log_list.html.erb

@ -1,7 +1,7 @@
<h2 class="govuk-body">
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<%= 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? %>

2
app/views/organisation_relationships/_managing_agent_list.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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| %>

2
app/views/organisation_relationships/_stock_owner_list.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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| %>

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

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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| %>

4
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 %>
</div>

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

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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| %>

5
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 %>
</div>

2
app/views/users/_user_list.html.erb

@ -1,7 +1,7 @@
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>">
<%= 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" %>

3
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("<span class=\"govuk-!-margin-right-4\">\n <strong>#{count}</strong> #{item_label} found matching ‘#{searched}’ of <strong>#{total_count}</strong> total #{item}. <a class=\"govuk-link\" href=\"path\">Clear search</a>\n</span>\n")
expect(result.to_html).to eq("<span class=\"govuk-!-margin-right-4\">\n <strong>#{count}</strong> #{item_label} found matching ‘#{searched}’ of <strong>#{total_count}</strong> total #{item}.\n")
end
context "when no search results are found" do

6
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

6
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

12
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

6
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

5
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)

Loading…
Cancel
Save