blacklight 7.13.0 → 7.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +109 -0
  3. data/README.md +0 -2
  4. data/VERSION +1 -1
  5. data/app/assets/javascripts/blacklight/blacklight.js +4 -2
  6. data/app/assets/stylesheets/blacklight/_header.scss +0 -5
  7. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +0 -1
  8. data/app/components/blacklight/advanced_search_form_component.html.erb +46 -0
  9. data/app/components/blacklight/advanced_search_form_component.rb +75 -0
  10. data/app/components/blacklight/constraint_component.html.erb +1 -1
  11. data/app/components/blacklight/constraints_component.rb +42 -17
  12. data/app/components/blacklight/document/thumbnail_component.html.erb +2 -2
  13. data/app/components/blacklight/document/thumbnail_component.rb +5 -2
  14. data/app/components/blacklight/document_component.rb +7 -2
  15. data/app/components/blacklight/document_metadata_component.rb +1 -1
  16. data/app/components/blacklight/facet_field_checkboxes_component.html.erb +23 -0
  17. data/app/components/blacklight/facet_field_checkboxes_component.rb +24 -0
  18. data/app/components/blacklight/facet_field_inclusive_constraint_component.html.erb +6 -0
  19. data/app/components/blacklight/facet_field_inclusive_constraint_component.rb +29 -0
  20. data/app/components/blacklight/facet_field_list_component.html.erb +1 -0
  21. data/app/components/blacklight/facet_field_pagination_component.html.erb +4 -4
  22. data/app/components/blacklight/facet_field_pagination_component.rb +0 -4
  23. data/app/components/blacklight/facet_item_component.rb +2 -0
  24. data/app/components/blacklight/hidden_search_state_component.rb +54 -0
  25. data/app/components/blacklight/search_bar_component.html.erb +14 -8
  26. data/app/components/blacklight/search_bar_component.rb +16 -1
  27. data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
  28. data/app/controllers/concerns/blacklight/catalog.rb +9 -3
  29. data/app/controllers/concerns/blacklight/search_context.rb +1 -1
  30. data/app/helpers/blacklight/component_helper_behavior.rb +1 -1
  31. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -2
  32. data/app/helpers/blacklight/facets_helper_behavior.rb +1 -1
  33. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +2 -38
  34. data/app/helpers/blacklight/icon_helper_behavior.rb +1 -1
  35. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +2 -2
  36. data/app/helpers/blacklight/render_partials_helper_behavior.rb +2 -2
  37. data/app/javascript/blacklight/button_focus.js +1 -0
  38. data/app/javascript/blacklight/modal.js +10 -4
  39. data/app/models/concerns/blacklight/suggest/response.rb +1 -1
  40. data/app/presenters/blacklight/clause_presenter.rb +37 -0
  41. data/app/presenters/blacklight/document_presenter.rb +5 -1
  42. data/app/presenters/blacklight/facet_field_presenter.rb +4 -0
  43. data/app/presenters/blacklight/facet_grouped_item_presenter.rb +45 -0
  44. data/app/presenters/blacklight/facet_item_presenter.rb +32 -20
  45. data/app/presenters/blacklight/field_presenter.rb +1 -1
  46. data/app/presenters/blacklight/inclusive_facet_item_presenter.rb +16 -0
  47. data/app/presenters/blacklight/search_bar_presenter.rb +4 -0
  48. data/app/values/blacklight/types.rb +1 -1
  49. data/app/views/bookmarks/_tools.html.erb +1 -1
  50. data/app/views/catalog/_advanced_search_form.html.erb +7 -0
  51. data/app/views/catalog/_advanced_search_help.html.erb +24 -0
  52. data/app/views/catalog/_search_form.html.erb +1 -0
  53. data/app/views/catalog/_zero_results.html.erb +1 -1
  54. data/app/views/catalog/advanced_search.html.erb +17 -0
  55. data/blacklight.gemspec +5 -4
  56. data/config/i18n-tasks.yml +1 -0
  57. data/config/locales/blacklight.en.yml +17 -0
  58. data/lib/blacklight/configuration.rb +2 -1
  59. data/lib/blacklight/configuration/field.rb +1 -1
  60. data/lib/blacklight/configuration/fields.rb +1 -1
  61. data/lib/blacklight/configuration/sort_field.rb +1 -1
  62. data/lib/blacklight/routes/searchable.rb +1 -0
  63. data/lib/blacklight/search_builder.rb +2 -0
  64. data/lib/blacklight/search_state.rb +5 -1
  65. data/lib/blacklight/search_state/filter_field.rb +17 -7
  66. data/lib/blacklight/solr/repository.rb +14 -5
  67. data/lib/blacklight/solr/response.rb +1 -1
  68. data/lib/blacklight/solr/search_builder_behavior.rb +87 -23
  69. data/package.json +1 -1
  70. data/spec/components/blacklight/advanced_search_form_component_spec.rb +51 -0
  71. data/spec/components/blacklight/constraint_layout_component_spec.rb +1 -1
  72. data/spec/components/blacklight/document_component_spec.rb +17 -0
  73. data/spec/components/blacklight/facet_field_checkboxes_component_spec.rb +55 -0
  74. data/spec/components/blacklight/facet_field_list_component_spec.rb +39 -4
  75. data/spec/components/blacklight/hidden_search_state_component_spec.rb +24 -0
  76. data/spec/controllers/catalog_controller_spec.rb +9 -0
  77. data/spec/features/advanced_search_spec.rb +67 -0
  78. data/spec/features/bookmarks_spec.rb +1 -9
  79. data/spec/features/facets_spec.rb +2 -17
  80. data/spec/features/search_filters_spec.rb +0 -20
  81. data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +1 -0
  82. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +1 -0
  83. data/spec/lib/blacklight/search_state/filter_field_spec.rb +65 -0
  84. data/spec/models/blacklight/solr/repository_spec.rb +12 -0
  85. data/spec/models/blacklight/solr/response/facets_spec.rb +1 -1
  86. data/spec/models/blacklight/solr/search_builder_spec.rb +28 -0
  87. data/spec/presenters/blacklight/clause_presenter_spec.rb +34 -0
  88. data/spec/presenters/blacklight/document_presenter_spec.rb +13 -0
  89. data/spec/presenters/blacklight/facet_grouped_item_presenter_spec.rb +41 -0
  90. data/spec/spec_helper.rb +8 -3
  91. data/spec/test_app_templates/Gemfile.extra +1 -1
  92. data/spec/views/catalog/_document.html.erb_spec.rb +1 -0
  93. data/spec/views/catalog/_thumbnail.html.erb_spec.rb +2 -0
  94. data/tasks/blacklight.rake +3 -3
  95. metadata +67 -28
  96. data/.travis.yml +0 -40
