Browse Source

Fix filter nesting

pull/522/head
baarkerlounger 3 years ago
parent
commit
0b7efd4251
  1. 14
      app/views/case_logs/_log_filters.erb
  2. 11
      app/views/filters/_radio_filter.html.erb

14
app/views/case_logs/_log_filters.erb

@ -6,7 +6,7 @@
<div class="app-filter__content"> <div class="app-filter__content">
<%= form_with url: "/logs", html: { method: :get } do |f| %> <%= form_with url: "/logs", html: { method: :get } do |f| %>
<% years = {"2021": "2021/22", "2022": "2022/23"} %> <% years = {"2021": "2021/22", "2022": "2022/23"} %>
<% all_or_yours = {"all": "All", "yours": "Yours"} %> <% all_or_yours = {"all": { label: "All" }, "yours": { label: "Yours" } } %>
<%= render partial: "filters/checkbox_filter", locals: { f: f, options: years, label: "Collection year", category: "years" } %> <%= render partial: "filters/checkbox_filter", locals: { f: f, options: years, label: "Collection year", category: "years" } %>
<%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %> <%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %>
<%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %> <%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %>
@ -15,10 +15,18 @@
f: f, f: f,
options: { options: {
"all": { label: "All" }, "all": { label: "All" },
"specific_org": { label: "Specific organisation", conditional_filter: { type: "select", label: "Organisation", category: "organisation" } } "specific_org": {
label: "Specific organisation",
conditional_filter: {
type: "select",
label: "Organisation",
category: "organisation",
options: [OpenStruct.new(id: "", name: "Select an option")] + Organisation.all.map { |org| OpenStruct.new(id: org.id, name: org.name) }
}
}
}, },
label: "Organisation", label: "Organisation",
category: "organisation" category: "organisation_select"
} %> } %>
<% end %> <% end %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>

11
app/views/filters/_radio_filter.html.erb

@ -1,17 +1,18 @@
<%= f.govuk_radio_buttons_fieldset category.to_sym, legend: { text: label, size: "s" }, small: true, form_group: { classes: "app-filter__group" } do %> <%= f.govuk_radio_buttons_fieldset category.to_sym, legend: { text: label, size: "s" }, small: true, form_group: { classes: "app-filter__group" } do %>
<% options.map do |key, option| %> <% options.map do |key, option| %>
<%= f.govuk_radio_button category, key.to_s, <%= f.govuk_radio_button category, key.to_s,
label: { text: option }, label: { text: option[:label] },
checked: filter_selected?(category, key), checked: filter_selected?(category, key),
size: "s" size: "s" do %>
%>
<% if option[:conditional_filter] %> <% if option[:conditional_filter] %>
<%= render partial: "filters/#{option[:conditional_filter][:type]}_filter", locals: { <%= render partial: "filters/#{option[:conditional_filter][:type]}_filter", locals: {
f:, f:,
collection: Organisation.all, collection: option[:conditional_filter][:options],
category: "organisation", category: option[:conditional_filter][:category],
label: option[:conditional_filter][:label],
secondary: true, secondary: true,
} %> } %>
<% end %> <% end %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>

Loading…
Cancel
Save