Skip to content

Commit ab288a0

Browse files
committed
Remove unnecessary partial and move render conditions to component
1 parent 3e3e63c commit ab288a0

File tree

6 files changed

+46
-46
lines changed

6 files changed

+46
-46
lines changed

app/components/blacklight/facet_field_filter_component.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
module Blacklight
44
class FacetFieldFilterComponent < Blacklight::Component
5+
# @params [Blacklight::FacetFieldPresenter] facet_field
56
def initialize(facet_field:)
67
@facet_field = facet_field
78
end
89

910
def render?
10-
@facet_field.facet_field.index_range.any?
11+
@facet_field.facet_field.index_range && @facet_field.display_facet.index?
1112
end
1213

1314
def prefix

app/controllers/concerns/blacklight/catalog.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def track
8080

8181
# displays values and pagination links for a single facet field
8282
def facet
83+
# @facet is a Blacklight::Configuration::FacetField
8384
@facet = blacklight_config.facet_fields[params[:id]]
8485
raise ActionController::RoutingError, 'Not Found' unless @facet
8586

@@ -88,8 +89,10 @@ def facet
8889
else
8990
search_service.facet_field_response(@facet.key)
9091
end
92+
# @display_facet is a Blacklight::Solr::Response::Facets::FacetField
9193
@display_facet = @response.aggregations[@facet.field]
9294

95+
# @presenter is a Blacklight::FacetFieldPresenter
9396
@presenter = @facet.presenter.new(@facet, @display_facet, view_context)
9497
@pagination = @presenter.paginator
9598
respond_to do |format|

app/views/catalog/_facet_index_navigation.html.erb

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/views/catalog/facet.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<div class="facet-filters card card-body bg-light p-3 mb-3 border-0">
55
<%= render Blacklight::Search::FacetSuggestInput.new(facet: @facet, presenter: @presenter) %>
6-
<%= render partial: 'facet_index_navigation' if @facet.index_range && @display_facet.index? %>
6+
<%= render Blacklight::FacetFieldFilterComponent.new(facet_field: @presenter) %>
77
</div>
88

99
<div class="facet-pagination top d-flex flex-wrap w-100 justify-content-between border-bottom pb-3 mb-3">
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Blacklight::FacetFieldFilterComponent, type: :component do
4+
let(:pagination) { Blacklight::Solr::FacetPaginator.new([]) }
5+
let(:facet) { Blacklight::Configuration::FacetField.new(index_range: '0'..'9', presenter: Blacklight::FacetFieldPresenter) }
6+
let(:display_facet) { instance_double(Blacklight::Solr::Response::Facets::FacetField, items: [], offset: 0, prefix: '', sort: 'index', index?: true) }
7+
let(:blacklight_config) { Blacklight::Configuration.new }
8+
9+
let(:presenter) { facet.presenter.new(facet, display_facet, vc_test_controller.view_context) }
10+
11+
before do
12+
with_request_url "/catalog/facet/language" do
13+
render_inline(described_class.new(facet_field: presenter))
14+
end
15+
end
16+
17+
it 'renders the facet index navigation range' do
18+
expect(page).to have_css '.pagination'
19+
expect(page).to have_link '0', href: '/catalog/facet/language.html?facet.prefix=0&facet.sort=index'
20+
expect(page).to have_link '1'
21+
expect(page).to have_link '8'
22+
expect(page).to have_link '9'
23+
end
24+
25+
it 'renders an "all" button' do
26+
expect(page).to have_css '.page-link', text: 'All'
27+
end
28+
29+
context 'with a selected index' do
30+
let(:display_facet) { instance_double(Blacklight::Solr::Response::Facets::FacetField, items: [], offset: 0, prefix: '5', sort: 'index', index?: true) }
31+
32+
it 'highlights the selected index' do
33+
expect(page).to have_css '.active', text: '5'
34+
end
35+
36+
it 'enables the clear facets button' do
37+
expect(page).to have_link 'All'
38+
end
39+
end
40+
end

spec/views/catalog/_facet_index_navigation.html.erb_spec.rb

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)