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

Permit configurable replacement of search tracking with client session storage #2954

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
<div id="appliedParams" class="clearfix constraints-container">
<%= render 'start_over' %>
<%= link_to t('blacklight.back_to_search'), search_action_path(only_path: true), class: 'btn btn-outline-secondary back-to-catalog d-none', aria: { live: "off" } %>
jcoyne marked this conversation as resolved.
Show resolved Hide resolved
</div>
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Blacklight
module SearchContext
class ClientAppliedParamsComponent < Blacklight::Component
delegate :search_action_path, to: :helpers
def render?
controller.params.permit(:counter)[:counter]
barmintor marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
@@ -0,0 +1,10 @@
<div class='pagination-search-widgets'>

<div class="page-links d-none" data-page-links-url="<%= page_links_url %>" aria-live="polite">
<%= link_to_previous_document %> |

<%= item_page_entry_info %> |

<%= link_to_next_document %>
</div>
</div>
@@ -0,0 +1,51 @@
# frozen_string_literal: true

module Blacklight
module SearchContext
class ClientItemPaginationComponent < Blacklight::Component
delegate :search_action_path, to: :helpers

def initialize(counter:, **_args)
@counter = counter
end

def render?
@counter.present?
end

def page_links_url
search_action_path action: 'page_links', counter: @counter
end

##
# Displays "showing X of Y items" message.
#
# @return [String]
def item_page_entry_info
# rubocop:disable Rails/OutputSafety
t('blacklight.search.entry_pagination_info.other', current: "<span class=\"pagination-counter-delimited\"></span>",
total: "<span class=\"pagination-total-delimited\"></span>",
count: "<span class=\"pagination-total-raw\"></span>").html_safe
# rubocop:enable Rails/OutputSafety
end

def link_to_previous_document(classes: 'previous', **link_opts)
# rubocop:disable Rails/OutputSafety
link_opts = { class: classes, rel: 'prev' }.merge(link_opts)
link_to '#', link_opts do
tag.span raw(t('views.pagination.previous')), class: 'previous'
end
# rubocop:enable Rails/OutputSafety
end

def link_to_next_document(classes: 'next', **link_opts)
# rubocop:disable Rails/OutputSafety
link_opts = { class: classes, rel: 'next' }.merge(link_opts)
link_to '#', link_opts do
tag.span raw(t('views.pagination.next')), class: 'next'
end
# rubocop:enable Rails/OutputSafety
end
end
end
end
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::SearchContext::ClientAppliedParamsComponent, type: :component do
subject(:render) { instance.render_in(view_context) }

let(:instance) { described_class.new }
let(:view_context) { controller.view_context }

before do
view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for('application/_start_over.html.erb' => 'start over'))
allow(view_context).to receive(:link_back_to_catalog).with(any_args)
end

it 'is blank without counter param' do
expect(render).to be_blank
end

context 'with counter param' do
before do
controller.params[:counter] = 1
end

it 'is not blank' do
expect(render).not_to be_blank
end
end
end
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::SearchContext::ClientItemPaginationComponent, type: :component do
subject(:render) { instance.render_in(view_context) }

let(:rendered) do
Capybara::Node::Simple.new(render)
end

let(:counter) { nil }
let(:instance) { described_class.new(counter: counter) }
let(:view_context) { controller.view_context }

before do
view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for('application/_start_over.html.erb' => 'start over'))
allow(view_context).to receive(:link_back_to_catalog).with(any_args)
end

it 'is blank without counter param' do
expect(render).to be_blank
end

context 'with counter param' do
let(:counter) { 1 }

it 'is not blank' do
expect(render).not_to be_blank
end

it 'has spans that will be populated dynamically by the client' do
expect(rendered).to have_selector 'span[class="pagination-counter-delimited"]'
expect(rendered).to have_selector 'span[class="pagination-total-delimited"]'
end
end
end