Skip to content

Commit d2b5a1c

Browse files
committed
Update 'no results' partial
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.
1 parent da85230 commit d2b5a1c

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

app/controllers/search_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def results
1818
# The @pagination instance variable includes info about next/previous pages (where they exist) to assist the UI.
1919
@pagination = Analyzer.new(@enhanced_query, response).pagination if @errors.nil?
2020

21-
# Display stuff
21+
# Display results
2222
@results = extract_results(response)
2323
@filters = extract_filters(response)
2424
end
@@ -30,7 +30,10 @@ def extract_errors(response)
3030
end
3131

3232
def extract_filters(response)
33-
response&.data&.search&.to_h&.dig('aggregations')
33+
aggs = response&.data&.search&.to_h&.dig('aggregations')
34+
return if aggs.blank?
35+
36+
aggs.select { |_, agg_values| agg_values.present? }
3437
end
3538

3639
def extract_results(response)

app/views/search/_result_empty.html.erb

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/views/search/results.html.erb

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,34 @@
4848

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

51-
<div class="layout-1q3q layout-band top-space">
51+
<div class="<%= 'layout-1q3q' if @filters.present? %> layout-band top-space">
5252
<div class="col3q wrap-results">
53-
<ul id="results" class="list-unbulleted">
54-
<%= render(partial: 'search/result', collection: @results) || render('result_empty') %>
55-
</ul>
53+
<% if @results.present? %>
54+
<ul id="results" class="list-unbulleted">
55+
<%= render(partial: 'search/result', collection: @results) %>
56+
</ul>
57+
<% else %>
58+
<div id="results">
59+
<p class="hd-2">No results found for your search</p>
60+
</div>
61+
<% end %>
5662
</div>
5763

58-
<aside class="col1q filter-container">
59-
<div id="filters">
60-
<h2>Available filters</h2>
61-
<% @filters&.each do |category, values| %>
62-
<%= render(partial: 'search/filter', locals: {category: category, values: values}) %>
63-
<% end %>
64-
</div>
65-
</aside>
64+
<% if @filters.present? %>
65+
<aside class="col1q filter-container">
66+
<div id="filters">
67+
<h2>Available filters</h2>
68+
<% @filters&.each do |category, values| %>
69+
<%= render(partial: 'search/filter', locals: {category: category, values: values}) %>
70+
<% end %>
71+
</div>
72+
</aside>
73+
<% end %>
6674
</div>
6775

68-
<div id="pagination">
69-
<%= render partial: "pagination" %>
70-
</div>
76+
<% if @results.present? %>
77+
<div id="pagination">
78+
<%= render partial: "pagination" %>
79+
</div>
80+
<% end %>
7181
</div>

test/controllers/search_controller_test.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,20 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
201201
match_requests_on: %i[method uri body]) do
202202
get '/results?q=asdfiouwenlasd'
203203
assert_response :success
204+
204205
# Result list contents state "no results"
205206
assert_select '#results'
206207
assert_select '#results', { count: 1 }
207-
assert_select '#results li', 'There are no results.'
208+
assert_select '#results p', 'No results found for your search'
209+
210+
# Filter sidebar is not shown
211+
assert_select '#filters', { count: 0 }
212+
208213
# Filters are not shown
209-
assert_select '#filters'
210214
assert_select '#filters .category h3', { count: 0 }
215+
216+
# Pagination is not shown
217+
assert_select '#pagination', { count: 0 }
211218
end
212219
end
213220

0 commit comments

Comments
 (0)