Browse Source

Remove filter value if hidden

pull/582/head
baarkerlounger 3 years ago
parent
commit
3e30eae0d3
  1. 13
      app/frontend/controllers/conditional_filter_controller.js
  2. 3
      app/frontend/controllers/index.js
  3. 2
      app/views/filters/_select_filter.html.erb
  4. 24
      spec/features/user_spec.rb

13
app/frontend/controllers/conditional_filter_controller.js

@ -0,0 +1,13 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
initialize() {
this.clearIfHidden()
}
clearIfHidden() {
if(this.element.style["display"] == "none") {
this.element.value = ""
}
}
}

3
app/frontend/controllers/index.js

@ -6,6 +6,9 @@ import { application } from "./application"
import AccessibleAutocompleteController from "./accessible_autocomplete_controller.js"
application.register("accessible-autocomplete", AccessibleAutocompleteController)
import ConditionalFilterController from "./conditional_filter_controller.js"
application.register("conditional-filter", ConditionalFilterController)
import ConditionalQuestionController from "./conditional_question_controller.js"
application.register("conditional-question", ConditionalQuestionController)

2
app/views/filters/_select_filter.html.erb

@ -4,4 +4,4 @@
:name,
label: { hidden: secondary },
options: { disabled: [""], selected: selected_option(category) },
"data-controller": "accessible-autocomplete" %>
"data-controller": ["accessible-autocomplete", "conditional-filter"] %>

24
spec/features/user_spec.rb

@ -524,5 +524,29 @@ RSpec.describe "User Features" do
click_button("Send email")
end
end
context "when viewing logs" do
context "when filtering by organisation and then switching back to all organisations", js: true do
let!(:organisation) { FactoryBot.create(:organisation, name: "Filtered Org") }
before do
allow(SecureRandom).to receive(:random_number).and_return(otp)
click_button("Sign in")
fill_in("code", with: otp)
click_button("Submit")
end
it "clears the previously selected organisation value" do
visit("/logs")
choose("organisation-select-specific-org-field", allow_label_click: true)
find("#organisation-field").click.native.send_keys("F", "i", "l", "t", :down, :enter)
click_button("Apply filters")
expect(page).to have_current_path("/logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&user=all&organisation_select=specific_org&organisation=#{organisation.id}")
choose("organisation-select-all-field", allow_label_click: true)
click_button("Apply filters")
expect(page).to have_current_path("/logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&user=all&organisation_select=all")
end
end
end
end
end

Loading…
Cancel
Save