Class: SnFilterable::MainComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Turbo::FramesHelper, Turbo::StreamsHelper
Defined in:
app/components/sn_filterable/main_component.rb

Overview

Renders the filtering interface

## Filters’ info An array of hashes in the following Hash format:

- multi: [Boolean]; Determines if this filter supports multiple simultaneous subfilters. If true, the filter must be declared in the [Filterable]'s [ARRAY_FILTER_SCOPES]
- title: [String]; The title to display on the filtering interface
- filter_name: [String]; The filter's parameter name, see [Filterable]'s documentation
- filters: [Array<Hash>]; An array of the available preset sub filters
  - name: [String]; The name of the sub filter to display in the interface
  - value: [String]; The value of the sub filter

Instance Method Summary collapse

Constructor Details

#initialize(frame_id:, filtered:, filters:, url: nil, search_filter_name: nil, show_sidebar: true, update_url_on_submit: true, extra_params: {}) ⇒ MainComponent

Returns a new instance of MainComponent.

Parameters:

  • frame_id (String)

    The unique turbo frame ID

  • filtered (Filtered)

    The filtered instance

  • filters (Array<Hash>)

    An array of the filters’ info (see [Filterable::MainComponent]‘s documentation)

  • url (String, nil) (defaults to: nil)

    Optional, the base URL of where the filters are displayed

  • search_filter_name (String, nil) (defaults to: nil)

    Optional, enable’s and set’s the search filter, specified by the filter’s parameter name

  • show_sidebar (Boolean) (defaults to: true)

    If true, will show the sidebar with the filters.

  • update_url_on_submit (Boolean) (defaults to: true)

    If true, will update the URL in the user’s browser on form submission.

  • extra_params (Hash) (defaults to: {})

    Optional, allows for custom form values to be supplied. Useful if you need to retain non-filterable query params



28
29
30
31
32
33
34
35
36
37
# File 'app/components/sn_filterable/main_component.rb', line 28

def initialize(frame_id:, filtered:, filters:, url: nil, search_filter_name: nil, show_sidebar: true, update_url_on_submit: true, extra_params: {})
  @frame_id = frame_id
  @filtered = filtered
  @filters = filters
  @url = url
  @search_filter_name = search_filter_name
  @show_sidebar = show_sidebar
  @update_url_on_submit = update_url_on_submit
  @extra_params = extra_params
end

Instance Method Details

#search_fieldObject



39
40
41
# File 'app/components/sn_filterable/main_component.rb', line 39

def search_field
  SnFilterable::SearchComponent.new(filtered: @filtered, filter_name: @search_filter_name)
end