From 7b6294199ccd0896cca2c20fe5b588dd3a3a5529 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 3 Dec 2020 09:02:51 +0100 Subject: [PATCH 01/11] Include the searched term in the search input form --- app/views/admin/shared/_user_search.html.erb | 2 +- spec/system/admin/administrators_spec.rb | 2 ++ spec/system/admin/managers_spec.rb | 2 ++ spec/system/admin/moderators_spec.rb | 2 ++ spec/system/admin/valuators_spec.rb | 2 ++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/admin/shared/_user_search.html.erb b/app/views/admin/shared/_user_search.html.erb index c553052c2..0dea2c65b 100644 --- a/app/views/admin/shared/_user_search.html.erb +++ b/app/views/admin/shared/_user_search.html.erb @@ -1,7 +1,7 @@
<%= form_for(User.new, url: url, as: :user, method: :get) do |f| %>
- <%= text_field_tag :name_or_email, "", placeholder: t("admin.shared.user_search.placeholder") %> + <%= text_field_tag :name_or_email, params[:name_or_email].to_s, placeholder: t("admin.shared.user_search.placeholder") %>
<%= f.submit t("admin.shared.user_search.button"), class: "button" %>
diff --git a/spec/system/admin/administrators_spec.rb b/spec/system/admin/administrators_spec.rb index a97f5d389..078e42635 100644 --- a/spec/system/admin/administrators_spec.rb +++ b/spec/system/admin/administrators_spec.rb @@ -83,6 +83,7 @@ describe "Admin administrators" do click_button "Search" expect(page).to have_content("Administrators: User search") + expect(page).to have_field "name_or_email", with: "Sumn" expect(page).to have_content(administrator1.name) expect(page).not_to have_content(administrator2.name) end @@ -95,6 +96,7 @@ describe "Admin administrators" do click_button "Search" expect(page).to have_content("Administrators: User search") + expect(page).to have_field "name_or_email", with: administrator2.email expect(page).to have_content(administrator2.email) expect(page).not_to have_content(administrator1.email) end diff --git a/spec/system/admin/managers_spec.rb b/spec/system/admin/managers_spec.rb index 081152a46..fd14946b5 100644 --- a/spec/system/admin/managers_spec.rb +++ b/spec/system/admin/managers_spec.rb @@ -64,6 +64,7 @@ describe "Admin managers", :admin do click_button "Search" expect(page).to have_content("Managers: User search") + expect(page).to have_field "name_or_email", with: "Taylor" expect(page).to have_content(manager1.name) expect(page).not_to have_content(manager2.name) end @@ -76,6 +77,7 @@ describe "Admin managers", :admin do click_button "Search" expect(page).to have_content("Managers: User search") + expect(page).to have_field "name_or_email", with: manager2.email expect(page).to have_content(manager2.email) expect(page).not_to have_content(manager1.email) end diff --git a/spec/system/admin/moderators_spec.rb b/spec/system/admin/moderators_spec.rb index 8ae8c8e58..dd97a65fa 100644 --- a/spec/system/admin/moderators_spec.rb +++ b/spec/system/admin/moderators_spec.rb @@ -64,6 +64,7 @@ describe "Admin moderators", :admin do click_button "Search" expect(page).to have_content("Moderators: User search") + expect(page).to have_field "name_or_email", with: "Eliz" expect(page).to have_content(moderator1.name) expect(page).not_to have_content(moderator2.name) end @@ -76,6 +77,7 @@ describe "Admin moderators", :admin do click_button "Search" expect(page).to have_content("Moderators: User search") + expect(page).to have_field "name_or_email", with: moderator2.email expect(page).to have_content(moderator2.email) expect(page).not_to have_content(moderator1.email) end diff --git a/spec/system/admin/valuators_spec.rb b/spec/system/admin/valuators_spec.rb index 388da65bd..23233b344 100644 --- a/spec/system/admin/valuators_spec.rb +++ b/spec/system/admin/valuators_spec.rb @@ -89,6 +89,7 @@ describe "Admin valuators", :admin do click_button "Search" expect(page).to have_content("Valuators: User search") + expect(page).to have_field "name_or_email", with: "Foster" expect(page).to have_content(valuator1.name) expect(page).not_to have_content(valuator2.name) end @@ -101,6 +102,7 @@ describe "Admin valuators", :admin do click_button "Search" expect(page).to have_content("Valuators: User search") + expect(page).to have_field "name_or_email", with: valuator2.email expect(page).to have_content(valuator2.email) expect(page).not_to have_content(valuator1.email) end From 2cf49b28de5827c0b7ec7627cbd753c1223f5117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 11:07:23 +0100 Subject: [PATCH 02/11] Extract users search view to a component We're going to make this search component more generic, but for now, we're keeping the exact same behavior we had. --- app/components/admin/search_component.html.erb | 10 ++++++++++ app/components/admin/search_component.rb | 7 +++++++ app/views/admin/shared/_user_search.html.erb | 11 +---------- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 app/components/admin/search_component.html.erb create mode 100644 app/components/admin/search_component.rb diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb new file mode 100644 index 000000000..0dea2c65b --- /dev/null +++ b/app/components/admin/search_component.html.erb @@ -0,0 +1,10 @@ +
+ <%= form_for(User.new, url: url, as: :user, method: :get) do |f| %> +
+ <%= text_field_tag :name_or_email, params[:name_or_email].to_s, placeholder: t("admin.shared.user_search.placeholder") %> +
+ <%= f.submit t("admin.shared.user_search.button"), class: "button" %> +
+
+ <% end %> +
diff --git a/app/components/admin/search_component.rb b/app/components/admin/search_component.rb new file mode 100644 index 000000000..b78ed1edc --- /dev/null +++ b/app/components/admin/search_component.rb @@ -0,0 +1,7 @@ +class Admin::SearchComponent < ApplicationComponent + attr_reader :url + + def initialize(url:) + @url = url + end +end diff --git a/app/views/admin/shared/_user_search.html.erb b/app/views/admin/shared/_user_search.html.erb index 0dea2c65b..a2a5eaaf3 100644 --- a/app/views/admin/shared/_user_search.html.erb +++ b/app/views/admin/shared/_user_search.html.erb @@ -1,10 +1 @@ -
- <%= form_for(User.new, url: url, as: :user, method: :get) do |f| %> -
- <%= text_field_tag :name_or_email, params[:name_or_email].to_s, placeholder: t("admin.shared.user_search.placeholder") %> -
- <%= f.submit t("admin.shared.user_search.button"), class: "button" %> -
-
- <% end %> -
+<%= render Admin::SearchComponent.new(url: url) %> From 9a24a8efe2a349dd2d740937c18718194f499cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 11:12:48 +0100 Subject: [PATCH 03/11] Use form_tag in search form This form does not depend on an object at all, so we can use a generic tag which is model-independent. --- app/components/admin/search_component.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb index 0dea2c65b..af3fe396d 100644 --- a/app/components/admin/search_component.html.erb +++ b/app/components/admin/search_component.html.erb @@ -1,9 +1,9 @@
- <%= form_for(User.new, url: url, as: :user, method: :get) do |f| %> + <%= form_tag(url, method: :get) do |f| %>
<%= text_field_tag :name_or_email, params[:name_or_email].to_s, placeholder: t("admin.shared.user_search.placeholder") %>
- <%= f.submit t("admin.shared.user_search.button"), class: "button" %> + <%= submit_tag t("admin.shared.user_search.button"), class: "button" %>
<% end %> From 155da08cf0cf752bbb5892594156723cd4e7babc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 11:17:45 +0100 Subject: [PATCH 04/11] Use a generic name for the search parameter This way we can use it for any model. --- app/components/admin/search_component.html.erb | 2 +- app/components/admin/search_component.rb | 6 ++++++ app/controllers/admin/administrators_controller.rb | 2 +- app/controllers/admin/managers_controller.rb | 2 +- app/controllers/admin/moderators_controller.rb | 2 +- app/controllers/admin/officials_controller.rb | 2 +- app/controllers/admin/organizations_controller.rb | 2 +- app/controllers/admin/poll/officers_controller.rb | 2 +- app/controllers/admin/valuators_controller.rb | 2 +- app/controllers/admin/verifications_controller.rb | 2 +- app/controllers/moderation/users_controller.rb | 2 +- app/views/admin/organizations/index.html.erb | 2 +- app/views/admin/organizations/search.html.erb | 2 +- app/views/admin/poll/officers/_search.html.erb | 2 +- app/views/moderation/users/index.html.erb | 2 +- spec/controllers/moderation/users_controller_spec.rb | 4 ++-- spec/system/admin/activity_spec.rb | 2 +- spec/system/admin/administrators_spec.rb | 12 ++++++------ spec/system/admin/managers_spec.rb | 12 ++++++------ spec/system/admin/moderators_spec.rb | 12 ++++++------ spec/system/admin/officials_spec.rb | 2 +- spec/system/admin/organizations_spec.rb | 8 ++++---- spec/system/admin/poll/officers_spec.rb | 2 +- spec/system/admin/valuators_spec.rb | 12 ++++++------ spec/system/admin/verifications_spec.rb | 2 +- spec/system/moderation/users_spec.rb | 2 +- 26 files changed, 55 insertions(+), 49 deletions(-) diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb index af3fe396d..de9f5200b 100644 --- a/app/components/admin/search_component.html.erb +++ b/app/components/admin/search_component.html.erb @@ -1,7 +1,7 @@
<%= form_tag(url, method: :get) do |f| %>
- <%= text_field_tag :name_or_email, params[:name_or_email].to_s, placeholder: t("admin.shared.user_search.placeholder") %> + <%= text_field_tag :search, search_terms.to_s, placeholder: t("admin.shared.user_search.placeholder") %>
<%= submit_tag t("admin.shared.user_search.button"), class: "button" %>
diff --git a/app/components/admin/search_component.rb b/app/components/admin/search_component.rb index b78ed1edc..246796c2c 100644 --- a/app/components/admin/search_component.rb +++ b/app/components/admin/search_component.rb @@ -4,4 +4,10 @@ class Admin::SearchComponent < ApplicationComponent def initialize(url:) @url = url end + + private + + def search_terms + params[:search] + end end diff --git a/app/controllers/admin/administrators_controller.rb b/app/controllers/admin/administrators_controller.rb index 8e77a93e6..8d8a5c741 100644 --- a/app/controllers/admin/administrators_controller.rb +++ b/app/controllers/admin/administrators_controller.rb @@ -6,7 +6,7 @@ class Admin::AdministratorsController < Admin::BaseController end def search - @users = User.search(params[:name_or_email]) + @users = User.search(params[:search]) .includes(:administrator) .page(params[:page]) .for_render diff --git a/app/controllers/admin/managers_controller.rb b/app/controllers/admin/managers_controller.rb index e001d5b72..4161a9a97 100644 --- a/app/controllers/admin/managers_controller.rb +++ b/app/controllers/admin/managers_controller.rb @@ -6,7 +6,7 @@ class Admin::ManagersController < Admin::BaseController end def search - @users = User.search(params[:name_or_email]) + @users = User.search(params[:search]) .includes(:manager) .page(params[:page]) .for_render diff --git a/app/controllers/admin/moderators_controller.rb b/app/controllers/admin/moderators_controller.rb index 8d7508a12..ece34b1fb 100644 --- a/app/controllers/admin/moderators_controller.rb +++ b/app/controllers/admin/moderators_controller.rb @@ -6,7 +6,7 @@ class Admin::ModeratorsController < Admin::BaseController end def search - @users = User.search(params[:name_or_email]) + @users = User.search(params[:search]) .includes(:moderator) .page(params[:page]) .for_render diff --git a/app/controllers/admin/officials_controller.rb b/app/controllers/admin/officials_controller.rb index 1b96a9365..1fd3adaa9 100644 --- a/app/controllers/admin/officials_controller.rb +++ b/app/controllers/admin/officials_controller.rb @@ -4,7 +4,7 @@ class Admin::OfficialsController < Admin::BaseController end def search - @users = User.search(params[:name_or_email]).page(params[:page]).for_render + @users = User.search(params[:search]).page(params[:page]).for_render end def edit diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 1a5367286..695cf0996 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -12,7 +12,7 @@ class Admin::OrganizationsController < Admin::BaseController def search @organizations = Organization.includes(:user) - .search(params[:term]) + .search(params[:search]) .order("users.created_at", :name, "users.email") .page(params[:page]) end diff --git a/app/controllers/admin/poll/officers_controller.rb b/app/controllers/admin/poll/officers_controller.rb index 9cf752126..3b926622d 100644 --- a/app/controllers/admin/poll/officers_controller.rb +++ b/app/controllers/admin/poll/officers_controller.rb @@ -6,7 +6,7 @@ class Admin::Poll::OfficersController < Admin::Poll::BaseController end def search - @user = User.find_by(email: params[:email]) + @user = User.find_by(email: params[:search]) respond_to do |format| if @user diff --git a/app/controllers/admin/valuators_controller.rb b/app/controllers/admin/valuators_controller.rb index fdfaab799..067090426 100644 --- a/app/controllers/admin/valuators_controller.rb +++ b/app/controllers/admin/valuators_controller.rb @@ -10,7 +10,7 @@ class Admin::ValuatorsController < Admin::BaseController end def search - @users = User.search(params[:name_or_email]) + @users = User.search(params[:search]) .includes(:valuator) .page(params[:page]) .for_render diff --git a/app/controllers/admin/verifications_controller.rb b/app/controllers/admin/verifications_controller.rb index 939add888..3e3671ec3 100644 --- a/app/controllers/admin/verifications_controller.rb +++ b/app/controllers/admin/verifications_controller.rb @@ -4,7 +4,7 @@ class Admin::VerificationsController < Admin::BaseController end def search - @users = User.incomplete_verification.search(params[:name_or_email]) + @users = User.incomplete_verification.search(params[:search]) .page(params[:page]) .for_render render :index diff --git a/app/controllers/moderation/users_controller.rb b/app/controllers/moderation/users_controller.rb index f07268348..2c958eda8 100644 --- a/app/controllers/moderation/users_controller.rb +++ b/app/controllers/moderation/users_controller.rb @@ -21,7 +21,7 @@ class Moderation::UsersController < Moderation::BaseController private def load_users - @users = User.with_hidden.search(params[:name_or_email]).page(params[:page]).for_render + @users = User.with_hidden.search(params[:search]).page(params[:page]).for_render end def block_user diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index b1110488a..8716668eb 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -3,7 +3,7 @@
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
- <%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %> + <%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %>
<%= f.submit t("admin.organizations.index.search"), class: "button" %> diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb index 2e534d052..7d2cdb263 100644 --- a/app/views/admin/organizations/search.html.erb +++ b/app/views/admin/organizations/search.html.erb @@ -3,7 +3,7 @@
<%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %>
- <%= text_field_tag :term, "", placeholder: t("admin.organizations.index.search_placeholder") %> + <%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %>
<%= f.submit t("admin.organizations.index.search"), class: "button" %>
diff --git a/app/views/admin/poll/officers/_search.html.erb b/app/views/admin/poll/officers/_search.html.erb index 4e5574d07..e61d9a73b 100644 --- a/app/views/admin/poll/officers/_search.html.erb +++ b/app/views/admin/poll/officers/_search.html.erb @@ -2,7 +2,7 @@ <%= form_tag search_admin_officers_path, method: :get, remote: true do %>
- <%= text_field_tag :email, "", + <%= text_field_tag :search, "", placeholder: t("admin.poll_officers.search.email_placeholder") %>
<%= submit_tag t("admin.poll_officers.search.search"), class: "button" %> diff --git a/app/views/moderation/users/index.html.erb b/app/views/moderation/users/index.html.erb index c7fcf502b..06403279e 100644 --- a/app/views/moderation/users/index.html.erb +++ b/app/views/moderation/users/index.html.erb @@ -3,7 +3,7 @@ <%= form_for(User.new, url: moderation_users_path, as: :user, method: :get) do |f| %>
- <%= text_field_tag :name_or_email, "", placeholder: t("moderation.users.index.search_placeholder") %> + <%= text_field_tag :search, "", placeholder: t("moderation.users.index.search_placeholder") %>
<%= f.submit t("moderation.users.index.search"), class: "button success" %> diff --git a/spec/controllers/moderation/users_controller_spec.rb b/spec/controllers/moderation/users_controller_spec.rb index 424e41c8b..1699c9c4e 100644 --- a/spec/controllers/moderation/users_controller_spec.rb +++ b/spec/controllers/moderation/users_controller_spec.rb @@ -7,9 +7,9 @@ describe Moderation::UsersController do it "keeps query parameters while using protected redirects" do user = create(:user, email: "user@consul.dev") - get :hide_in_moderation_screen, params: { id: user, name_or_email: "user@consul.dev", host: "evil.dev" } + get :hide_in_moderation_screen, params: { id: user, search: "user@consul.dev", host: "evil.dev" } - expect(response).to redirect_to "/moderation/users?name_or_email=user%40consul.dev" + expect(response).to redirect_to "/moderation/users?search=user%40consul.dev" end end end diff --git a/spec/system/admin/activity_spec.rb b/spec/system/admin/activity_spec.rb index d83c29d9f..0accba34a 100644 --- a/spec/system/admin/activity_spec.rb +++ b/spec/system/admin/activity_spec.rb @@ -223,7 +223,7 @@ describe "Admin activity" do scenario "Shows moderation activity from moderation screen" do user = create(:user) - visit moderation_users_path(name_or_email: user.username) + visit moderation_users_path(search: user.username) within("#moderation_users") do click_link "Block" diff --git a/spec/system/admin/administrators_spec.rb b/spec/system/admin/administrators_spec.rb index 078e42635..c8da6fc80 100644 --- a/spec/system/admin/administrators_spec.rb +++ b/spec/system/admin/administrators_spec.rb @@ -19,7 +19,7 @@ describe "Admin administrators" do end scenario "Create Administrator", :js do - fill_in "name_or_email", with: user.email + fill_in "search", with: user.email click_button "Search" expect(page).to have_content user.name @@ -66,7 +66,7 @@ describe "Admin administrators" do expect(page).to have_content(administrator1.name) expect(page).to have_content(administrator2.name) - fill_in "name_or_email", with: " " + fill_in "search", with: " " click_button "Search" expect(page).to have_content("Administrators: User search") @@ -79,11 +79,11 @@ describe "Admin administrators" do expect(page).to have_content(administrator1.name) expect(page).to have_content(administrator2.name) - fill_in "name_or_email", with: "Sumn" + fill_in "search", with: "Sumn" click_button "Search" expect(page).to have_content("Administrators: User search") - expect(page).to have_field "name_or_email", with: "Sumn" + expect(page).to have_field "search", with: "Sumn" expect(page).to have_content(administrator1.name) expect(page).not_to have_content(administrator2.name) end @@ -92,11 +92,11 @@ describe "Admin administrators" do expect(page).to have_content(administrator1.email) expect(page).to have_content(administrator2.email) - fill_in "name_or_email", with: administrator2.email + fill_in "search", with: administrator2.email click_button "Search" expect(page).to have_content("Administrators: User search") - expect(page).to have_field "name_or_email", with: administrator2.email + expect(page).to have_field "search", with: administrator2.email expect(page).to have_content(administrator2.email) expect(page).not_to have_content(administrator1.email) end diff --git a/spec/system/admin/managers_spec.rb b/spec/system/admin/managers_spec.rb index fd14946b5..6b46fa15e 100644 --- a/spec/system/admin/managers_spec.rb +++ b/spec/system/admin/managers_spec.rb @@ -15,7 +15,7 @@ describe "Admin managers", :admin do end scenario "Create Manager", :js do - fill_in "name_or_email", with: user.email + fill_in "search", with: user.email click_button "Search" expect(page).to have_content user.name @@ -47,7 +47,7 @@ describe "Admin managers", :admin do expect(page).to have_content(manager1.name) expect(page).to have_content(manager2.name) - fill_in "name_or_email", with: " " + fill_in "search", with: " " click_button "Search" expect(page).to have_content("Managers: User search") @@ -60,11 +60,11 @@ describe "Admin managers", :admin do expect(page).to have_content(manager1.name) expect(page).to have_content(manager2.name) - fill_in "name_or_email", with: "Taylor" + fill_in "search", with: "Taylor" click_button "Search" expect(page).to have_content("Managers: User search") - expect(page).to have_field "name_or_email", with: "Taylor" + expect(page).to have_field "search", with: "Taylor" expect(page).to have_content(manager1.name) expect(page).not_to have_content(manager2.name) end @@ -73,11 +73,11 @@ describe "Admin managers", :admin do expect(page).to have_content(manager1.email) expect(page).to have_content(manager2.email) - fill_in "name_or_email", with: manager2.email + fill_in "search", with: manager2.email click_button "Search" expect(page).to have_content("Managers: User search") - expect(page).to have_field "name_or_email", with: manager2.email + expect(page).to have_field "search", with: manager2.email expect(page).to have_content(manager2.email) expect(page).not_to have_content(manager1.email) end diff --git a/spec/system/admin/moderators_spec.rb b/spec/system/admin/moderators_spec.rb index dd97a65fa..df1af19b4 100644 --- a/spec/system/admin/moderators_spec.rb +++ b/spec/system/admin/moderators_spec.rb @@ -15,7 +15,7 @@ describe "Admin moderators", :admin do end scenario "Create Moderator", :js do - fill_in "name_or_email", with: user.email + fill_in "search", with: user.email click_button "Search" expect(page).to have_content user.name @@ -47,7 +47,7 @@ describe "Admin moderators", :admin do expect(page).to have_content(moderator1.name) expect(page).to have_content(moderator2.name) - fill_in "name_or_email", with: " " + fill_in "search", with: " " click_button "Search" expect(page).to have_content("Moderators: User search") @@ -60,11 +60,11 @@ describe "Admin moderators", :admin do expect(page).to have_content(moderator1.name) expect(page).to have_content(moderator2.name) - fill_in "name_or_email", with: "Eliz" + fill_in "search", with: "Eliz" click_button "Search" expect(page).to have_content("Moderators: User search") - expect(page).to have_field "name_or_email", with: "Eliz" + expect(page).to have_field "search", with: "Eliz" expect(page).to have_content(moderator1.name) expect(page).not_to have_content(moderator2.name) end @@ -73,11 +73,11 @@ describe "Admin moderators", :admin do expect(page).to have_content(moderator1.email) expect(page).to have_content(moderator2.email) - fill_in "name_or_email", with: moderator2.email + fill_in "search", with: moderator2.email click_button "Search" expect(page).to have_content("Moderators: User search") - expect(page).to have_field "name_or_email", with: moderator2.email + expect(page).to have_field "search", with: moderator2.email expect(page).to have_content(moderator2.email) expect(page).not_to have_content(moderator1.email) end diff --git a/spec/system/admin/officials_spec.rb b/spec/system/admin/officials_spec.rb index 2b1e18331..2cd86c085 100644 --- a/spec/system/admin/officials_spec.rb +++ b/spec/system/admin/officials_spec.rb @@ -38,7 +38,7 @@ describe "Admin officials", :admin do scenario "Create an official" do visit admin_officials_path - fill_in "name_or_email", with: citizen.email + fill_in "search", with: citizen.email click_button "Search" expect(page).to have_current_path(search_admin_officials_path, ignore_query: true) diff --git a/spec/system/admin/organizations_spec.rb b/spec/system/admin/organizations_spec.rb index 86548e846..7f2d400df 100644 --- a/spec/system/admin/organizations_spec.rb +++ b/spec/system/admin/organizations_spec.rb @@ -36,7 +36,7 @@ describe "Admin::Organizations" do visit admin_organizations_path expect(page).to have_content("Get up, Stand up") - fill_in "term", with: " " + fill_in "search", with: " " click_button "Search" expect(page).to have_current_path(search_admin_organizations_path, ignore_query: true) @@ -49,7 +49,7 @@ describe "Admin::Organizations" do visit search_admin_organizations_path expect(page).not_to have_content("Get up, Stand up") - fill_in "term", with: "Up, sta" + fill_in "search", with: "Up, sta" click_button "Search" within("#search-results") do @@ -61,7 +61,7 @@ describe "Admin::Organizations" do visit search_admin_organizations_path expect(page).not_to have_content("Get up, Stand up") - fill_in "term", with: user.email + fill_in "search", with: user.email click_button "Search" within("#search-results") do @@ -73,7 +73,7 @@ describe "Admin::Organizations" do visit search_admin_organizations_path expect(page).not_to have_content("Get up, Stand up") - fill_in "term", with: user.phone_number + fill_in "search", with: user.phone_number click_button "Search" within("#search-results") do diff --git a/spec/system/admin/poll/officers_spec.rb b/spec/system/admin/poll/officers_spec.rb index 51d2fd506..cf08b95a0 100644 --- a/spec/system/admin/poll/officers_spec.rb +++ b/spec/system/admin/poll/officers_spec.rb @@ -15,7 +15,7 @@ describe "Admin poll officers", :admin do end scenario "Create", :js do - fill_in "email", with: user.email + fill_in "search", with: user.email click_button "Search" expect(page).to have_content user.name diff --git a/spec/system/admin/valuators_spec.rb b/spec/system/admin/valuators_spec.rb index 23233b344..f5108dd63 100644 --- a/spec/system/admin/valuators_spec.rb +++ b/spec/system/admin/valuators_spec.rb @@ -22,7 +22,7 @@ describe "Admin valuators", :admin do end scenario "Create", :js do - fill_in "name_or_email", with: user.email + fill_in "search", with: user.email click_button "Search" expect(page).to have_content(user.name) @@ -72,7 +72,7 @@ describe "Admin valuators", :admin do expect(page).to have_content(valuator1.name) expect(page).to have_content(valuator2.name) - fill_in "name_or_email", with: " " + fill_in "search", with: " " click_button "Search" expect(page).to have_content("Valuators: User search") @@ -85,11 +85,11 @@ describe "Admin valuators", :admin do expect(page).to have_content(valuator1.name) expect(page).to have_content(valuator2.name) - fill_in "name_or_email", with: "Foster" + fill_in "search", with: "Foster" click_button "Search" expect(page).to have_content("Valuators: User search") - expect(page).to have_field "name_or_email", with: "Foster" + expect(page).to have_field "search", with: "Foster" expect(page).to have_content(valuator1.name) expect(page).not_to have_content(valuator2.name) end @@ -98,11 +98,11 @@ describe "Admin valuators", :admin do expect(page).to have_content(valuator1.email) expect(page).to have_content(valuator2.email) - fill_in "name_or_email", with: valuator2.email + fill_in "search", with: valuator2.email click_button "Search" expect(page).to have_content("Valuators: User search") - expect(page).to have_field "name_or_email", with: valuator2.email + expect(page).to have_field "search", with: valuator2.email expect(page).to have_content(valuator2.email) expect(page).not_to have_content(valuator1.email) end diff --git a/spec/system/admin/verifications_spec.rb b/spec/system/admin/verifications_spec.rb index 69bb37fb2..98961a571 100644 --- a/spec/system/admin/verifications_spec.rb +++ b/spec/system/admin/verifications_spec.rb @@ -22,7 +22,7 @@ describe "Incomplete verifications", :admin do visit admin_verifications_path - fill_in "name_or_email", with: "juan" + fill_in "search", with: "juan" click_button "Search" expect(page).to have_content("Juan_anonymous") diff --git a/spec/system/moderation/users_spec.rb b/spec/system/moderation/users_spec.rb index d05951eae..62a72d59a 100644 --- a/spec/system/moderation/users_spec.rb +++ b/spec/system/moderation/users_spec.rb @@ -58,7 +58,7 @@ describe "Moderate users" do visit moderation_users_path expect(page).not_to have_content citizen.name - fill_in "name_or_email", with: "Wanda" + fill_in "search", with: "Wanda" click_button "Search" within("#moderation_users") do From b453ed6c1460dae9321adbe7513dafb768686c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 11:42:05 +0100 Subject: [PATCH 05/11] Add ARIA role and ARIA label to admin search form This way screen reader users will have an easier access to it. --- app/components/admin/search_component.html.erb | 4 ++-- app/components/admin/search_component.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb index de9f5200b..6af631ccc 100644 --- a/app/components/admin/search_component.html.erb +++ b/app/components/admin/search_component.html.erb @@ -1,7 +1,7 @@
- <%= form_tag(url, method: :get) do |f| %> + <%= form_tag(url, method: :get, role: "search") do |f| %>
- <%= text_field_tag :search, search_terms.to_s, placeholder: t("admin.shared.user_search.placeholder") %> + <%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %>
<%= submit_tag t("admin.shared.user_search.button"), class: "button" %>
diff --git a/app/components/admin/search_component.rb b/app/components/admin/search_component.rb index 246796c2c..239faacea 100644 --- a/app/components/admin/search_component.rb +++ b/app/components/admin/search_component.rb @@ -10,4 +10,8 @@ class Admin::SearchComponent < ApplicationComponent def search_terms params[:search] end + + def label + t("admin.shared.user_search.placeholder") + end end From 49c22b880cb0ae6adce5ebe40407402f98ce90b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 11:39:33 +0100 Subject: [PATCH 06/11] Use CSS to style the search component We simplify the view, and so make it easier to customize. --- app/assets/stylesheets/admin/search.css | 17 +++++++++++++++++ app/components/admin/search_component.html.erb | 14 ++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 app/assets/stylesheets/admin/search.css diff --git a/app/assets/stylesheets/admin/search.css b/app/assets/stylesheets/admin/search.css new file mode 100644 index 000000000..f4e818abd --- /dev/null +++ b/app/assets/stylesheets/admin/search.css @@ -0,0 +1,17 @@ +.admin [role=search] { + display: flex; + + [type="submit"] { + @include button($background: $link); + border-radius: 0; + font-size: 1rem; + + &[disabled] { + @include button-disabled; + } + } + + @include breakpoint(medium) { + width: 50%; + } +} diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb index 6af631ccc..117a9b50f 100644 --- a/app/components/admin/search_component.html.erb +++ b/app/components/admin/search_component.html.erb @@ -1,10 +1,4 @@ -
- <%= form_tag(url, method: :get, role: "search") do |f| %> -
- <%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %> -
- <%= submit_tag t("admin.shared.user_search.button"), class: "button" %> -
-
- <% end %> -
+<%= form_tag(url, method: :get, role: "search") do |f| %> + <%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %> + <%= submit_tag t("admin.shared.user_search.button") %> +<% end %> From 0a3acf3c5fe8b2eaaea616a373453ca73f9f19e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 15:44:12 +0100 Subject: [PATCH 07/11] Use a shared translation for search buttons We were writing the same text over and over for the same translations. Since they all serve the same function, it's perfectly fine for them to have the same text, and so we can have a shared translation. --- app/components/admin/search_component.html.erb | 2 +- .../admin/local_census_records/index.html.erb | 2 +- app/views/admin/organizations/index.html.erb | 2 +- app/views/admin/organizations/search.html.erb | 2 +- .../poll/booth_assignments/_search_booths.html.erb | 2 +- .../officer_assignments/_search_officers.html.erb | 2 +- app/views/admin/poll/officers/_search.html.erb | 2 +- app/views/admin/poll/questions/_search.html.erb | 2 +- app/views/admin/shared/_booth_search.html.erb | 2 +- app/views/admin/shared/_debate_search.html.erb | 2 +- app/views/admin/shared/_proposal_search.html.erb | 2 +- app/views/admin/users/index.html.erb | 2 +- app/views/moderation/users/index.html.erb | 2 +- config/locales/en/admin.yml | 12 ++---------- config/locales/en/moderation.yml | 1 - config/locales/es/admin.yml | 14 +++----------- config/locales/es/moderation.yml | 1 - 17 files changed, 18 insertions(+), 36 deletions(-) diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb index 117a9b50f..911f742d2 100644 --- a/app/components/admin/search_component.html.erb +++ b/app/components/admin/search_component.html.erb @@ -1,4 +1,4 @@ <%= form_tag(url, method: :get, role: "search") do |f| %> <%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %> - <%= submit_tag t("admin.shared.user_search.button") %> + <%= submit_tag t("admin.shared.search.search") %> <% end %> diff --git a/app/views/admin/local_census_records/index.html.erb b/app/views/admin/local_census_records/index.html.erb index 0278f8275..bac308537 100644 --- a/app/views/admin/local_census_records/index.html.erb +++ b/app/views/admin/local_census_records/index.html.erb @@ -13,7 +13,7 @@
<%= text_field_tag :search, "", placeholder: t("admin.local_census_records.index.search.placeholder") %>
- <%= submit_tag t("admin.local_census_records.index.search.search"), class: "button" %> + <%= submit_tag t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 8716668eb..8afaeedd8 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -6,7 +6,7 @@ <%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %>
- <%= f.submit t("admin.organizations.index.search"), class: "button" %> + <%= f.submit t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb index 7d2cdb263..6f65f3843 100644 --- a/app/views/admin/organizations/search.html.erb +++ b/app/views/admin/organizations/search.html.erb @@ -5,7 +5,7 @@
<%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %>
- <%= f.submit t("admin.organizations.index.search"), class: "button" %> + <%= f.submit t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/poll/booth_assignments/_search_booths.html.erb b/app/views/admin/poll/booth_assignments/_search_booths.html.erb index b8f5d7c80..adf7ed00d 100644 --- a/app/views/admin/poll/booth_assignments/_search_booths.html.erb +++ b/app/views/admin/poll/booth_assignments/_search_booths.html.erb @@ -5,7 +5,7 @@ @search, placeholder: t("admin.shared.booths_search.placeholder"), id: "search-booths" %>
- <%= submit_tag t("admin.shared.booths_search.button"), class: "button" %> + <%= submit_tag t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/poll/officer_assignments/_search_officers.html.erb b/app/views/admin/poll/officer_assignments/_search_officers.html.erb index 2e994fe8a..b1602dc7e 100644 --- a/app/views/admin/poll/officer_assignments/_search_officers.html.erb +++ b/app/views/admin/poll/officer_assignments/_search_officers.html.erb @@ -5,7 +5,7 @@ @search, placeholder: t("admin.shared.poll_officers_search.placeholder"), id: "search-officers" %>
- <%= submit_tag t("admin.shared.poll_officers_search.button"), class: "button" %> + <%= submit_tag t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/poll/officers/_search.html.erb b/app/views/admin/poll/officers/_search.html.erb index e61d9a73b..8980d5daf 100644 --- a/app/views/admin/poll/officers/_search.html.erb +++ b/app/views/admin/poll/officers/_search.html.erb @@ -5,7 +5,7 @@ <%= text_field_tag :search, "", placeholder: t("admin.poll_officers.search.email_placeholder") %>
- <%= submit_tag t("admin.poll_officers.search.search"), class: "button" %> + <%= submit_tag t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/poll/questions/_search.html.erb b/app/views/admin/poll/questions/_search.html.erb index e8a2c52c5..56127db13 100644 --- a/app/views/admin/poll/questions/_search.html.erb +++ b/app/views/admin/poll/questions/_search.html.erb @@ -4,7 +4,7 @@ @search, placeholder: t("admin.shared.poll_questions_search.placeholder") %>
- <%= submit_tag t("admin.shared.poll_questions_search.button"), class: "button" %> + <%= submit_tag t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/admin/shared/_booth_search.html.erb b/app/views/admin/shared/_booth_search.html.erb index eb22940db..ddaf5db0b 100644 --- a/app/views/admin/shared/_booth_search.html.erb +++ b/app/views/admin/shared/_booth_search.html.erb @@ -3,7 +3,7 @@
<%= text_field_tag :search, params[:search], placeholder: t("admin.shared.booths_search.placeholder") %>
- <%= f.submit t("admin.shared.booths_search.button"), class: "button" %> + <%= f.submit t("admin.shared.search.search"), class: "button" %>
diff --git a/app/views/admin/shared/_debate_search.html.erb b/app/views/admin/shared/_debate_search.html.erb index 42c9938d0..378d23ed4 100644 --- a/app/views/admin/shared/_debate_search.html.erb +++ b/app/views/admin/shared/_debate_search.html.erb @@ -3,7 +3,7 @@
<%= text_field_tag :search, "", placeholder: t("admin.shared.debate_search.placeholder") %>
- <%= f.submit t("admin.shared.debate_search.button"), class: "button" %> + <%= f.submit t("admin.shared.search.search"), class: "button" %>
diff --git a/app/views/admin/shared/_proposal_search.html.erb b/app/views/admin/shared/_proposal_search.html.erb index 5a6207d4c..c8aee5e2a 100644 --- a/app/views/admin/shared/_proposal_search.html.erb +++ b/app/views/admin/shared/_proposal_search.html.erb @@ -3,7 +3,7 @@
<%= text_field_tag :search, "", placeholder: t("admin.shared.proposal_search.placeholder") %>
- <%= f.submit t("admin.shared.proposal_search.button"), class: "button" %> + <%= f.submit t("admin.shared.search.search"), class: "button" %>
diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 612f5d81d..4463ea2e7 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -5,7 +5,7 @@
<%= text_field_tag :search, "", placeholder: t("admin.users.search.placeholder") %>
- <%= submit_tag t("admin.users.search.search"), class: "button" %> + <%= submit_tag t("admin.shared.search.search"), class: "button" %>
<% end %> diff --git a/app/views/moderation/users/index.html.erb b/app/views/moderation/users/index.html.erb index 06403279e..7ea2180f1 100644 --- a/app/views/moderation/users/index.html.erb +++ b/app/views/moderation/users/index.html.erb @@ -6,7 +6,7 @@ <%= text_field_tag :search, "", placeholder: t("moderation.users.index.search_placeholder") %>
- <%= f.submit t("moderation.users.index.search"), class: "button success" %> + <%= f.submit t("admin.shared.search.search"), class: "button success" %>
<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index cf330ae41..6c05bf15c 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -907,7 +907,6 @@ en: entry_name: officer search: email_placeholder: Search user by email - search: Search user_not_found: User not found help: "To add or remove Poll officers use the search form below." poll_officer_assignments: @@ -1170,7 +1169,6 @@ en: no_organizations: There are no organizations. reject: Reject rejected: Rejected - search: Search search_placeholder: Name, email or phone number title: Organisations verified: Verified @@ -1255,23 +1253,19 @@ en: shared: true_value: "Yes" false_value: "No" + search: + search: "Search" booths_search: - button: Search placeholder: Search booth by name or location poll_officers_search: - button: Search placeholder: Search poll officers poll_questions_search: - button: Search placeholder: Search poll questions proposal_search: - button: Search placeholder: Search proposals by title, code, description or question debate_search: - button: Search placeholder: Search debates by title or description user_search: - button: Search placeholder: Search user by name or email search_results: "Search results" no_search_results: "No results found." @@ -1440,7 +1434,6 @@ en: erased: Erased search: placeholder: Search user by email, name or document number - search: Search verifications: index: phone_not_given: Phone not given @@ -1581,7 +1574,6 @@ en: postal_code: Postal code search: placeholder: Search by document number - search: Search import: Import CSV new: creating: Creating new local census record diff --git a/config/locales/en/moderation.yml b/config/locales/en/moderation.yml index 01be3e57d..53b2ea64d 100644 --- a/config/locales/en/moderation.yml +++ b/config/locales/en/moderation.yml @@ -111,7 +111,6 @@ en: index: hidden: Blocked hide: Block - search: Search search_placeholder: email or name of user title: Block users notice_hide: User blocked. All of this user's debates and comments have been hidden. diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 18c87db4b..f970c74f4 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -906,7 +906,6 @@ es: entry_name: presidente de mesa search: email_placeholder: Buscar usuario por email - search: Buscar user_not_found: Usuario no encontrado help: "Para añadir o eliminar Presidentes de mesa utiliza el buscador a continuación." poll_officer_assignments: @@ -1169,7 +1168,6 @@ es: no_organizations: No hay organizaciones. reject: Rechazar rejected: Rechazada - search: Buscar search_placeholder: Nombre, email o teléfono title: Organizaciones verified: Verificada @@ -1254,23 +1252,19 @@ es: shared: true_value: "Sí" false_value: "No" + search: + search: "Buscar" booths_search: - button: Buscar placeholder: Buscar urna por nombre poll_officers_search: - button: Buscar placeholder: Buscar presidentes de mesa poll_questions_search: - button: Buscar placeholder: Buscar preguntas proposal_search: - button: Buscar placeholder: Buscar propuestas por título, código, descripción o pregunta debate_search: - button: Buscar placeholder: Buscar debates por título o descripción user_search: - button: Buscar placeholder: Buscar usuario por nombre o email search_results: "Resultados de la búsqueda" no_search_results: "No se han encontrado resultados." @@ -1439,7 +1433,6 @@ es: erased: Borrados search: placeholder: Buscar usuario por email, nombre o DNI - search: Buscar verifications: index: phone_not_given: No ha dado su teléfono @@ -1580,7 +1573,6 @@ es: postal_code: Código postal search: placeholder: Búsqueda por número de documento - search: Buscar import: Importar CSV new: creating: Creando nuevo registro de censo local @@ -1605,4 +1597,4 @@ es: errored: Filas erróneas created: Registros creados local_census_records: - no_records_found: No se han encontrado registros. \ No newline at end of file + no_records_found: No se han encontrado registros. diff --git a/config/locales/es/moderation.yml b/config/locales/es/moderation.yml index a31d7b6c5..968c7bfd0 100644 --- a/config/locales/es/moderation.yml +++ b/config/locales/es/moderation.yml @@ -111,7 +111,6 @@ es: index: hidden: Bloqueado hide: Bloquear - search: Buscar search_placeholder: email o nombre de usuario title: Bloquear usuarios notice_hide: Usuario bloqueado. Se han ocultado todos sus debates y comentarios. From 9b073599f08bea1f5ed79b915f03580bd4e9b177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 15:50:12 +0100 Subject: [PATCH 08/11] Allow different labels in admin search component --- app/components/admin/search_component.rb | 9 +++------ app/views/admin/shared/_user_search.html.erb | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/components/admin/search_component.rb b/app/components/admin/search_component.rb index 239faacea..28b07cd17 100644 --- a/app/components/admin/search_component.rb +++ b/app/components/admin/search_component.rb @@ -1,8 +1,9 @@ class Admin::SearchComponent < ApplicationComponent - attr_reader :url + attr_reader :url, :label - def initialize(url:) + def initialize(url:, label:) @url = url + @label = label end private @@ -10,8 +11,4 @@ class Admin::SearchComponent < ApplicationComponent def search_terms params[:search] end - - def label - t("admin.shared.user_search.placeholder") - end end diff --git a/app/views/admin/shared/_user_search.html.erb b/app/views/admin/shared/_user_search.html.erb index a2a5eaaf3..2023fd0ed 100644 --- a/app/views/admin/shared/_user_search.html.erb +++ b/app/views/admin/shared/_user_search.html.erb @@ -1 +1 @@ -<%= render Admin::SearchComponent.new(url: url) %> +<%= render Admin::SearchComponent.new(url: url, label: t("admin.shared.user_search.placeholder")) %> From a9427f5971a474192233c7a58a8fbea1dde27605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 16:19:57 +0100 Subject: [PATCH 09/11] Allow custom options in search form component So we keep the same API as the form_tag method. --- app/components/admin/search_component.html.erb | 2 +- app/components/admin/search_component.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/components/admin/search_component.html.erb b/app/components/admin/search_component.html.erb index 911f742d2..0caf05d0e 100644 --- a/app/components/admin/search_component.html.erb +++ b/app/components/admin/search_component.html.erb @@ -1,4 +1,4 @@ -<%= form_tag(url, method: :get, role: "search") do |f| %> +<%= form_tag(url, options) do |f| %> <%= text_field_tag :search, search_terms.to_s, placeholder: label, "aria-label": label %> <%= submit_tag t("admin.shared.search.search") %> <% end %> diff --git a/app/components/admin/search_component.rb b/app/components/admin/search_component.rb index 28b07cd17..da18311ec 100644 --- a/app/components/admin/search_component.rb +++ b/app/components/admin/search_component.rb @@ -1,9 +1,10 @@ class Admin::SearchComponent < ApplicationComponent - attr_reader :url, :label + attr_reader :url, :label, :form_options - def initialize(url:, label:) + def initialize(url:, label:, **form_options) @url = url @label = label + @form_options = form_options end private @@ -11,4 +12,8 @@ class Admin::SearchComponent < ApplicationComponent def search_terms params[:search] end + + def options + { method: :get, role: "search" }.merge(form_options) + end end From e33794e45e87cc0fa517bb99bf9a68187d09b359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 17:33:57 +0100 Subject: [PATCH 10/11] Reuse admin search component in other sections There are some sections where we are not reusing it: * The budget investments search is completely different, so this component isn't appropriate there * Booth assignment and officers are slightly different, and I'm not entirely sure it's safe to refactor these cases --- .../admin/poll/questions_controller.rb | 2 -- app/views/admin/debates/index.html.erb | 5 ++++- .../admin/local_census_records/index.html.erb | 15 +++++---------- app/views/admin/organizations/index.html.erb | 15 ++++----------- app/views/admin/organizations/search.html.erb | 14 ++++---------- app/views/admin/poll/booths/index.html.erb | 5 ++++- app/views/admin/poll/officers/_search.html.erb | 14 +++++--------- app/views/admin/poll/officers/index.html.erb | 4 +--- app/views/admin/poll/questions/_search.html.erb | 14 ++++---------- app/views/admin/poll/questions/index.html.erb | 4 +--- app/views/admin/proposals/index.html.erb | 5 ++++- app/views/admin/shared/_booth_search.html.erb | 10 ---------- app/views/admin/shared/_debate_search.html.erb | 10 ---------- app/views/admin/shared/_proposal_search.html.erb | 10 ---------- app/views/admin/users/index.html.erb | 15 +++++---------- app/views/management/proposals/index.html.erb | 5 ++++- app/views/moderation/users/index.html.erb | 14 ++++---------- 17 files changed, 49 insertions(+), 112 deletions(-) delete mode 100644 app/views/admin/shared/_booth_search.html.erb delete mode 100644 app/views/admin/shared/_debate_search.html.erb delete mode 100644 app/views/admin/shared/_proposal_search.html.erb diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb index c6d147af0..f17ac5c9c 100644 --- a/app/controllers/admin/poll/questions_controller.rb +++ b/app/controllers/admin/poll/questions_controller.rb @@ -7,8 +7,6 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController def index @polls = Poll.not_budget - @search = search_params[:search] - @questions = @questions.search(search_params).page(params[:page]).order("created_at DESC") @proposals = Proposal.successful.sort_by_confidence_score diff --git a/app/views/admin/debates/index.html.erb b/app/views/admin/debates/index.html.erb index 117c9f9f8..bac99fdde 100644 --- a/app/views/admin/debates/index.html.erb +++ b/app/views/admin/debates/index.html.erb @@ -5,7 +5,10 @@

