Skip to content

Commit eab35ed

Browse files
committed
Move facet components to Facets namespace
Adding a namespace for all the Facet commponents to go to
1 parent 03ecdaf commit eab35ed

25 files changed

+247
-197
lines changed
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
# frozen_string_literal: true
22

33
module Blacklight
4-
class FacetFieldCheckboxesComponent < Blacklight::Component
5-
def initialize(facet_field:, layout: nil)
6-
@facet_field = facet_field
7-
@layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
8-
end
9-
10-
def render?
11-
presenters.any?
12-
end
13-
14-
def presenters
15-
return [] unless @facet_field.paginator
16-
17-
return to_enum(:presenters) unless block_given?
18-
19-
@facet_field.paginator.items.each do |item|
20-
yield Blacklight::FacetCheckboxItemPresenter.new(item, @facet_field.facet_field, helpers, @facet_field.key, @facet_field.search_state)
21-
end
22-
end
23-
end
4+
class FacetFieldCheckboxesComponent < Facets::FieldComponent; end
5+
FacetFieldCheckboxesComponent = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("FacetFieldCheckboxesComponent", "Blacklight::Facets::CheckboxesComponent", ActiveSupport::Deprecation.new)
246
end
Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
# frozen_string_literal: true
22

33
module Blacklight
4-
class FacetFieldComponent < Blacklight::Component
5-
renders_one :label
6-
renders_one :body
7-
8-
# @param [Blacklight::FacetFieldPresenter] facet_field
9-
def initialize(facet_field:)
10-
@facet_field = facet_field
11-
end
12-
13-
def html_id
14-
"facet-#{@facet_field.key.parameterize}"
15-
end
16-
17-
def header_html_id
18-
"#{html_id}-header"
19-
end
20-
end
4+
class FacetFieldComponent < Facets::FieldComponent; end
5+
FacetFieldComponent = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("FacetFieldComponent", "Blacklight::Facets::FieldComponent", ActiveSupport::Deprecation.new)
216
end
Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
11
# frozen_string_literal: true
22

33
module Blacklight
4-
class FacetFieldInclusiveConstraintComponent < Blacklight::Component
5-
with_collection_parameter :facet_field
6-
7-
def initialize(facet_field:, values: nil)
8-
@facet_field = facet_field
9-
@values = values
10-
end
11-
12-
def values
13-
@values ||= @facet_field.values.find { |v| v.is_a? Array }
14-
@values || []
15-
end
16-
17-
def render?
18-
values.present?
19-
end
20-
21-
def presenters
22-
return to_enum(:presenters) unless block_given?
23-
24-
values.each do |item|
25-
yield Blacklight::FacetGroupedItemPresenter.new(values, item, @facet_field.facet_field, helpers, @facet_field.key, @facet_field.search_state)
26-
end
27-
end
28-
end
4+
class FacetFieldInclusiveConstraintComponent < Facets::InclusiveConstraintComponent; end
5+
FacetFieldInclusiveConstraintComponent = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("FacetFieldInclusiveConstraintComponent",
6+
"Blacklight::Facets::InclusiveConstraintComponent",
7+
ActiveSupport::Deprecation.new)
298
end
Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
# frozen_string_literal: true
22

33
module Blacklight
4-
class FacetFieldListComponent < Blacklight::Component
5-
def initialize(facet_field:, layout: nil)
6-
@facet_field = facet_field
7-
@layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
8-
end
9-
10-
def facet_items(wrapping_element: :li, **item_args)
11-
facet_item_component_class.with_collection(facet_item_presenters, wrapping_element: wrapping_element, **item_args)
12-
end
13-
14-
def facet_item_presenters
15-
@facet_field.paginator.items.map do |item|
16-
facet_item_presenter(item)
17-
end
18-
end
19-
20-
def render?
21-
@facet_field.paginator&.items&.any?
22-
end
23-
24-
def facet_item_presenter(facet_item)
25-
facet_config.item_presenter.new(facet_item, facet_config, helpers, @facet_field.key)
26-
end
27-
28-
def facet_item_component_class
29-
facet_config.item_component
30-
end
31-
32-
def facet_config
33-
@facet_field.facet_field
34-
end
35-
end
4+
class FacetFieldListComponent < Facets::ListComponent; end
5+
FacetFieldListComponent = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("FacetFieldListComponent", "Blacklight::Facets::ListComponent", ActiveSupport::Deprecation.new)
366
end
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# frozen_string_literal: true
22

33
module Blacklight
4-
class FacetFieldNoLayoutComponent < Blacklight::Component
5-
renders_one :label
6-
renders_one :body
7-
8-
def initialize(**); end
9-
10-
def call
11-
body.to_s
12-
end
13-
end
4+
class FacetFieldNoLayoutComponent < Facets::FieldComponent; end
5+
FacetFieldNoLayoutComponent = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("FacetFieldNoLayoutComponent", "Blacklight::Facets::NoLayoutComponent", ActiveSupport::Deprecation.new)
146
end
Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,6 @@
11
# frozen_string_literal: true
22

