Skip to content

Commit 0c9047f

Browse files
committed
display search context consistently regardless of whether there is a single result (DLC-1161)
1 parent 681eb01 commit 0c9047f

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<div class="input-group-append p-0">
2-
<% if @search_context[:prev] || @search_context[:next] %>
3-
<%= helpers.link_back_to_catalog(label: "<span class=\"d-none d-md-inline\">#{item_page_entry_info} </span><i class=\"fa fa-reply-all\"></i>".html_safe, class: 'btn bg-body btn-outline-info rounded-md-left-0 rounded-right-0 align-content-center w-100 h-100', :"data-toggle" => 'tooltip', "aria-label": t('views.pagination.return_to_search'), title: t('views.pagination.return_to_search') ) %>
4-
<%= link_to_previous_document @search_context[:prev], "btn bg-body btn-outline-info rounded-0 align-content-center flex-shrink-1" %>
5-
<%= link_to_next_document @search_context[:next], "btn bg-body btn-outline-info rounded-right align-content-center flex-shrink-1" %>
6-
<% else %>
7-
<%= helpers.link_back_to_catalog(label: '<i class="fa fa-reply-all"></i> '.html_safe, class: 'btn bg-body btn-outline-info rounded-md-left-0 align-content-center flex-fill', :"data-toggle" => 'tooltip', "aria-label": t('views.pagination.return_to_search'), title: t('views.pagination.return_to_search') ) %>
8-
<% end %>
2+
<%= helpers.link_back_to_catalog(label: "<span class=\"d-none d-md-inline\">#{item_page_entry_info} </span><i class=\"fa fa-reply-all\"></i>".html_safe, class: 'btn bg-body btn-outline-info rounded-md-left-0 rounded-right-0 align-content-center w-100 h-100', :"data-toggle" => 'tooltip', "aria-label": t('views.pagination.return_to_search'), title: t('views.pagination.return_to_search') ) %>
3+
<%= link_to_previous_document @search_context[:prev], "btn bg-body btn-outline-info rounded-0 align-content-center flex-shrink-1" %>
4+
<%= link_to_next_document @search_context[:next], "btn bg-body btn-outline-info rounded-right align-content-center flex-shrink-1" %>
95
</div>

app/components/dcv/search_context/pagination_component.rb

+4
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ class PaginationComponent < Blacklight::SearchContextComponent
55
def will_render?(**_args)
66
render?
77
end
8+
9+
def render?
10+
([:prev, :next] & @search_context.keys).present? if @search_context
11+
end
812
end
913
end

app/views/kaminari/dcv_collapsible/_prev_page.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
remote: data-remote
88
-%>
99
<% tag_class="btn bg-body btn-outline-info rounded-0 #{'disabled' if current_page.first?}" -%>
10-
<%= link_to '<i class="fa fa-arrow-left"></i>'.html_safe, url, :rel => 'next', :remote => remote, :"data-toggle" => 'tooltip', "aria-label": raw(t 'views.pagination.previous'), title: raw(t 'views.pagination.previous'), class: tag_class %>
10+
<%= link_to '<i class="fa fa-arrow-left"></i>'.html_safe, url, :rel => 'prev', :remote => remote, :"data-toggle" => 'tooltip', "aria-label": raw(t 'views.pagination.previous'), title: raw(t 'views.pagination.previous'), class: tag_class %>

app/views/kaminari/dcv_compact/_prev_page.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
remote: data-remote
88
-%>
99
<% tag_class="btn bg-body btn-outline-info rounded-0 align-content-center #{'disabled' if current_page.first?}" -%>
10-
<%= link_to '<i class="fa fa-arrow-left"></i>'.html_safe, url, :rel => 'next', :remote => remote, :"data-toggle" => 'tooltip', "aria-label": raw(t 'views.pagination.previous'), title: raw(t 'views.pagination.previous'), class: tag_class %>
10+
<%= link_to '<i class="fa fa-arrow-left"></i>'.html_safe, url, :rel => 'prev', :remote => remote, :"data-toggle" => 'tooltip', "aria-label": raw(t 'views.pagination.previous'), title: raw(t 'views.pagination.previous'), class: tag_class %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
describe Dcv::SearchContext::PaginationComponent, type: :component do
6+
subject(:component) { described_class.new(search_context: search_context, search_session: search_session) }
7+
8+
# search_context may be nil or a hash of :prev and :next
9+
let(:search_context) { nil }
10+
11+
# search_session may be nil or a hash of %w(id counter total)
12+
let(:search_session) { nil }
13+
14+
15+
let(:item_page_entry_info) { nil }
16+
17+
before do
18+
allow(view_context).to receive(:item_page_entry_info).and_return(item_page_entry_info)
19+
allow(view_context).to receive(:current_search_session).and_return({ query_params: {}})
20+
allow(view_context).to receive(:link_back_to_catalog) { |arg| arg[:label] }
21+
end
22+
23+
include_context "renderable view components"
24+
25+
context "with a single document in search" do
26+
let(:item_page_entry_info) { "item_page_entry_info" }
27+
let(:search_context) { { prev: nil, next: nil } }
28+
let(:search_session) { { 'counter' => 1, 'id' => 'id', 'total' => 1 } }
29+
it 'links to the facet and shows the number of hits' do
30+
expect(rendered).to have_selector 'span.d-md-inline', text: item_page_entry_info
31+
end
32+
end
33+
34+
context "with a transformed value" do
35+
end
36+
end

0 commit comments

Comments
 (0)