<%= t("admin.debates.index.title") %>

<% if @debates.any? %> - <%= render "/admin/shared/debate_search", url: admin_debates_path %> + <%= render Admin::SearchComponent.new( + url: admin_debates_path, + label: t("admin.shared.debate_search.placeholder") + ) %>

<%= page_entries_info @debates %>

diff --git a/app/views/admin/local_census_records/index.html.erb b/app/views/admin/local_census_records/index.html.erb index bac308537..3ac46dce2 100644 --- a/app/views/admin/local_census_records/index.html.erb +++ b/app/views/admin/local_census_records/index.html.erb @@ -8,16 +8,11 @@ new_admin_local_census_records_import_path, class: "button float-right hollow" %> -
- <%= form_tag admin_local_census_records_path, method: :get, remote: true do %> -
- <%= text_field_tag :search, "", placeholder: t("admin.local_census_records.index.search.placeholder") %> -
- <%= submit_tag t("admin.shared.search.search"), class: "button" %> -
-
- <% end %> -
+<%= render Admin::SearchComponent.new( + url: admin_local_census_records_path, + label: t("admin.local_census_records.index.search.placeholder"), + remote: true +) %>
<%= render "local_census_records" %> diff --git a/app/views/admin/organizations/index.html.erb b/app/views/admin/organizations/index.html.erb index 8afaeedd8..d28ffc42f 100644 --- a/app/views/admin/organizations/index.html.erb +++ b/app/views/admin/organizations/index.html.erb @@ -1,16 +1,9 @@