33
module Blacklight
4-
class FacetItemComponent < Blacklight::Component
5-
attr_reader :label, :href, :hits
6-
7-
with_collection_parameter :facet_item
8-
9-
def initialize(facet_item:, wrapping_element: 'li', suppress_link: false)
10-
@facet_item = facet_item
11-
@label = facet_item.label
12-
@hits = facet_item.hits
13-
@href = facet_item.href
14-
@selected = facet_item.selected?
15-
@wrapping_element = wrapping_element
16-
@suppress_link = suppress_link
17-
end
18-
19-
def call
20-
# if the downstream app has overridden the helper methods we'd usually call,
21-
# use the helpers to preserve compatibility
22-
content = if @selected
23-
render_selected_facet_value
24-
else
25-
render_facet_value
26-
end
27-
28-
return '' if content.blank?
29-
return content unless @wrapping_element
30-
31-
content_tag @wrapping_element, content
32-
end
33-
34-
##
35-
# Standard display of a facet value in a list. Used in both _facets sidebar
36-
# partial and catalog/facet expanded list. Will output facet value name as
37-
# a link to add that to your restrictions, with count in parens.
38-
#
39-
# @return [String]
40-
# @private
41-
def render_facet_value
42-
tag.span(class: "facet-label") do
43-
link_to_unless(@suppress_link, label, href, class: "facet-select", rel: "nofollow")
44-
end + render_facet_count
45-
end
46-
47-
##
48-
# Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
49-
# @see #render_facet_value
50-
#
51-
# @private
52-
def render_selected_facet_value
53-
tag.span(class: "facet-label") do
54-
tag.span(label, class: "selected") +
55-
# remove link
56-
link_to(href, class: "remove", rel: "nofollow") do
57-
render(Blacklight::Icons::RemoveComponent.new(aria_hidden: true)) +
58-
tag.span(helpers.t(:'blacklight.search.facets.selected.remove'), class: 'visually-hidden')
59-
end
60-
end + render_facet_count(classes: ["selected"])
61-
end
62-
63-
##
64-
# Renders a count value for facet limits. Can be over-ridden locally
65-
# to change style. And can be called by plugins to get consistent display.
66-
#
67-
# @param [Hash] options
68-
# @option options [Array<String>] an array of classes to add to count span.
69-
# @return [String]
70-
# @private
71-
def render_facet_count(options = {})
72-
return '' if hits.blank?
73-
74-
classes = (options[:classes] || []) << "facet-count"
75-
tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(hits)), class: classes)
76-
end
77-
end
4+
class FacetItemComponent < Facets::ItemComponent; end
5+
FacetItemComponent = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("FacetItemComponent", "Blacklight::Facets::ItemComponent", ActiveSupport::Deprecation.new)
786
end

app/components/blacklight/facet_item_pivot_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize(facet_item:, wrapping_element: 'li', suppress_link: false, collap
2828
end
2929

3030
def call
31-
facet = Blacklight::FacetItemComponent.new(facet_item: @facet_item, wrapping_element: nil, suppress_link: @suppress_link)
31+
facet = Blacklight::Facets::ItemComponent.new(facet_item: @facet_item, wrapping_element: nil, suppress_link: @suppress_link)
3232

3333
id = "h-#{self.class.mint_id}" if @collapsing && has_items?
3434

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
module Blacklight
4+
module Facets
5+
class CheckboxesComponent < Blacklight::Component
6+
def initialize(facet_field:, layout: nil)
7+
@facet_field = facet_field
8+
@layout = layout == false ? Blacklight::Facets::NoLayoutComponent : Blacklight::Facets::FieldComponent
9+
end
10+
11+
def render?
12+
presenters.any?
13+
end
14+
15+
def presenters
16+
return [] unless @facet_field.paginator
17+
18+
return to_enum(:presenters) unless block_given?
19+
20+
@facet_field.paginator.items.each do |item|
21+
yield Blacklight::FacetCheckboxItemPresenter.new(item, @facet_field.facet_field, helpers, @facet_field.key, @facet_field.search_state)
22+
end
23+
end
24+
end
25+
end
26+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Blacklight
4+
module Facets
5+
class FieldComponent < Blacklight::Component
6+
renders_one :label
7+
renders_one :body
8+
9+
# @param [Blacklight::FacetFieldPresenter] facet_field
10+
def initialize(facet_field:)
11+
@facet_field = facet_field
12+
end
13+
14+
def html_id
15+
"facet-#{@facet_field.key.parameterize}"
16+
end
17+
18+
def header_html_id
19+
"#{html_id}-header"
20+
end
21+
end
22+
end
23+
end
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="inclusive_or card card-body bg-light mb-3">
22
<h5><%= t('blacklight.advanced_search.any_of') %></h5>
33
<ul class="list-unstyled facet-values">
4-
<%= render(Blacklight::FacetItemComponent.with_collection(presenters.to_a)) %>
4+
<%= render Blacklight::Facets::ItemComponent.with_collection(presenters.to_a) %>
55
</ul>
66
</div>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
module Blacklight
4+
module Facets
5+
class InclusiveConstraintComponent < Blacklight::Component
6+
with_collection_parameter :facet_field
7+
8+
def initialize(facet_field:, values: nil)
9+
@facet_field = facet_field
10+
@values = values
11+
end
12+
13+
def values
14+
@values ||= @facet_field.values.find { |v| v.is_a? Array }
15+
@values || []
16+
end
17+
18+
def render?
19+
values.present?
20+
end
21+
22+
def presenters
23+
return to_enum(:presenters) unless block_given?
24+
25+
values.each do |item|
26+
yield Blacklight::FacetGroupedItemPresenter.new(values, item, @facet_field.facet_field, helpers, @facet_field.key, @facet_field.search_state)
27+
end
28+
end
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)