@@ -15,7 +15,7 @@ module Blacklight
15
15
  end
16
16
 
17
17
  def field_component(field)
18
- field.try(:component) || Blacklight::MetadataFieldComponent
18
+ field&.component || Blacklight::MetadataFieldComponent
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,23 @@
1
+ <%= render(@layout.new(facet_field: @facet_field)) do |component| %>
2
+ <% component.with(:label) do %>
3
+ <%= @facet_field.label %>
4
+ <% end %>
5
+
6
+ <% component.with(:body) do %>
7
+ <ul class="facet-values list-unstyled blacklight-facet-checkboxes">
8
+ <% presenters.each_with_index do |presenter, idx| -%>
9
+ <li>
10
+ <span class="facet-checkbox">
11
+ <%= check_box_tag "f_inclusive[#{@facet_field.key}][]", presenter.value, presenter.selected?, id: "f_inclusive_#{@facet_field.key}_#{idx}"%>
12
+ </span>
13
+
14
+ <span class="label-and-count">
15
+ <%= label_tag "f_inclusive_#{@facet_field.key}_#{idx}" do %>
16
+ <%= presenter.label %>
17
+ <% end %>
18
+ <span>
19
+ </li>
20
+ <% end -%>
21
+ </ul>
22
+ <% end %>
23
+ <% end %>
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class FacetFieldCheckboxesComponent < ::ViewComponent::Base
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::FacetItemPresenter.new(item, @facet_field.facet_field, @view_context, @facet_field.key, @facet_field.search_state)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ <div class="inclusive_or card card-body bg-light mb-3">
2
+ <h5><%= t('blacklight.advanced_search.any_of') %></h5>
3
+ <ul class="list-unstyled facet-values">
4
+ <%= @view_context.render(Blacklight::FacetItemComponent.with_collection(presenters.to_a)) %>
5
+ </ul>
6
+ </div>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class FacetFieldInclusiveConstraintComponent < ::ViewComponent::Base
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, @view_context, @facet_field.key, @facet_field.search_state)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -3,6 +3,7 @@
3
3
  <%= @facet_field.label %>
4
4
  <% end %>
