Browse Source

Radio button on log filter is now preset to "All" (#552)

* Radio button on log filter is now preset to "All"

* lint fixes

* removed instance @ variable
pull/619/head
Ted-U 3 years ago committed by baarkerlounger
parent
commit
07e3bad429
  1. 1
      app/helpers/filters_helper.rb
  2. 3
      app/views/case_logs/_log_filters.erb
  3. 13
      spec/helpers/filters_helper_spec.rb

1
app/helpers/filters_helper.rb

@ -3,6 +3,7 @@ module FiltersHelper
return false unless session[:case_logs_filters] return false unless session[:case_logs_filters]
selected_filters = JSON.parse(session[:case_logs_filters]) selected_filters = JSON.parse(session[:case_logs_filters])
return true if selected_filters.blank? && filter == "user" && value == :all
return false if selected_filters[filter].blank? return false if selected_filters[filter].blank?
selected_filters[filter].include?(value.to_s) selected_filters[filter].include?(value.to_s)

3
app/views/case_logs/_log_filters.erb

@ -6,9 +6,10 @@
<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"} %>
<%= 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": "All", "yours": "Yours"}, label: "Logs", category: "user" } %> <%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %> <% end %>
</div> </div>

13
spec/helpers/filters_helper_spec.rb

@ -9,6 +9,19 @@ RSpec.describe FiltersHelper do
end end
end end
context "when the filter is the user filter but session filters is empty" do
before do
session[:case_logs_filters] = {}.to_json
end
context "when looking at the all value" do
it "returns true if no filters have been set yet" do
expect(filter_selected?("user", :all)).to be_truthy
expect(filter_selected?("user", :yours)).to be_falsey
end
end
end
context "when one filter is selected" do context "when one filter is selected" do
before do before do
session[:case_logs_filters] = { "status": "in_progress" }.to_json session[:case_logs_filters] = { "status": "in_progress" }.to_json

Loading…
Cancel
Save