<%= t("admin.organizations.index.title") %>

-
- <%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %> -
- <%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %> - -
- <%= f.submit t("admin.shared.search.search"), class: "button" %> -
-
- <% end %> -
+<%= render Admin::SearchComponent.new( + url: search_admin_organizations_path, + label: t("admin.organizations.index.search_placeholder") +) %> <%= render "shared/filter_subnav", i18n_namespace: "admin.organizations.index" %> diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb index 6f65f3843..2c40759f1 100644 --- a/app/views/admin/organizations/search.html.erb +++ b/app/views/admin/organizations/search.html.erb @@ -1,15 +1,9 @@

<%= t("admin.organizations.search.title") %>

-
- <%= form_for(Organization.new, url: search_admin_organizations_path, method: :get) do |f| %> -
- <%= text_field_tag :search, "", placeholder: t("admin.organizations.index.search_placeholder") %> -
- <%= f.submit t("admin.shared.search.search"), class: "button" %> -
-
- <% end %> -
+<%= render Admin::SearchComponent.new( + url: search_admin_organizations_path, + label: t("admin.organizations.index.search_placeholder") +) %>
<% if @organizations.any? %> diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index 415515653..fd1353a72 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -4,7 +4,10 @@ <%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button float-right" %> <% end %> -<%= render "/admin/shared/booth_search", url: admin_booths_path %> +<%= render Admin::SearchComponent.new( + url: admin_booths_path, + label: t("admin.shared.booths_search.placeholder") +) %> <% if @booths.empty? %>
diff --git a/app/views/admin/poll/officers/_search.html.erb b/app/views/admin/poll/officers/_search.html.erb index 8980d5daf..715a15237 100644 --- a/app/views/admin/poll/officers/_search.html.erb +++ b/app/views/admin/poll/officers/_search.html.erb @@ -1,11 +1,7 @@