5
5
  <% component.with(:body) do %>
6
+ <%= @view_context.render(Blacklight::FacetFieldInclusiveConstraintComponent.new(facet_field: @facet_field)) %>
6
7
  <ul class="facet-values list-unstyled">
7
8
  <%= render_facet_limit_list @facet_field.paginator, @facet_field.key %>
8
9
  </ul>
@@ -1,9 +1,9 @@
1
1
  <div class="prev_next_links btn-group">
2
- <%= link_to_previous_page @facet_field.paginator, raw(t('views.pagination.previous')), params: @facet_field.search_state.to_h, param_name: param_name, class: 'btn btn-link', data: { blacklight_modal: "preserve" } do %>
2
+ <%= @view_context.link_to_previous_page @facet_field.paginator, raw(t('views.pagination.previous')), params: @facet_field.search_state.to_h, param_name: param_name, class: 'btn btn-link', data: { blacklight_modal: "preserve" } do %>
3
3
  <%= content_tag :span, raw(t('views.pagination.previous')), class: 'disabled btn' %>
4
4
  <% end %>
5
5
 
6
- <%= link_to_next_page @facet_field.paginator, raw(t('views.pagination.next')), params: @facet_field.search_state.to_h, param_name: param_name, class: 'btn btn-link', data: { blacklight_modal: "preserve" } do %>
6
+ <%= @view_context.link_to_next_page @facet_field.paginator, raw(t('views.pagination.next')), params: @facet_field.search_state.to_h, param_name: param_name, class: 'btn btn-link', data: { blacklight_modal: "preserve" } do %>
7
7
  <%= content_tag :span, raw(t('views.pagination.next')), class: 'disabled btn' %>
8
8
  <% end %>
9
9
  </div>
@@ -11,9 +11,9 @@
11
11
  <div class="sort-options btn-group">
12
12
  <% if @facet_field.paginator.sort == 'index' -%>
13
13
  <span class="active az btn btn-outline-secondary"><%= t('blacklight.search.facets.sort.index') %></span>
14
- <%= link_to(t('blacklight.search.facets.sort.count'), sort_facet_url('count'), class: "sort_change numeric btn btn-outline-secondary", data: { blacklight_modal: "preserve" }) %>
14
+ <%= @view_context.link_to(t('blacklight.search.facets.sort.count'), sort_facet_url('count'), class: "sort_change numeric btn btn-outline-secondary", data: { blacklight_modal: "preserve" }) %>
15
15
  <% elsif @facet_field.paginator.sort == 'count' -%>
16
- <%= link_to(t('blacklight.search.facets.sort.index'), sort_facet_url('index'), class: "sort_change az btn btn-outline-secondary", data: { blacklight_modal: "preserve" }) %>
16
+ <%= @view_context.link_to(t('blacklight.search.facets.sort.index'), sort_facet_url('index'), class: "sort_change az btn btn-outline-secondary", data: { blacklight_modal: "preserve" }) %>
17
17
  <span class="active numeric btn btn-outline-secondary"><%= t('blacklight.search.facets.sort.count') %></span>
18
18
  <% end -%>
19
19
  </div>
@@ -6,10 +6,6 @@ module Blacklight
6
6
  @facet_field = facet_field
7
7
  end
8
8
 
9
- def render?
10
- @facet_field.facet_field.index_range&.any?
11
- end
12
-
13
9
  def sort_facet_url(sort)
14
10
  @facet_field.paginator.params_for_resort_url(sort, @facet_fieldsearch_state.to_h)
15
11
  end
@@ -103,6 +103,8 @@ module Blacklight
103
103
  def render_facet_count(options = {})
104
104
  return @view_context.render_facet_count(@hits, options) unless @view_context.method(:render_facet_count).owner == Blacklight::FacetsHelperBehavior || explicit_component_configuration?
105
105
 
106
+ return '' if @hits.blank?
107
+
106
108
  classes = (options[:classes] || []) << "facet-count"
107
109
  tag.span(t('blacklight.search.facets.count', number: number_with_delimiter(@hits)), class: classes)
