blacklight 7.26.1 → 7.27.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: 5943737d0e65f97d49929bd5e1698de5f42a3cea352150f56e2417834ef307ea
4
- data.tar.gz: e2ddfa33c4e1cf788a22084e9465acad0a530ea9d714e820c91805f09a8a2b80
3
+ metadata.gz: 39fe32f4252deb7d8bb08a1d2781a8d1af7e387eb2bafc93fc083cd13eda9b21
4
+ data.tar.gz: f0b41d058163f54ca1f5a11b745077c8404eea4f8cea43d87c8ea4e6d6ed0d30
5
5
  SHA512:
6
- metadata.gz: 2d8f7cfb29344d217c4f8f1929fa9ac422567b59ab47d893ccea78f425be5524f75e1456f19fc3bfc25b7211f17b152f7de0a02733bfe4c9bb7f9fd0b6044219
7
- data.tar.gz: 6219cde27cd67bfb826532d2b08b6d50a720104a12525251dc79b59a35bb9be0ba5f776f5d6b2e09a3fcbecf410445ba827d4ba85b9106c00a52fe7424aea8f0
6
+ metadata.gz: e02cee90b4acb73a5b3fe4883c2a076f37146200fdec169bc3bbf0012ffcd79e5244019ee703c97c601f7100bdaecacf65617dccbc2050911b0fa4e7a24eefbd
7
+ data.tar.gz: 80036e1203a14f9d7f90e11a8fd02309e447d29be4f1deb4250d7628a3bcfad1ed00e43d57d9152fd1fff751e27e983af0adb0747978978039a6d1d81309e688
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.26.1
1
+ 7.27.0
@@ -11,11 +11,19 @@ module Blacklight
11
11
  # @param [Blacklight::Solr::Response::Facets::FacetField] display_facet
12
12
  # @param [Blacklight::Configuration] blacklight_config
13
13
  # @param [Boolean] layout
14
+ # rubocop:disable Metrics/CyclomaticComplexity
14
15
  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
+ if display_facet_or_field_config.is_a? Blacklight::FacetFieldPresenter
17
+ @facet_field_presenter = display_facet_or_field_config
18
+ @field_config = @facet_field_presenter.facet_field
19
+ @display_facet = @facet_field_presenter.display_facet
20
+ elsif display_facet_or_field_config.is_a?(Blacklight::Configuration::Field) || field_config
21
+ @facet_field_presenter = nil # we need the view context to generate this
16
22
  @field_config = display_facet_or_field_config || field_config
17
- @display_facet = display_facet || (response && response.aggregations[@field_config.field])
23
+ @display_facet = display_facet ||
24
+ response&.aggregations&.fetch(@field_config.field) { Blacklight::Solr::Response::Facets::NullFacetField.new(@field_config.field, response: response) }
18
25
  elsif (display_facet || display_facet_or_field_config).respond_to?(:name)
26
+ @facet_field_presenter = nil # we need the view context to generate this
19
27
  @display_facet = display_facet || display_facet_or_field_config
20
28
  @field_config = field_config || blacklight_config&.facet_configuration_for_field(@display_facet.name)
21
29
  else
@@ -24,20 +32,27 @@ module Blacklight
24
32
 
25
33
  @component_args = component_args
26
34
  end
35
+ # rubocop:enable Metrics/CyclomaticComplexity
27
36
 
28
37
  def render?
29
38
  helpers.should_render_field?(@field_config, @display_facet)
30
39
  end
31
40
 
32
41
  def call
42
+ return render_partial if @field_config.partial
43
+
33
44
  component = @field_config.component == true ? Blacklight::FacetFieldListComponent : @field_config.component
34
45
 
35
46
  render(
36
47
  component.new(
37
- facet_field: helpers.facet_field_presenter(@field_config, @display_facet),
48
+ facet_field: @facet_field_presenter || helpers.facet_field_presenter(@field_config, @display_facet),
38
49
  **@component_args
39
50
  )
40
51
  )
