Skip to content

Commit

Permalink
Copy SearchContextComponent to ServerItemPaginationComponent to ease …
Browse files Browse the repository at this point in the history
…BL8 upgrade path

Closes projectblacklight#3313
  • Loading branch information
maxkadel committed Oct 28, 2024
1 parent 6847a50 commit f1195c2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class='pagination-search-widgets'>

<div class="page-links">
<%= link_to_previous_document %> |

<%= item_page_entry_info %> |

<%= link_to_next_document %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module Blacklight
module SearchContext
class ServerItemPaginationComponent < Blacklight::Component
with_collection_parameter :search_context

def initialize(search_context:, search_session:, current_document:)
@search_context = search_context
@search_session = search_session
@current_document_id = current_document.id
end

def render?
@search_context.present? && (@search_context[:prev] || @search_context[:next])
end

def item_page_entry_info
Deprecation.silence(Blacklight::CatalogHelperBehavior) do
helpers.item_page_entry_info
end
end

def link_to_previous_document(document = nil, *args, **kwargs)
Deprecation.silence(Blacklight::UrlHelperBehavior) do
helpers.link_to_previous_document(document || @search_context[:prev], *args, **kwargs)
end
end

def link_to_next_document(document = nil, *args, **kwargs)
Deprecation.silence(Blacklight::UrlHelperBehavior) do
helpers.link_to_next_document(document || @search_context[:next], *args, **kwargs)
end
end
end
end
end
1 change: 1 addition & 0 deletions app/components/blacklight/search_context_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SearchContextComponent < Blacklight::Component
with_collection_parameter :search_context

def initialize(search_context:, search_session:)
Blacklight.deprecation.warn("Blacklight::SearchContextComponent is deprecated and will be moved to Blacklight::SearchContext::ServerItemPaginationComponent in Blacklight 8.0.0")
@search_context = search_context
@search_session = search_session
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/blacklight/catalog_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def item_page_entry_info
total: number_with_delimiter(search_session['total']),
count: search_session['total'].to_i).html_safe
end
deprecation_deprecate item_page_entry_info: 'Use Blacklight::SearchContextComponent methods instead'
deprecation_deprecate item_page_entry_info: 'Use Blacklight::SearchContext::ServerItemPaginationComponent methods instead'

##
# Look up search field user-displayable label
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def link_to_previous_document(previous_document, classes: 'previous', **addl_lin
tag.span raw(t('views.pagination.previous')), class: 'previous'
end
end
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContextComponent'
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContext::ServerItemPaginationComponent'

##
# Link to the next document in the current search context
Expand All @@ -69,7 +69,7 @@ def link_to_next_document(next_document, classes: 'next', **addl_link_opts)
tag.span raw(t('views.pagination.next')), class: 'next'
end
end
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContextComponent'
deprecation_deprecate link_to_previous_document: 'Moving to Blacklight::SearchContext::ServerItemPaginationComponent'

##
# Attributes for a link that gives a URL we can use to track clicks for the current search session
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalog/_previous_next_doc.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::SearchContextComponent instead.') %>
<%= render(Blacklight::SearchContextComponent.new(search_context: @search_context, search_session: search_session)) %>
<% Deprecation.warn(self, 'The partial _previous_next_doc.html.erb will be removed in 8.0. Render Blacklight::SearchContext::ServerItemPaginationComponent instead.') %>
<%= render(Blacklight::SearchContext::ServerItemPaginationComponent.new(search_context: @search_context, search_session: search_session, current_document: @current_document)) %>
2 changes: 1 addition & 1 deletion app/views/catalog/_show_main_content.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render(Blacklight::SearchContextComponent.new(search_context: @search_context, search_session: search_session)) if search_session['document_id'] == @document.id %>
<%= render(Blacklight::SearchContext::ServerItemPaginationComponent.new(search_context: @search_context, search_session: search_session, current_document: @document)) if search_session['document_id'] == @document.id %>

<% @page_title = t('blacklight.search.show.title', document_title: Deprecation.silence(Blacklight::BlacklightHelperBehavior) { document_show_html_title }, application_name: application_name).html_safe %>
<% content_for(:head) { render_link_rel_alternates } %>
Expand Down

0 comments on commit f1195c2

Please sign in to comment.