108
110
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ # Writes out zero or more <input type="hidden"> elements, completely
5
+ # representing a hash passed in using Rails-style request parameters
6
+ # for hashes nested with arrays and other hashes.
7
+ class HiddenSearchStateComponent < ::ViewComponent::Base
8
+ # @param [Hash] hash
9
+ def initialize(params:)
10
+ Deprecation.warn(self, "Passing page as a parameter to HiddenSearchStateComponent is deprecated and will not be supported in Blacklight 8") if params.key?(:page)
11
+ @params = params.except(:utf8)
12
+ end
13
+
14
+ def call
15
+ hidden_fields = []
16
+ flatten_hash(@params).each do |name, value|
17
+ value = Array.wrap(value)
18
+ value.each do |v|
19
+ hidden_fields << hidden_field_tag(name, v.to_s, id: nil)
20
+ end
21
+ end
22
+
23
+ safe_join(hidden_fields, "\n")
24
+ end
25
+
26
+ private
27
+
28
+ def flatten_hash(hash = params, ancestor_names = [])
29
+ flat_hash = {}
30
+ hash.each do |k, v|
31
+ names = Array.new(ancestor_names)
32
+ names << k
33
+ if v.is_a?(Hash)
34
+ flat_hash.merge!(flatten_hash(v, names))
35
+ else
36
+ key = flat_hash_key(names)
37
+ key += "[]" if v.is_a?(Array)
38
+ flat_hash[key] = v
39
+ end
40
+ end
41
+
42
+ flat_hash
43
+ end
44
+
45
+ def flat_hash_key(names)
46
+ names = Array.new(names)
47
+ name = names.shift.to_s.dup
48
+ names.each do |n|
49
+ name << "[#{n}]"
50
+ end
51
+ name
52
+ end
53
+ end
54
+ end
@@ -1,29 +1,35 @@
1
- <%= form_tag @url, method: @method, class: @classes.join(' '), role: 'search', 'aria-label' => t('blacklight.search.form.submit') do %>
1
+ <%= form_tag @url, method: @method, class: @classes.join(' '), role: 'search', 'aria-label' => scoped_t('submit') do %>
2
2
  <%= render_hash_as_hidden_fields(@params) %>
3
3
  <% if @search_fields.length > 1 %>
4
- <label for="search_field" class="sr-only"><%= t('blacklight.search.form.search_field.label') %></label>
4
+ <label for="search_field" class="sr-only"><%= scoped_t('search_field.label') %></label>
5
5
  <% end %>
6
6
  <div class="input-group">
7
+ <%= prepend %>
8
+
7
9
  <% if @search_fields.length > 1 %>
8
10
  <%= select_tag(:search_field,
9
11
  options_for_select(@search_fields, h(@search_field)),
10
- title: t('blacklight.search.form.search_field.title'),
12
+ title: scoped_t('search_field.title'),
11
13
  id: "#{@prefix}search_field",
12
14
  class: "custom-select search-field") %>
13
15
  <% elsif @search_fields.length == 1 %>
14
16
  <%= hidden_field_tag :search_field, @search_fields.first.last %>
15
17
  <% end %>
16
18
 
17
- <label for="<%= @prefix %>q" class="sr-only"><%= t('blacklight.search.form.search.label') %></label>
18
- <%= text_field_tag :q, @q, placeholder: t('blacklight.search.form.search.placeholder'), class: "search-q q form-control rounded-#{@search_fields.length > 1 ? '0' : 'left'}", id: "#{@prefix}q", autocomplete: autocomplete_path.present? ? "off" : "", autofocus: @autofocus, data: { autocomplete_enabled: autocomplete_path.present?, autocomplete_path: autocomplete_path } %>
19
-
20
- <%= content %>
19
+ <label for="<%= @prefix %><%= @query_param %>" class="sr-only"><%= scoped_t('search.label') %></label>
20
+ <%= text_field_tag @query_param, @q, placeholder: scoped_t('search.placeholder'), class: "search-q q form-control rounded-#{@search_fields.length > 1 ? '0' : 'left'}", id: "#{@prefix}q", autocomplete: autocomplete_path.present? ? "off" : "", autofocus: @autofocus, data: { autocomplete_enabled: autocomplete_path.present?, autocomplete_path: autocomplete_path } %>
21
21
 
22
22
  <span class="input-group-append">
23
+ <%= append %>
24
+
23
25
  <button type="submit" class="btn btn-primary search-btn" id="<%= @prefix %>search">
24
- <span class="submit-search-text"><%= t('blacklight.search.form.submit') %></span>
26
+ <span class="submit-search-text"><%= scoped_t('submit') %></span>
25
27
  <%= blacklight_icon :search, aria_hidden: true %>
26
28
  </button>
27
29
  </span>
28
30
  </div>
29
31
  <% end %>
