blacklight 7.25.3 → 7.26.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ed5074249090af28b69f617baadf69238599d64f387aae61ef71478ea501573
4
- data.tar.gz: 03c767a4f628e2e09cd0afbbcb84a30cb0b4161013343f6fd45ab0a9653b58e6
3
+ metadata.gz: 61a8ce6dc6b7186a9facb02e2862cd9ab252992fd16ac8f3cfb52bb0dc414a0b
4
+ data.tar.gz: 8fca956b142ab7f1c446858320df1247bed718197ab499e826eb663406db95d9
5
5
  SHA512:
6
- metadata.gz: 55bab7b3b6c79e06a946650fa0be87eb273b29ef7e2967a945b4222e58edb4da63781b6011d325c9de6377fe8fcb6c6678a651dc4afa6a2d86860a81fa81ebdb
7
- data.tar.gz: ccafd10839a91ef7ec21bc5838da73f4cd31d6a17320e6e20b4e052c0414b9ca16c2e6347e1ca1f9dbdaacfed26e723bed9eb6289b5e8c7c887c3867a3cbf8b7
6
+ metadata.gz: 175534daee84446996871538ece0c562194b485d53b801cb8ab839569fe36c712d94c7629623dc5e32d4e58993d82bc4f899669dbdfaf30de5447235236728f4
7
+ data.tar.gz: 53c10ab08c741669511f9e77ea1d948968fc0b635b16a883c5c055ebeab45dfd9d7ab295838049f5ff27328f40bb66e06f919a28c649b4c3a89595c49812f176
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.25.3
1
+ 7.26.0
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ ##
5
+ # Renders a single section for facet limit with a specified
6
+ # solr field used for faceting. This renders no UI of it's own, but renders
7
+ # the component that is configured for the facet.
8
+ class FacetComponent < ViewComponent::Base
9
+ with_collection_parameter :display_facet_or_field_config
10
+
11
+ # @param [Blacklight::Solr::Response::Facets::FacetField] display_facet
12
+ # @param [Blacklight::Configuration] blacklight_config
13
+ # @param [Boolean] layout
14
+ def initialize(display_facet_or_field_config: nil, display_facet: nil, field_config: nil, response: nil, blacklight_config: nil, **component_args)
15
+ if display_facet_or_field_config.is_a?(Blacklight::Configuration::Field) || field_config
16
+ @field_config = display_facet_or_field_config || field_config
17
+ @display_facet = display_facet || (response && response.aggregations[@field_config.field])
18
+ elsif (display_facet || display_facet_or_field_config).respond_to?(:name)
19
+ @display_facet = display_facet || display_facet_or_field_config
20
+ @field_config = field_config || blacklight_config&.facet_configuration_for_field(@display_facet.name)
21
+ else
22
+ raise ArgumentError, 'You must provide one of display_facet or field_config' unless @field_config
23
+ end
24
+
25
+ @component_args = component_args
26
+ end
27
+
28
+ def render?
29
+ helpers.should_render_field?(@field_config, @display_facet)
30
+ end
31
+
32
+ def call
33
+ component = @field_config.component == true ? Blacklight::FacetFieldListComponent : @field_config.component
34
+
35
+ render(
36
+ component.new(
37
+ facet_field: helpers.facet_field_presenter(@field_config, @display_facet),
38
+ **@component_args
39
+ )
40
+ )
41
+ end
42
+ end
43
+ end
@@ -16,7 +16,7 @@ module Blacklight
16
16
  end
17
17
 
18
18
  def render?
19
- @facet_field.paginator.items.any?
19
+ @facet_field.paginator&.items&.any?
20
20
  end
21
21
  end
22
22
  end
@@ -4,6 +4,8 @@ module Blacklight
4
4
  class FacetItemComponent < Blacklight::Component
5
5
  extend Deprecation
6
6
 
7
+ attr_reader :label, :href, :hits
8
+
7
9
  with_collection_parameter :facet_item
8
10
 
9
11
  def initialize(facet_item:, wrapping_element: 'li', suppress_link: false)
@@ -48,9 +50,9 @@ module Blacklight
48
50
  def overridden_helper_methods?
49
51
  return false if explicit_component_configuration?
50
52
 
51
- @view_context.method(:render_facet_item).owner != Blacklight::FacetsHelperBehavior ||
52
- @view_context.method(:render_facet_value).owner != Blacklight::FacetsHelperBehavior ||
53
- @view_context.method(:render_selected_facet_value).owner != Blacklight::FacetsHelperBehavior
53
+ helpers.method(:render_facet_item).owner != Blacklight::FacetsHelperBehavior ||
54
+ helpers.method(:render_facet_value).owner != Blacklight::FacetsHelperBehavior ||
55
+ helpers.method(:render_selected_facet_value).owner != Blacklight::FacetsHelperBehavior
54
56
  end
55
57
 
56
58
  # Call out to the helper method equivalent of this component
@@ -72,7 +74,7 @@ module Blacklight
72
74
  # @private
73
75
  def render_facet_value
74
76
  tag.span(class: "facet-label") do
