Sha256: 2de3ab5b962e5c6e41c03638d5ce69f44da70cee7c5ca4f739353a1ea36ad952

Contents?: true

Size: 1.77 KB

Versions: 13

Compression:

Stored size: 1.77 KB

Contents

<%
  conditions = @refine_filter_query.available_conditions_attributes

  conditions_for_category = -> (category) do
    conditions.filter { |c| c[:meta][:category] == category}
  end

  categories = conditions.map { |c| c[:meta][:category] }.uniq.compact

  # Note that the stimulus controllers set default condition id for new conditions
  # so this is only for rare cases where it gets unset
  selected_condition_id ||= @refine_filter.default_condition_id
  selected_condition_id ||= categories
    .first
    &.conditions_for_category.call(categories.first)
    [:id]

  uncategorized_conditions = conditions.filter { |c| c[:meta][:category].nil? }

%>

<%= tag.div data: {
  action: "$change->refine--update#condition",
  controller: 'fields--super-select',
  fields__super_select_enable_search_value: 'true',
  fields__super_select_container_width_value: 'resolve',
} do %>
  <select
    data-fields--super-select-target="select"
    data-condition-id="<%= selected_condition_id %>"
    name="conditions"
    class="refine-condition-select"
  >
    <optgroup >
      <% uncategorized_conditions.each do |condition_option| %>
        <option
          value="<%= condition_option[:id] %>"
          <% if selected_condition_id == condition_option[:id] %>selected<% end %>
        ><%= condition_option[:display] %></option>
      <% end %>
    </optgroup>
    <% categories.each do |category| %>
      <optgroup class="divider" label="<%= category %>">
        <% conditions_for_category.call(category).each do |condition_option| %>
          <option
            value="<%= condition_option[:id] %>"
            <% if selected_condition_id == condition_option[:id] %>selected<% end %>
          ><%= condition_option[:display] %></option>
        <% end %>
      </optgroup>
    <% end %>
  </select>
<% end %>

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
refine-rails-2.9.12 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.11 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.10 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.9 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.8 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.7 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.6 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.5 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.4 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.3 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.2 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.1 app/views/refine/blueprints/_condition_select.html.erb
refine-rails-2.9.0 app/views/refine/blueprints/_condition_select.html.erb