32
+
33
+ <% if presenter.advanced_search_enabled? %>
34
+ <%= link_to t('blacklight.advanced_search.more_options'), @advanced_search_url, class: 'advanced_search btn btn-secondary'%>
35
+ <% end %>
@@ -2,10 +2,20 @@
2
2
 
3
3
  module Blacklight
4
4
  class SearchBarComponent < ::ViewComponent::Base
5
+ with_content_areas :append, :prepend
6
+
5
7
  # rubocop:disable Metrics/ParameterLists
6
- def initialize(url:, params:, classes: ['search-query-form'], presenter: nil, prefix: '', method: 'GET', q: nil, search_field: nil, search_fields: [], autocomplete_path: nil, autofocus: nil)
8
+ def initialize(
9
+ url:, advanced_search_url: nil, params:,
10
+ classes: ['search-query-form'], presenter: nil, prefix: '',
11
+ method: 'GET', q: nil, query_param: :q,
12
+ search_field: nil, search_fields: [], autocomplete_path: nil,
13
+ autofocus: nil, i18n: { scope: 'blacklight.search.form' }
14
+ )
7
15
  @url = url
16
+ @advanced_search_url = advanced_search_url
8
17
  @q = q || params[:q]
18
+ @query_param = query_param
9
19
  @search_field = search_field || params[:search_field]
10
20
  @params = params.except(:q, :search_field, :utf8, :page)
11
21
  @prefix = prefix
@@ -15,6 +25,7 @@ module Blacklight
15
25
  @autocomplete_path = autocomplete_path
16
26
  @autofocus = autofocus
17
27
  @search_fields = search_fields
28
+ @i18n = i18n
18
29
  end
19
30
  # rubocop:enable Metrics/ParameterLists
20
31
 
@@ -47,5 +58,9 @@ module Blacklight
47
58
  @view_context.render_hash_as_hidden_fields(*args)
48
59
  end
49
60
  end
61
+
62
+ def scoped_t(key, **args)
63
+ t(key, default: t(key, scope: 'blacklight.search.form'), **@i18n, **args)
64
+ end
50
65
  end
51
66
  end
@@ -25,7 +25,7 @@ module Blacklight::Bookmarks
25
25
  def action_documents
26
26
  bookmarks = token_or_current_or_guest_user.bookmarks
27
27
  bookmark_ids = bookmarks.collect { |b| b.document_id.to_s }
28
- search_service.fetch(bookmark_ids)
28
+ search_service.fetch(bookmark_ids, rows: bookmark_ids.count)
29
29
  end
30
30
 
31
31
  def action_success_redirect_path
@@ -56,6 +56,12 @@ module Blacklight::Catalog
56
56
  end
57
57
  end
58
58
 
59
+ def advanced_search
60
+ empty_service = search_service_class.new(config: blacklight_config, user_params: {}, **search_service_context)
61
+
62
+ (@response, _deprecated_document_list) = empty_service.search_results
63
+ end
64
+
59
65
  # get a single document from the index
60
66
  def raw
61
67
  raise(ActionController::RoutingError, 'Not Found') unless blacklight_config.raw_endpoint.enabled
@@ -133,7 +139,7 @@ module Blacklight::Catalog
133
139
  # Check if any search parameters have been set
134
140
  # @return [Boolean]
135
141
  def has_search_parameters?
136
- params[:q].present? || params[:f].present? || params[:search_field].present?
142
+ params[:search_field].present? || search_state.has_constraints?
137
143
  end
138
144
 
139
145
  # TODO: deprecate this constant with #facet_limit_for
@@ -316,11 +322,11 @@ module Blacklight::Catalog
316
322
  # If there are errors coming from the index page, we want to trap those sensibly
317
323
 
318
324
  if flash[:notice] == flash_notice
319
- logger.error "Cowardly aborting rsolr_request_error exception handling, because we redirected to a page that raises another exception"
325
+ logger&.error "Cowardly aborting rsolr_request_error exception handling, because we redirected to a page that raises another exception"
320
326
  raise exception
321
327
  end
322
328
 
323
- logger.error exception
329
+ logger&.error exception
324
330
 
325
331
  flash[:notice] = flash_notice
326
332
  redirect_to search_action_url
@@ -117,7 +117,7 @@ module Blacklight::SearchContext
117
117
  { prev: documents.first, next: documents.last }
118
118
  end
119
119
  rescue Blacklight::Exceptions::InvalidRequest => e
120
- logger.warn "Unable to setup next and previous documents: #{e}"
120
+ logger&.warn "Unable to setup next and previous documents: #{e}"
121
121
  nil
