Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding option for single page count #3315

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

adding option for single page count #3315

wants to merge 5 commits into from

Conversation

hudajkhan
Copy link

What this pull request does:

Adds a check to see if there is only one search result, and shows "1 of 1" in the view without showing previous or next links.
Adds a test for this particular case.

Closes #3314 .
Addresses a ticket in EarthWorks: sul-dlss/earthworks#1367

Comment on lines 17 to 19
return true if total == 1

@search_context.present? && (@search_context[:prev] || @search_context[:next])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this effectively the same as:

Suggested change
return true if total == 1
@search_context.present? && (@search_context[:prev] || @search_context[:next])
@search_context.present?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, because maybe you can have a search_context but not have a :prev or :next?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right – my guess is that case (you have a context, but no prev or next) is the same thing as having a single result. But just a guess!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separately I have to remove the "|" separating the different sections, so that will be another commit.

end

def display_separator
'|' unless total == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this display separator a translation.

Copy link
Author

@hudajkhan hudajkhan Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to do that in the latest commit.

@@ -23,6 +23,18 @@
end
end

context 'when there is exactly one search result with no next or previous document' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone goes directly to a show page without any session history. Will they still see this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the most recent changes, I went directly to an item page url in a separate browser and that did not show the "1 of 1" content.

@jcoyne
Copy link
Member

jcoyne commented Sep 9, 2024

For anyone else who is interested in the history, this conditional originated in the initial git commit 15 years aog: cfc4743#diff-c732a210586cc78a766262d89f052850316eef0ddeb8a1fc63020dff9a77a85bR1

However it didn't have any pagination at that time.

@cbeer added pagination in d619178 and it did support "1 of 1"

@search_context.present? && (@search_context[:prev] || @search_context[:next]) && (@search_session['document_id'] == @current_document_id)
return false unless @search_session['document_id'] == @current_document_id

return true if total == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to check for @search_context here. Otherwise it will display on pages with no search context.

@hudajkhan
Copy link
Author

Thanks for the comments @jcoyne. I should be able to look at this today/tomorrow.

@hudajkhan
Copy link
Author

@jcoyne I believe I addressed your comments. Thanks!

@search_context.present? && (@search_context[:prev] || @search_context[:next]) && (@search_session['document_id'] == @current_document_id)
return false unless @search_context.present? && @search_session['document_id'] == @current_document_id

total == 1 || (@search_context[:prev] || @search_context[:next])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
total == 1 || (@search_context[:prev] || @search_context[:next])
total == 1 || @search_context[:prev] || @search_context[:next]

next_document ||= @search_context[:next]
link_opts = session_tracking_params(next_document, count + 1, per_page: per_page, search_id: search_id).merge(class: classes, rel: 'next').merge(link_opts)
link_to_unless next_document.nil?, raw(t('views.pagination.next')), url_for_document(next_document), link_opts do
tag.span raw(t('views.pagination.next')), class: 'next'
end
end

def current_count
total == 1 ? total : number_with_delimiter(count)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a conditional here?

Suggested change
total == 1 ? total : number_with_delimiter(count)
number_with_delimiter(count)

@@ -20,7 +20,7 @@ def render?
end

def display_separator
'|' unless total == 1
t('views.pagination.separator') unless total == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to configure the delimiter separately for each language that we want to support? This seems to me like something better suited for Blacklight::Config rather than an i18n.

@@ -1,7 +1,7 @@
<div class="search-context page-links">
<%= link_to_previous_document %> |
<%= link_to_previous_document %> <%= display_separator %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put the conditional for total == 1 here, then we can avoid checking it several times in the component class. I think that'll make the code simpler to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable display of pagination component in the case where we have only one result
4 participants