<%= t("admin.poll_officers.search.help") %>

-<%= form_tag search_admin_officers_path, method: :get, remote: true do %> -
- <%= text_field_tag :search, "", - placeholder: t("admin.poll_officers.search.email_placeholder") %> -
- <%= submit_tag t("admin.shared.search.search"), class: "button" %> -
-
-<% end %> +<%= render Admin::SearchComponent.new( + url: search_admin_officers_path, + label: t("admin.poll_officers.search.email_placeholder"), + remote: true +) %> diff --git a/app/views/admin/poll/officers/index.html.erb b/app/views/admin/poll/officers/index.html.erb index c6b5caf74..1f84a46ee 100644 --- a/app/views/admin/poll/officers/index.html.erb +++ b/app/views/admin/poll/officers/index.html.erb @@ -1,8 +1,6 @@

<%= t("admin.poll_officers.index.title") %>

-
- <%= render "search" %> -
+<%= render "search" %>
diff --git a/app/views/admin/poll/questions/_search.html.erb b/app/views/admin/poll/questions/_search.html.erb index 56127db13..5f627756b 100644 --- a/app/views/admin/poll/questions/_search.html.erb +++ b/app/views/admin/poll/questions/_search.html.erb @@ -1,10 +1,4 @@ -<%= form_tag(admin_questions_path, method: :get) do |f| %> -
- <%= text_field_tag :search, - @search, - placeholder: t("admin.shared.poll_questions_search.placeholder") %> -
- <%= submit_tag t("admin.shared.search.search"), class: "button" %> -
-
-<% end %> +<%= render Admin::SearchComponent.new( + url: admin_questions_path, + label: t("admin.shared.poll_questions_search.placeholder") +) %> diff --git a/app/views/admin/poll/questions/index.html.erb b/app/views/admin/poll/questions/index.html.erb index d5fac81e4..6f704e489 100644 --- a/app/views/admin/poll/questions/index.html.erb +++ b/app/views/admin/poll/questions/index.html.erb @@ -3,9 +3,7 @@ <%= link_to t("admin.questions.index.create"), new_admin_question_path, class: "button float-right" %> -
- <%= render "search" %> -
+<%= render "search" %>
<%= render "filter_subnav" %> diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb index bc59de812..43693ea1e 100644 --- a/app/views/admin/proposals/index.html.erb +++ b/app/views/admin/proposals/index.html.erb @@ -5,7 +5,10 @@