122
122
  end
123
123
  end
@@ -10,7 +10,7 @@ module Blacklight
10
10
  deprecation_deprecate :document_action_label
11
11
 
12
12
  # @deprecated
13
- def document_action_path action_opts, url_opts = nil
13
+ def document_action_path action_opts, url_opts = {}
14
14
  if action_opts.path
15
15
  send(action_opts.path, url_opts)
16
16
  elsif url_opts[:id].class.respond_to?(:model_name)
@@ -189,7 +189,7 @@ module Blacklight::ConfigurationHelperBehavior
189
189
 
190
190
  field = fields.first if document.nil?
191
191
  field ||= fields.find { |f| document.has? f }
192
- field &&= field.try(:to_sym)
192
+ field &&= field&.to_sym
193
193
 
194
194
  field
195
195
  end
@@ -198,7 +198,7 @@ module Blacklight::ConfigurationHelperBehavior
198
198
  ##
199
199
  # Default sort field
200
200
  def default_sort_field
201
- (active_sort_fields.find { |_k, config| config.respond_to?(:default) && config.default } || active_sort_fields.first).try(:last)
201
+ (active_sort_fields.find { |_k, config| config.respond_to?(:default) && config.default } || active_sort_fields.first)&.last
202
202
  end
203
203
 
204
204
  ##
@@ -180,7 +180,7 @@ module Blacklight::FacetsHelperBehavior
180
180
  # @return [String]
181
181
  def facet_partial_name(display_facet = nil)
182
182
  config = facet_configuration_for_field(display_facet.name)
183
- name = config.try(:partial)
183
+ name = config.partial
184
184
  name ||= "facet_pivot" if config.pivot
185
185
  name || "facet_limit"
186
186
  end
@@ -21,43 +21,7 @@ module Blacklight::HashAsHiddenFieldsHelperBehavior
21
21
  # @param [Hash] hash
22
22
  # @return [String]
23
23
  def render_hash_as_hidden_fields(hash)
24
- hidden_fields = []
25
- flatten_hash(hash).each do |name, value|
26
- value = Array.wrap(value)
27
- value.each do |v|
28
- hidden_fields << hidden_field_tag(name, v.to_s, id: nil)
29
- end
30
- end
31
-
32
- safe_join(hidden_fields, "\n")
33
- end
34
- deprecation_deprecate render_hash_as_hidden_fields: 'Moving to a private method of Blacklight::SearchBarComponent'
35
-
36
- private
37
-
38
- def flatten_hash(hash = params, ancestor_names = [])
39
- flat_hash = {}
40
- hash.each do |k, v|
41
- names = Array.new(ancestor_names)
42
- names << k
43
- if v.is_a?(Hash)
44
- flat_hash.merge!(flatten_hash(v, names))
45
- else
46
- key = flat_hash_key(names)
47
- key += "[]" if v.is_a?(Array)
48
- flat_hash[key] = v
49
- end
50
- end
51
-
52
- flat_hash
53
- end
54
-
55
- def flat_hash_key(names)
56
- names = Array.new(names)
57
- name = names.shift.to_s.dup
58
- names.each do |n|
59
- name << "[#{n}]"
60
- end
61
- name
24
+ render Blacklight::HiddenSearchStateComponent.new(params: hash)
62
25
  end
26
+ deprecation_deprecate render_hash_as_hidden_fields: 'Use Blacklight::HiddenSearchStateComponent instead'
63
27
  end
@@ -12,7 +12,7 @@ module Blacklight::IconHelperBehavior
12
12
  def blacklight_icon(icon_name, options = {})
13
13
  Rails.cache.fetch([:blacklight_icons, icon_name, options]) do
14
14
  icon = Blacklight::Icon.new(icon_name, **options)
15
- tag.span(icon.svg.html_safe, icon.options)
15
+ tag.span(icon.svg.html_safe, **icon.options)
16
16
  end
17
17
  end
18
18
  end
@@ -88,8 +88,8 @@ module Blacklight::RenderConstraintsHelperBehavior
88
88
  return "".html_safe if search_state.filter_params.blank?
89
89
 
90
90
  Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
91
- safe_join(search_state.filter_params.each_pair.map do |facet, values|
92
- render_filter_element(facet, values, search_state)
91
+ safe_join(search_state.filters.map do |field|
92
+ render_filter_element(field.key, field.values, search_state)
93
93
  end, "\n")
94
94
  end
95
95
  end