Skip to content

Commit

Permalink
Update 'no results' partial
Browse files Browse the repository at this point in the history
Why these changes are being introduced:

When a search returns no results, the filter sidebar should be
omitted and the 'no results' text should be larger. This change
was requested as part of the GDT project, but it should apply to
all TIMDEX UI apps.

Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/GDT-133
* https://mitlibraries.atlassian.net/browse/GDT-161

How this addresses that need:

Updates the 'no results' text and implements the requested styling
changes. The filter logic changes a bit to hide the sidebar:

* In the search controller, empty aggregations are no longer
extracted from the response.
* In the results view, a few conditionals have been added to hide
the filter sidebar, omit the `layout1q3q` class from the results
wrapper, and render the 'no results' message as a header rather
than a list element.
* If a search returns no results, the pagination partial is
hidden.

Side effects of this change:

* The results view is somewhat less elegant as a result of these
changes.
* A guard clause has been added to `SearchController#extract_filters`
to protect against calling `select` on `nil`. (This can occur if
the API returns errors, in which case it will return no aggregations.)
* The `result_empty` partial has been removed. It is only one line
of HTML that feels more readable inline.
* Development and review of this work revealed accessibility concerns
about the results summary (including the 'no results' message) being
too deep in the tab order. This information should be foregrounded
for screen reader users. I've opened GDT-161 to address this.
  • Loading branch information
jazairi committed Feb 1, 2024
1 parent da85230 commit d2b5a1c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
7 changes: 5 additions & 2 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def results
# The @pagination instance variable includes info about next/previous pages (where they exist) to assist the UI.
@pagination = Analyzer.new(@enhanced_query, response).pagination if @errors.nil?

# Display stuff
# Display results
@results = extract_results(response)
@filters = extract_filters(response)
end
Expand All @@ -30,7 +30,10 @@ def extract_errors(response)
end

def extract_filters(response)
response&.data&.search&.to_h&.dig('aggregations')
aggs = response&.data&.search&.to_h&.dig('aggregations')
return if aggs.blank?

aggs.select { |_, agg_values| agg_values.present? }
end

def extract_results(response)
Expand Down
1 change: 0 additions & 1 deletion app/views/search/_result_empty.html.erb

This file was deleted.

40 changes: 25 additions & 15 deletions app/views/search/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,34 @@

<%= render(partial: 'shared/error', collection: @errors) %>

<div class="layout-1q3q layout-band top-space">
<div class="<%= 'layout-1q3q' if @filters.present? %> layout-band top-space">
<div class="col3q wrap-results">
<ul id="results" class="list-unbulleted">
<%= render(partial: 'search/result', collection: @results) || render('result_empty') %>
</ul>
<% if @results.present? %>
<ul id="results" class="list-unbulleted">
<%= render(partial: 'search/result', collection: @results) %>
</ul>
<% else %>
<div id="results">
<p class="hd-2">No results found for your search</p>
</div>
<% end %>
</div>

<aside class="col1q filter-container">
<div id="filters">
<h2>Available filters</h2>
<% @filters&.each do |category, values| %>
<%= render(partial: 'search/filter', locals: {category: category, values: values}) %>
<% end %>
</div>
</aside>
<% if @filters.present? %>
<aside class="col1q filter-container">
<div id="filters">
<h2>Available filters</h2>
<% @filters&.each do |category, values| %>
<%= render(partial: 'search/filter', locals: {category: category, values: values}) %>
<% end %>
</div>
</aside>
<% end %>
</div>

<div id="pagination">
<%= render partial: "pagination" %>
</div>
<% if @results.present? %>
<div id="pagination">
<%= render partial: "pagination" %>
</div>
<% end %>
</div>
11 changes: 9 additions & 2 deletions test/controllers/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,20 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
match_requests_on: %i[method uri body]) do
get '/results?q=asdfiouwenlasd'
assert_response :success

# Result list contents state "no results"
assert_select '#results'
assert_select '#results', { count: 1 }
assert_select '#results li', 'There are no results.'
assert_select '#results p', 'No results found for your search'

# Filter sidebar is not shown
assert_select '#filters', { count: 0 }

# Filters are not shown
assert_select '#filters'
assert_select '#filters .category h3', { count: 0 }

# Pagination is not shown
assert_select '#pagination', { count: 0 }
end
end

Expand Down

0 comments on commit d2b5a1c

Please sign in to comment.