41
52
  end
53
+
54
+ def render_partial
55
+ helpers.render(@field_config.partial, locals: { field_name: @field_config.field, facet_field: @field_config, display_facet: @display_facet }.merge(@component_args))
56
+ end
42
57
  end
43
58
  end
@@ -60,9 +60,7 @@ module Blacklight::Catalog
60
60
  end
61
61
 
62
62
  def advanced_search
63
- empty_service = search_service_class.new(config: blacklight_config, user_params: {}, **search_service_context)
64
-
65
- (@response, _deprecated_document_list) = empty_service.search_results
63
+ (@response, _deprecated_document_list) = blacklight_advanced_search_form_search_service.search_results
66
64
  end
67
65
 
68
66
  # get a single document from the index
@@ -334,4 +332,14 @@ module Blacklight::Catalog
334
332
  flash[:notice] = flash_notice
335
333
  redirect_to search_action_url
336
334
  end
335
+
336
+ def blacklight_advanced_search_form_search_service
337
+ form_search_state = search_state_class.new(blacklight_advanced_search_form_params, blacklight_config, self)
338
+
339
+ search_service_class.new(config: blacklight_config, search_state: form_search_state, user_params: form_search_state.to_h, **search_service_context)
340
+ end
341
+
342
+ def blacklight_advanced_search_form_params
343
+ {}
344
+ end
337
345
  end
@@ -35,7 +35,7 @@ module Blacklight::RenderConstraintsHelperBehavior
35
35
  end
36
36
 
37
37
  Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
38
- render_constraints_query(params_or_search_state) + render_constraints_filters(params_or_search_state)
38
+ render_constraints_query(params_or_search_state) + render_constraints_clauses(params_or_search_state) + render_constraints_filters(params_or_search_state)
39
39
  end
40
40
  end
41
41
 
@@ -60,6 +60,24 @@ module Blacklight::RenderConstraintsHelperBehavior
60
60
  end
61
61
  end
62
62
 
63
+ ##
64
+ # Render the query constraints
65
+ #
66
+ # @deprecated
67
+ # @param [Blacklight::SearchState,ActionController::Parameters] params_or_search_state query parameters
68
+ # @return [String]
69
+ def render_constraints_clauses(params_or_search_state = search_state)
70
+ search_state = convert_to_search_state(params_or_search_state)
71
+
72
+ clause_presenters = search_state.clause_params.map do |key, clause|
73
+ field_config = blacklight_config.search_fields[clause[:field]]
74
+ Blacklight::ClausePresenter.new(key, clause, field_config, self, search_state)
75
+ end
76
+
77
+ render(Blacklight::ConstraintComponent.with_collection(clause_presenters))
78
+ end
79
+ deprecation_deprecate :render_constraints_clauses
80
+
63
81
  ##
64
82
  # Provide a url for removing a particular constraint. This can be overriden
65
83
  # in the case that you want parameters other than the defaults to be removed
@@ -25,7 +25,7 @@ module Blacklight
25
25
  end
26
26
 
27
27
  def remove_href(path = search_state)
28
- view_context.search_action_path(path.reset_search(clause: path.clause_params.except(key)))
28
+ view_context.search_action_path(path.reset_search(clause: path.clause_params.except(key)).to_h)
29
29
  end
30
30
 
31
31
  private
@@ -1,5 +1,5 @@
1
1
  <% if render_show_doc_actions_method_from_blacklight? %>
2
- <%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools", wrapping_tag: 'span', wrapping_classes: 'btn btn-outline-primary', link_classes: '', actions: document_actions(document_list, options: { document: nil }), options: { document_list: @response.documents }, url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h))) %>
2
+ <%= render(Blacklight::Document::ActionsComponent.new(document: nil, tag: 'div', classes: "#{controller_name}Tools", link_classes: 'btn btn-outline-primary', actions: document_actions(document_list, options: { document: nil }), options: { document_list: @response.documents }, url_opts: Blacklight::Parameters.sanitize(params.to_unsafe_h))) %>
3
3
  <% else %>