<%= t("admin.proposals.index.title") %>

<% if @proposals.any? %> - <%= render "/admin/shared/proposal_search", url: admin_proposals_path %> + <%= render Admin::SearchComponent.new( + url: admin_proposals_path, + label: t("admin.shared.proposal_search.placeholder") + ) %>

<%= page_entries_info @proposals %>

diff --git a/app/views/admin/shared/_booth_search.html.erb b/app/views/admin/shared/_booth_search.html.erb deleted file mode 100644 index ddaf5db0b..000000000 --- a/app/views/admin/shared/_booth_search.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%= form_for(Poll::Booth.new, url: url, as: :booth, method: :get) do |f| %> -
-
- <%= text_field_tag :search, params[:search], placeholder: t("admin.shared.booths_search.placeholder") %> -
- <%= f.submit t("admin.shared.search.search"), class: "button" %> -
-
-
-<% end %> diff --git a/app/views/admin/shared/_debate_search.html.erb b/app/views/admin/shared/_debate_search.html.erb deleted file mode 100644 index 378d23ed4..000000000 --- a/app/views/admin/shared/_debate_search.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%= form_for(Debate.new, url: url, as: :debate, method: :get) do |f| %> -
-
- <%= text_field_tag :search, "", placeholder: t("admin.shared.debate_search.placeholder") %> -
- <%= f.submit t("admin.shared.search.search"), class: "button" %> -
-
-
-<% end %> diff --git a/app/views/admin/shared/_proposal_search.html.erb b/app/views/admin/shared/_proposal_search.html.erb deleted file mode 100644 index c8aee5e2a..000000000 --- a/app/views/admin/shared/_proposal_search.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%= form_for(Proposal.new, url: url, as: :proposal, method: :get) do |f| %> -
-
- <%= text_field_tag :search, "", placeholder: t("admin.shared.proposal_search.placeholder") %> -
- <%= f.submit t("admin.shared.search.search"), class: "button" %> -
-
-
-<% end %> diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 4463ea2e7..49165c31e 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -1,15 +1,10 @@

