Skip to content

Commit

Permalink
Bugfix: retain the search scope and query terms in the search form on…
Browse files Browse the repository at this point in the history
… a search results page. Fixes #1503
  • Loading branch information
seanaery committed Dec 18, 2023
1 parent 7922386 commit c1a234f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/components/arclight/search_bar_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%= render(Blacklight::SearchBarComponent.new(
**@kwargs,
params: @params.merge(f: (@params[:f] || {}).except(:collection)))) do |c| %>
params: @params.merge(f: (@params[:f] || {}).except(:collection)),
q: @q,
search_field: @search_field)) do |c| %>
<% c.with_before_input_group do %>
<div class="input-group within-collection-dropdown">
Expand Down
2 changes: 1 addition & 1 deletion app/components/arclight/search_bar_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def within_collection_options
end

def collection_name
@collection_name ||= Array(@params.dig(:f, :collection)).first ||
@collection_name ||= Array(@params.dig(:f, :collection)).reject(&:empty?).first ||
helpers.current_context_document&.collection_name
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/features/fielded_search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@
end
end
end

describe 'search box scope retention' do
it 'retains the selected field on the search results page' do
visit search_catalog_path q: 'root', search_field: 'name'
expect(page).to have_select 'search_field', selected: 'Name'
end
end
end
5 changes: 5 additions & 0 deletions spec/features/search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
expect(page).to have_css '.index_title', text: /A brief account/
end

it 'retains the search query in the search box' do
visit search_catalog_path q: 'papers', search_field: 'all_fields'
expect(page).to have_css 'input#q[value="papers"]'
end

it 'renders the expected metadata for a collection' do
visit search_catalog_path q: '', search_field: 'all_fields'

Expand Down

0 comments on commit c1a234f

Please sign in to comment.