4
4
  <% Deprecation.warn(self, '#render_show_doc_actions is deprecated; use ActionComponents instead') %>
5
5
  <ul class="<%= controller_name %>Tools nav nav-pills">
@@ -99,6 +99,12 @@ module Blacklight::Solr::Response::Facets
99
99
  end
100
100
  end
101
101
 
102
+ class NullFacetField < FacetField
103
+ def initialize name, items = [], response: nil, **kwargs
104
+ super(name, items, response: response, **kwargs)
105
+ end
106
+ end
107
+
102
108
  ##
103
109
  # Get all the Solr facet data (fields, queries, pivots) as a hash keyed by
104
110
  # both the Solr field name and/or by the blacklight field name
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Blacklight::FacetComponent, type: :component do
6
+ subject(:rendered) do
7
+ render_inline_to_capybara_node(component)
8
+ end
9
+
10
+ let(:component) { described_class.new(**component_kwargs) }
11
+ let(:component_kwargs) { { field_config: facet_config, display_facet: display_facet } }
12
+ let(:items) { [{ label: "Book", value: 'Book', hits: 20 }] }
13
+
14
+ let(:display_facet) do
15
+ instance_double(Blacklight::Solr::Response::Facets::FacetField, name: 'field', items: items, limit: nil, sort: :index, offset: 0, prefix: nil)
16
+ end
17
+
18
+ let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'field', component: Blacklight::FacetFieldListComponent).normalize! }
19
+
20
+ before do
21
+ allow(controller).to receive(:view_context).and_return(controller.view_context)
22
+ allow(controller.view_context).to receive(:facet_limit_for).and_return(20)
23
+ end
24
+
25
+ it 'delegates to the configured component to render something' do
26
+ expect(rendered).to have_selector 'ul.facet-values'
27
+ end
28
+
29
+ context 'with a facet configured to use a partial' do
30
+ let(:facet_config) do
31
+ Blacklight::Configuration::FacetField.new(key: 'field', partial: 'catalog/facet_partial').normalize!
32
+ end
33
+
34
+ before do
35
+ controller.view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for('catalog/_facet_partial.html.erb' => 'facet partial'))
36
+ end
37
+
38
+ it 'renders the partial' do
39
+ expect(rendered).to have_content 'facet partial'
40
+ end
41
+ end
42
+
43
+ context 'with a field and response' do
44
+ let(:component_kwargs) do
45
+ { display_facet_or_field_config: facet_config, response: response }
46
+ end
47
+
48
+ let(:response) { instance_double(Blacklight::Solr::Response, aggregations: { 'field' => display_facet }) }
49
+
50
+ it 'extracts the facet data from the response to pass on to the rendering component' do
51
+ allow(facet_config.component).to receive(:new).and_call_original
52
+
53
+ rendered
54
+
55
+ expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: display_facet))
56
+ end
57
+
58
+ context 'when the field is not in the response' do
59
+ let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'some_other_field', component: Blacklight::FacetFieldListComponent).normalize! }
60
+
61
+ it 'uses a null field to pass through the response information anyway' do
62
+ allow(facet_config.component).to receive(:new).and_call_original
63
+
64
+ rendered
65
+
66
+ expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: have_attributes(items: [], response: response)))
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'with a display facet and configuration' do
72
+ let(:component_kwargs) do
73
+ { display_facet_or_field_config: display_facet, blacklight_config: blacklight_config }
74
+ end
75
+
76
+ let(:blacklight_config) { Blacklight::Configuration.new.tap { |config| config.facet_fields['field'] = facet_config } }
77
+
78
+ it 'pulls the facet config from the blacklight config' do
79
+ allow(facet_config.component).to receive(:new).and_call_original
80
+
81
+ rendered
82
+
83
+ expect(facet_config.component).to have_received(:new).with(facet_field: have_attributes(facet_field: facet_config, display_facet: display_facet))
84
+ end
85
+ end
86
+
87
+ context 'with a presenter' do
88
+ let(:component_kwargs) do
89
+ { display_facet_or_field_config: presenter }
90
+ end
91
+
92
+ let(:presenter) { Blacklight::FacetFieldPresenter.new(facet_config, display_facet, controller.view_context) }
93
+
94
+ it 'renders the component with the provided presenter' do
95
+ allow(facet_config.component).to receive(:new).and_call_original
96
+
97
+ rendered
98
+
99
+ expect(facet_config.component).to have_received(:new).with(facet_field: presenter)
100
+ end
101
+ end
102
+ end
@@ -6,6 +6,7 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
6
6
  let(:config) do