<%= t("admin.users.index.title") %>

-
- <%= form_tag admin_users_path, method: :get, remote: true do %> -
- <%= text_field_tag :search, "", placeholder: t("admin.users.search.placeholder") %> -
- <%= submit_tag t("admin.shared.search.search"), class: "button" %> -
-
- <% end %> -
+<%= render Admin::SearchComponent.new( + url: admin_users_path, + label: t("admin.users.search.placeholder"), + remote: true +) %>
<%= render "users" %> diff --git a/app/views/management/proposals/index.html.erb b/app/views/management/proposals/index.html.erb index 6ec7bd712..21397b553 100644 --- a/app/views/management/proposals/index.html.erb +++ b/app/views/management/proposals/index.html.erb @@ -1,7 +1,10 @@

<%= t("management.proposals.index.title") %>

- <%= render "admin/shared/proposal_search", url: management_proposals_path %> + <%= render Admin::SearchComponent.new( + url: management_proposals_path, + label: t("admin.shared.proposal_search.placeholder") + ) %>
diff --git a/app/views/moderation/users/index.html.erb b/app/views/moderation/users/index.html.erb index 7ea2180f1..6ae397dd4 100644 --- a/app/views/moderation/users/index.html.erb +++ b/app/views/moderation/users/index.html.erb @@ -1,15 +1,9 @@