75
- link_to_unless(@suppress_link, @label, @href, class: "facet-select", rel: "nofollow")
77
+ link_to_unless(@suppress_link, label, href, class: "facet-select", rel: "nofollow")
76
78
  end + render_facet_count
77
79
  end
78
80
 
@@ -83,9 +85,9 @@ module Blacklight
83
85
  # @private
84
86
  def render_selected_facet_value
85
87
  tag.span(class: "facet-label") do
86
- tag.span(@label, class: "selected") +
88
+ tag.span(label, class: "selected") +
87
89
  # remove link
88
- link_to(@href, class: "remove", rel: "nofollow") do
90
+ link_to(href, class: "remove", rel: "nofollow") do
89
91
  tag.span('✖', class: "remove-icon", aria: { hidden: true }) +
90
92
  tag.span(helpers.t(:'blacklight.search.facets.selected.remove'), class: 'sr-only visually-hidden')
91
93
  end
@@ -101,12 +103,12 @@ module Blacklight
101
103
  # @return [String]
102
104
  # @private
103
105
  def render_facet_count(options = {})
104
- return helpers.render_facet_count(@hits, options) unless helpers.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration?
106
+ return helpers.render_facet_count(hits, options) unless helpers.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration?
105
107
 
106
- return '' if @hits.blank?
108
+ return '' if hits.blank?
107
109
 
108
110
  classes = (options[:classes] || []) << "facet-count"
109
- tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(@hits)), class: classes)
111
+ tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(hits)), class: classes)
110
112
  end
111
113
 
112
114
  private
@@ -76,13 +76,10 @@ module Blacklight::FacetsHelperBehavior
76
76
  field_config = facet_configuration_for_field(display_facet.name)
77
77
 
78
78
  if field_config.component
79
- return unless should_render_field?(field_config, display_facet)
80
-
81
- component = field_config.component == true ? Blacklight::FacetFieldListComponent : field_config.component
82
-
83
79
  return render(
84
- component.new(
85
- facet_field: facet_field_presenter(field_config, display_facet),
80
+ Blacklight::FacetComponent.new(
81
+ display_facet: display_facet,
82
+ field_config: field_config,
86
83
  layout: (params[:action] == 'facet' ? false : options[:layout])
87
84
  )
88
85
  )
@@ -107,9 +107,13 @@ module Blacklight::RenderConstraintsHelperBehavior
107
107
  safe_join(Array(values).map do |val|
108
108
  next if val.blank? # skip empty string
109
109
 
110
- presenter = facet_item_presenter(facet_config, val, facet)
111
-
112
110
  Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
111
+ presenter = if val.is_a? Array
112
+ inclusive_facet_item_presenter(facet_config, val, facet)
113
+ else
114
+ facet_item_presenter(facet_config, val, facet)
115
+ end
116
+
113
117
  render_constraint_element(presenter.field_label,
114
118
  presenter.label,
115
119
  remove: presenter.remove_href(search_state),
@@ -118,6 +122,10 @@ module Blacklight::RenderConstraintsHelperBehavior
118
122
  end, "\n")
119
123
  end
120
124
 
125
+ def inclusive_facet_item_presenter(facet_config, facet_item, facet_field)
126
+ Blacklight::InclusiveFacetItemPresenter.new(facet_item, facet_config, self, facet_field)
127
+ end
128
+
121
129
  # Render a label/value constraint on the screen. Can be called
122
130
  # by plugins and such to get application-defined rendering.
123
131
  #
@@ -199,7 +199,7 @@ RSpec.describe Blacklight::FacetsHelperBehavior do
199
199
 
200
200
  it "lets you override the rendered partial for pivot facets" do
201
201
  mock_facet = double(name: 'component_field')
202
- expect(helper).to receive(:render).with(an_instance_of(Blacklight::FacetFieldListComponent))
202
+ expect(helper).to receive(:render).with(an_instance_of(Blacklight::FacetComponent))
203
203
  helper.render_facet_limit(mock_facet)
204
204
  end
205
205
 
@@ -54,6 +54,14 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
54
54
  expect(subject).to have_link "Remove constraint Item Type: journal", href: "/catalog?q=biz"
55
55
  end
56
56
  end
57
+
58
+ context 'with multivalued facets' do
59
+ subject { helper.render_filter_element('type', [%w[journal book]], path) }
60
+
61
+ it "handles such values gracefully" do
62
+ expect(subject).to have_link "Remove constraint Item Type: journal OR book", href: "/catalog?q=biz"
63
+ end
64
+ end
57
65
  end
58
66
 
59
67
  describe "#render_constraints_filters" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.25.3
4
+ version: 7.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2022-05-24 00:00:00.000000000 Z
20
+ date: 2022-06-20 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -453,6 +453,7 @@ files:
453
453
  - app/components/blacklight/document_metadata_component.rb
454
454
  - app/components/blacklight/document_title_component.html.erb
455
455
  - app/components/blacklight/document_title_component.rb
456
+ - app/components/blacklight/facet_component.rb
456
457
  - app/components/blacklight/facet_field_checkboxes_component.html.erb
457
458
  - app/components/blacklight/facet_field_checkboxes_component.rb
458
459
  - app/components/blacklight/facet_field_component.html.erb