7
7
  Blacklight::Configuration.new do |config|
8
8
  config.add_facet_field 'type'
9
+ config.add_search_field 'title'
9
10
  end
10
11
  end
11
12
 
@@ -31,6 +32,21 @@ RSpec.describe Blacklight::RenderConstraintsHelperBehavior do
31
32
  end
32
33
  end
33
34
 
35
+ describe '#render_constraints_clauses' do
36
+ subject { helper.render_constraints_clauses(params) }
37
+
38
+ let(:my_engine) { double("Engine") }
39
+ let(:params) { ActionController::Parameters.new(clause: { "0": { field: 'title', query: 'nature' } }, f: { type: 'journal' }) }
40
+
41
+ it 'renders the clause constraint' do
42
+ expect(subject).to have_selector '.constraint-value', text: /Title\s+nature/
43
+ end
44
+
45
+ it "has a link relative to the current url" do
46
+ expect(subject).to have_link 'Remove constraint Title: nature', href: '/catalog?f%5Btype%5D%5B%5D=journal'
47
+ end
48
+ end
49
+
34
50
  describe '#render_filter_element' do
35
51
  subject { helper.render_filter_element('type', ['journal'], path) }
36
52
 
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.26.1
4
+ version: 7.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -14,10 +14,10 @@ authors:
14
14
  - Dan Funk
15
15
  - Naomi Dushay
16
16
  - Justin Coyne
17
- autorequire:
17
+ autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2022-06-27 00:00:00.000000000 Z
20
+ date: 2022-07-01 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -780,6 +780,7 @@ files:
780
780
  - spec/components/blacklight/document/group_component_spec.rb
781
781
  - spec/components/blacklight/document_component_spec.rb
782
782
  - spec/components/blacklight/document_metadata_component_spec.rb
783
+ - spec/components/blacklight/facet_component_spec.rb
783
784
  - spec/components/blacklight/facet_field_checkboxes_component_spec.rb
784
785
  - spec/components/blacklight/facet_field_list_component_spec.rb
785
786
  - spec/components/blacklight/facet_item_component_spec.rb
@@ -932,7 +933,7 @@ homepage: http://projectblacklight.org/
932
933
  licenses:
933
934
  - Apache 2.0
934
935
  metadata: {}
935
- post_install_message:
936
+ post_install_message:
936
937
  rdoc_options: []
937
938
  require_paths:
938
939
  - lib
@@ -947,8 +948,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
947
948
  - !ruby/object:Gem::Version
948
949
  version: '0'
949
950
  requirements: []
950
- rubygems_version: 3.2.32
951
- signing_key:
951
+ rubygems_version: 3.1.2
952
+ signing_key:
952
953
  specification_version: 4
953
954
  summary: Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr)
954
955
  index.
@@ -960,6 +961,7 @@ test_files:
960
961
  - spec/components/blacklight/document/group_component_spec.rb
961
962
  - spec/components/blacklight/document_component_spec.rb
962
963
  - spec/components/blacklight/document_metadata_component_spec.rb
964
+ - spec/components/blacklight/facet_component_spec.rb
963
965
  - spec/components/blacklight/facet_field_checkboxes_component_spec.rb
964
966
  - spec/components/blacklight/facet_field_list_component_spec.rb
965
967
  - spec/components/blacklight/facet_item_component_spec.rb