Sha256: 52e5b634ad0885ab03149afe40ab66ec167c9236a60ec1700169a01d98c52e4d

Contents?: true

Size: 1.99 KB

Versions: 21

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Blacklight
  class FacetFieldListComponent < Blacklight::Component
    def initialize(facet_field:, layout: nil)
      @facet_field = facet_field
      @layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent
    end

    ##
    # Renders the list of values
    # removes any elements where render_facet_item returns a nil value. This enables an application
    # to filter undesireable facet items so they don't appear in the UI
    # @deprecated
    def render_facet_limit_list(paginator, facet_field, wrapping_element = :li)
      return render(facet_items(wrapping_element: wrapping_element)) if paginator == @facet_field.paginator && facet_field == @facet_field.key

      facet_config ||= helpers.facet_configuration_for_field(facet_field)

      collection = paginator.items.map do |item|
        facet_item_presenter(item, facet_config, facet_field)
      end

      render(facet_item_component_class(facet_config).with_collection(collection, wrapping_element: wrapping_element))
    end
    Blacklight.deprecation.deprecate_methods(self, render_facet_limit_list: 'Call e.g. `render facet_items` instead')

    def facet_items(wrapping_element: :li, **item_args)
      facet_item_component_class.with_collection(facet_item_presenters, wrapping_element: wrapping_element, **item_args)
    end

    def facet_item_presenters
      @facet_field.paginator.items.map do |item|
        facet_item_presenter(item)
      end
    end

    def render?
      @facet_field.paginator&.items&.any?
    end

    def facet_item_presenter(facet_item, deprecated_facet_config = nil, facet_field = nil)
      (deprecated_facet_config || facet_config).item_presenter.new(facet_item, deprecated_facet_config || facet_config, helpers, facet_field || @facet_field.key)
    end

    def facet_item_component_class(deprecated_facet_config = nil)
      (deprecated_facet_config || facet_config).item_component
    end

    def facet_config
      @facet_field.facet_field
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/components/blacklight/facet_field_list_component.rb
blacklight-8.6.0 app/components/blacklight/facet_field_list_component.rb
blacklight-8.5.1 app/components/blacklight/facet_field_list_component.rb
blacklight-8.5.0 app/components/blacklight/facet_field_list_component.rb
blacklight-8.4.0 app/components/blacklight/facet_field_list_component.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/components/blacklight/facet_field_list_component.rb
blacklight-8.3.0 app/components/blacklight/facet_field_list_component.rb
blacklight-8.2.2 app/components/blacklight/facet_field_list_component.rb
blacklight-8.2.1 app/components/blacklight/facet_field_list_component.rb
blacklight-8.2.0 app/components/blacklight/facet_field_list_component.rb
blacklight-8.1.0 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.1 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta8 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta7 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta6 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta5 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta4 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta3 app/components/blacklight/facet_field_list_component.rb
blacklight-8.0.0.beta2 app/components/blacklight/facet_field_list_component.rb