<%= t("moderation.users.index.title") %>

-<%= form_for(User.new, url: moderation_users_path, as: :user, method: :get) do |f| %> -
-
- <%= text_field_tag :search, "", placeholder: t("moderation.users.index.search_placeholder") %> -
-
- <%= f.submit t("admin.shared.search.search"), class: "button success" %> -
-
-<% end %> +<%= render Admin::SearchComponent.new( + url: moderation_users_path, + label: t("moderation.users.index.search_placeholder") +) %> <% if @users.present? %>

<%= page_entries_info @users %>

From cf510043a485811f669c9a94ec7ae538bf8db830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Dec 2020 17:43:14 +0100 Subject: [PATCH 11/11] Search on the same URL by default --- app/components/admin/search_component.rb | 10 +++++++--- app/views/admin/debates/index.html.erb | 5 +---- app/views/admin/local_census_records/index.html.erb | 1 - app/views/admin/organizations/search.html.erb | 5 +---- app/views/admin/poll/booths/index.html.erb | 5 +---- app/views/admin/poll/questions/_search.html.erb | 5 +---- app/views/admin/proposals/index.html.erb | 5 +---- app/views/admin/users/index.html.erb | 1 - app/views/management/proposals/index.html.erb | 5 +---- app/views/moderation/users/index.html.erb | 5 +---- 10 files changed, 14 insertions(+), 33 deletions(-) diff --git a/app/components/admin/search_component.rb b/app/components/admin/search_component.rb index da18311ec..e7c4a3e45 100644 --- a/app/components/admin/search_component.rb +++ b/app/components/admin/search_component.rb @@ -1,12 +1,16 @@ class Admin::SearchComponent < ApplicationComponent - attr_reader :url, :label, :form_options + attr_reader :label, :form_options - def initialize(url:, label:, **form_options) - @url = url + def initialize(label:, url: nil, **form_options) @label = label + @url = url @form_options = form_options end + def url + @url || request.path + end + private def search_terms diff --git a/app/views/admin/debates/index.html.erb b/app/views/admin/debates/index.html.erb index bac99fdde..7a743aea1 100644 --- a/app/views/admin/debates/index.html.erb +++ b/app/views/admin/debates/index.html.erb @@ -5,10 +5,7 @@

