-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a configuration object for Blacklight::Configuration.track_…
…search_session - allow configuration of components for applied parameters and item pagination - only build server-side search tracking data if using server-side tracking - extract applied_params html into a component
- Loading branch information
Showing
13 changed files
with
185 additions
and
27 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
app/components/blacklight/search_context/server_applied_params_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div id="appliedParams" class="clearfix constraints-container"> | ||
<%= render 'start_over' %> | ||
<%= link_back_to_catalog class: 'btn btn-outline-secondary' %> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
app/components/blacklight/search_context/server_applied_params_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module SearchContext | ||
class ServerAppliedParamsComponent < Blacklight::Component | ||
delegate :current_search_session, :link_back_to_catalog, to: :helpers | ||
|
||
def render? | ||
current_search_session | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
class Blacklight::Configuration | ||
class SessionTrackingConfig < Blacklight::OpenStructWithHashAccess | ||
# @!attribute storage | ||
# @return [String, FalseClass] 'server': use server-side tracking; 'client': delegate search tracking and prev/next navigation to client | ||
# @!attribute applied_params_component | ||
# @return [Class] component class used to render a facet group | ||
# @!attribute item_pagination_component | ||
# @return [Class] component class used to render the constraints | ||
|
||
def initialize(property_hash = {}) | ||
super({ storage: 'server' }.merge(property_hash)) | ||
end | ||
|
||
def applied_params_component | ||
super || default_applied_params_component(storage) | ||
end | ||
|
||
def item_pagination_component | ||
super || default_item_pagination_component(storage) | ||
end | ||
|
||
def url_helper | ||
super || default_url_helper(storage) | ||
end | ||
|
||
def default_applied_params_component(storage) | ||
return Blacklight::SearchContext::ServerAppliedParamsComponent if storage == 'server' | ||
|
||
nil | ||
end | ||
|
||
def default_item_pagination_component(storage) | ||
return Blacklight::SearchContextComponent if storage == 'server' | ||
|
||
nil | ||
end | ||
|
||
# extension point for alternative storage types | ||
def default_url_helper(_storage) | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
spec/components/blacklight/search_context/server_applied_params_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Blacklight::SearchContext::ServerAppliedParamsComponent, type: :component do | ||
subject(:render) { instance.render_in(view_context) } | ||
|
||
let(:instance) { described_class.new } | ||
let(:current_search_session) { nil } | ||
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(:current_search_session).and_return current_search_session | ||
allow(view_context).to receive(:link_back_to_catalog).with(any_args) | ||
end | ||
|
||
it 'is blank without current session' do | ||
expect(render).to be_blank | ||
end | ||
|
||
context 'with current session' do | ||
let(:current_search_session) { double(query_params: { q: 'abc' }) } | ||
|
||
it 'is not blank' do | ||
expect(render).not_to be_blank | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
spec/lib/blacklight/configuration/session_tracking_config_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Blacklight::Configuration::SessionTrackingConfig do | ||
subject(:config) { described_class.new } | ||
|
||
it "defaults @storage to 'server'" do | ||
expect(config.storage).to eq 'server' | ||
end | ||
|
||
context "@storage is set to 'server'" do | ||
before do | ||
config.storage = 'server' | ||
end | ||
|
||
it "defaults components values" do | ||
expect(config.applied_params_component).to eq Blacklight::SearchContext::ServerAppliedParamsComponent | ||
end | ||
|
||
it "defaults tracking url helper" do | ||
expect(config.url_helper).to be_nil | ||
end | ||
end | ||
|
||
context "@storage is set to false" do | ||
before do | ||
config.storage = false | ||
end | ||
|
||
it "defaults components values" do | ||
expect(config.applied_params_component).to be_nil | ||
end | ||
|
||
it "defaults tracking url helper" do | ||
expect(config.url_helper).to be_nil | ||
end | ||
end | ||
end |