Keep filters in admin search
While this bug was already present in the general admin search, the combination of both search and filters was very uncommon. I've only found this combinations in the users section, where you've got the "erased" filter, but in this case searching for erased users doesn't really make sense since their username and email have been deleted and so there's nothing to find. So the hidden content seemed to be the only affected section. However, we're adding the field to every section so we don't have to make sure we add it when we need it (like we did in the SDGManagement section).
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<%= form_tag(url, options) do |f| %>
|
<%= form_tag(url, options) do |f| %>
|
||||||
|
<%= hidden_current_filter_tag %>
|
||||||
<%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %>
|
<%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %>
|
||||||
<%= content %>
|
<%= content %>
|
||||||
<%= submit_tag t("admin.shared.search.search") %>
|
<%= submit_tag t("admin.shared.search.search") %>
|
||||||
|
|||||||
@@ -20,4 +20,14 @@ class Admin::SearchComponent < ApplicationComponent
|
|||||||
def options
|
def options
|
||||||
{ method: :get, role: "search" }.merge(form_options)
|
{ method: :get, role: "search" }.merge(form_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hidden_current_filter_tag
|
||||||
|
hidden_field_tag(:filter, current_filter) if current_filter
|
||||||
|
end
|
||||||
|
|
||||||
|
def current_filter
|
||||||
|
if helpers.respond_to?(:current_filter)
|
||||||
|
helpers.current_filter
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<%= header %>
|
<%= header %>
|
||||||
|
|
||||||
<%= render SDGManagement::Relations::SearchComponent.new(label: search_label, current_filter: current_filter) %>
|
<%= render SDGManagement::Relations::SearchComponent.new(label: search_label) %>
|
||||||
<%= render "shared/filter_subnav", i18n_namespace: "sdg_management.relations.index" %>
|
<%= render "shared/filter_subnav", i18n_namespace: "sdg_management.relations.index" %>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
||||||
include Header
|
include Header
|
||||||
delegate :valid_filters, :current_filter, to: :helpers
|
|
||||||
|
|
||||||
attr_reader :records
|
attr_reader :records
|
||||||
|
|
||||||
def initialize(records)
|
def initialize(records)
|
||||||
|
|||||||
@@ -5,5 +5,4 @@
|
|||||||
<%= component.select_tag :target_code, target_options,
|
<%= component.select_tag :target_code, target_options,
|
||||||
include_blank: target_blank_option,
|
include_blank: target_blank_option,
|
||||||
"aria-label": target_label %>
|
"aria-label": target_label %>
|
||||||
<%= component.hidden_field_tag :filter, current_filter %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
class SDGManagement::Relations::SearchComponent < ApplicationComponent
|
class SDGManagement::Relations::SearchComponent < ApplicationComponent
|
||||||
include SDG::OptionsForSelect
|
include SDG::OptionsForSelect
|
||||||
attr_reader :label, :current_filter
|
attr_reader :label
|
||||||
|
|
||||||
def initialize(label:, current_filter: nil)
|
def initialize(label:)
|
||||||
@label = label
|
@label = label
|
||||||
@current_filter = current_filter
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
31
spec/components/admin/search_component_spec.rb
Normal file
31
spec/components/admin/search_component_spec.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Admin::SearchComponent do
|
||||||
|
describe "#hidden_current_filter_tag" do
|
||||||
|
context "controller responds to current_filter", controller: ApplicationController do
|
||||||
|
it "is present when the controller has a current filter" do
|
||||||
|
allow(controller).to receive(:current_filter).and_return("all")
|
||||||
|
|
||||||
|
render_inline Admin::SearchComponent.new(label: "Search")
|
||||||
|
|
||||||
|
expect(page).to have_field "filter", type: :hidden, with: "all"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is not present when the controller has no current filter" do
|
||||||
|
render_inline Admin::SearchComponent.new(label: "Search")
|
||||||
|
|
||||||
|
expect(page).not_to have_field "filter", type: :hidden
|
||||||
|
expect(page).not_to have_field "filter"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "controller does not respond to current_filter", controller: ActionController::Base do
|
||||||
|
it "is not present" do
|
||||||
|
render_inline Admin::SearchComponent.new(label: "Search")
|
||||||
|
|
||||||
|
expect(page).not_to have_field "filter", type: :hidden
|
||||||
|
expect(page).not_to have_field "filter"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -102,4 +102,24 @@ describe "Hidden content search", :admin do
|
|||||||
expect(page).not_to have_content "alien1"
|
expect(page).not_to have_content "alien1"
|
||||||
expect(page).not_to have_content "alien2"
|
expect(page).not_to have_content "alien2"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "keeps filter parameters after searching" do
|
||||||
|
create(:user, :hidden, :with_confirmed_hide, username: "person1")
|
||||||
|
create(:user, :hidden, :with_confirmed_hide, username: "alien1")
|
||||||
|
create(:user, :hidden, username: "person2")
|
||||||
|
create(:user, :hidden, username: "alien2")
|
||||||
|
|
||||||
|
visit admin_hidden_users_path(filter: "with_confirmed_hide")
|
||||||
|
|
||||||
|
fill_in "search", with: "alien"
|
||||||
|
click_button "Search"
|
||||||
|
|
||||||
|
expect(page).not_to have_content "person1"
|
||||||
|
expect(page).to have_content "alien1"
|
||||||
|
expect(page).not_to have_content "person2"
|
||||||
|
expect(page).not_to have_content "alien2"
|
||||||
|
|
||||||
|
expect(page).to have_content "Confirmed"
|
||||||
|
expect(page).not_to have_link "Confirmed"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user