<%= t("admin.debates.index.title") %>

<% if @debates.any? %> - <%= render Admin::SearchComponent.new( - url: admin_debates_path, - label: t("admin.shared.debate_search.placeholder") - ) %> + <%= render Admin::SearchComponent.new(label: t("admin.shared.debate_search.placeholder")) %>

<%= page_entries_info @debates %>

diff --git a/app/views/admin/local_census_records/index.html.erb b/app/views/admin/local_census_records/index.html.erb index 3ac46dce2..5de47ed85 100644 --- a/app/views/admin/local_census_records/index.html.erb +++ b/app/views/admin/local_census_records/index.html.erb @@ -9,7 +9,6 @@ class: "button float-right hollow" %> <%= render Admin::SearchComponent.new( - url: admin_local_census_records_path, label: t("admin.local_census_records.index.search.placeholder"), remote: true ) %> diff --git a/app/views/admin/organizations/search.html.erb b/app/views/admin/organizations/search.html.erb index 2c40759f1..40a08a7c9 100644 --- a/app/views/admin/organizations/search.html.erb +++ b/app/views/admin/organizations/search.html.erb @@ -1,9 +1,6 @@

<%= t("admin.organizations.search.title") %>

-<%= render Admin::SearchComponent.new( - url: search_admin_organizations_path, - label: t("admin.organizations.index.search_placeholder") -) %> +<%= render Admin::SearchComponent.new(label: t("admin.organizations.index.search_placeholder")) %>
<% if @organizations.any? %> diff --git a/app/views/admin/poll/booths/index.html.erb b/app/views/admin/poll/booths/index.html.erb index fd1353a72..4954801a2 100644 --- a/app/views/admin/poll/booths/index.html.erb +++ b/app/views/admin/poll/booths/index.html.erb @@ -4,10 +4,7 @@ <%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button float-right" %> <% end %> -<%= render Admin::SearchComponent.new( - url: admin_booths_path, - label: t("admin.shared.booths_search.placeholder") -) %> +<%= render Admin::SearchComponent.new(label: t("admin.shared.booths_search.placeholder")) %> <% if @booths.empty? %>
diff --git a/app/views/admin/poll/questions/_search.html.erb b/app/views/admin/poll/questions/_search.html.erb index 5f627756b..73730dcd6 100644 --- a/app/views/admin/poll/questions/_search.html.erb +++ b/app/views/admin/poll/questions/_search.html.erb @@ -1,4 +1 @@ -<%= render Admin::SearchComponent.new( - url: admin_questions_path, - label: t("admin.shared.poll_questions_search.placeholder") -) %> +<%= render Admin::SearchComponent.new(label: t("admin.shared.poll_questions_search.placeholder")) %> diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb index 43693ea1e..075e70278 100644 --- a/app/views/admin/proposals/index.html.erb +++ b/app/views/admin/proposals/index.html.erb @@ -5,10 +5,7 @@

<%= t("admin.proposals.index.title") %>

<% if @proposals.any? %> - <%= render Admin::SearchComponent.new( - url: admin_proposals_path, - label: t("admin.shared.proposal_search.placeholder") - ) %> + <%= render Admin::SearchComponent.new(label: t("admin.shared.proposal_search.placeholder")) %>

<%= page_entries_info @proposals %>

diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index 49165c31e..96ece4ae5 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -1,7 +1,6 @@

<%= t("admin.users.index.title") %>

<%= render Admin::SearchComponent.new( - url: admin_users_path, label: t("admin.users.search.placeholder"), remote: true ) %> diff --git a/app/views/management/proposals/index.html.erb b/app/views/management/proposals/index.html.erb index 21397b553..a5862961e 100644 --- a/app/views/management/proposals/index.html.erb +++ b/app/views/management/proposals/index.html.erb @@ -1,10 +1,7 @@

<%= t("management.proposals.index.title") %>

- <%= render Admin::SearchComponent.new( - url: management_proposals_path, - label: t("admin.shared.proposal_search.placeholder") - ) %> + <%= render Admin::SearchComponent.new(label: t("admin.shared.proposal_search.placeholder")) %>
diff --git a/app/views/moderation/users/index.html.erb b/app/views/moderation/users/index.html.erb index 6ae397dd4..9008f8fec 100644 --- a/app/views/moderation/users/index.html.erb +++ b/app/views/moderation/users/index.html.erb @@ -1,9 +1,6 @@

<%= t("moderation.users.index.title") %>

-<%= render Admin::SearchComponent.new( - url: moderation_users_path, - label: t("moderation.users.index.search_placeholder") -) %> +<%= render Admin::SearchComponent.new(label: t("moderation.users.index.search_placeholder")) %> <% if @users.present? %>

<%= page_entries_info @users %>