Fix losing search query when sort users on admin users page
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
0d5cbd16ee
commit
40c86cfede
8 changed files with 94 additions and 39 deletions
|
@ -120,6 +120,18 @@ module SortingHelper
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def users_sort_options_hash
|
||||||
|
{
|
||||||
|
sort_value_name => sort_title_name,
|
||||||
|
sort_value_recently_signin => sort_title_recently_signin,
|
||||||
|
sort_value_oldest_signin => sort_title_oldest_signin,
|
||||||
|
sort_value_recently_created => sort_title_recently_created,
|
||||||
|
sort_value_oldest_created => sort_title_oldest_created,
|
||||||
|
sort_value_recently_updated => sort_title_recently_updated,
|
||||||
|
sort_value_oldest_updated => sort_title_oldest_updated
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def sortable_item(item, path, sorted_by)
|
def sortable_item(item, path, sorted_by)
|
||||||
link_to item, path, class: sorted_by == item ? 'is-active' : ''
|
link_to item, path, class: sorted_by == item ? 'is-active' : ''
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,27 +10,16 @@
|
||||||
.search-field-holder
|
.search-field-holder
|
||||||
= search_field_tag :search_query, params[:search_query], placeholder: 'Search by name, email or username', class: 'form-control search-text-input js-search-input', spellcheck: false
|
= search_field_tag :search_query, params[:search_query], placeholder: 'Search by name, email or username', class: 'form-control search-text-input js-search-input', spellcheck: false
|
||||||
= icon("search", class: "search-icon")
|
= icon("search", class: "search-icon")
|
||||||
.dropdown
|
.dropdown.user-sort-dropdown
|
||||||
- toggle_text = if @sort.present? then sort_options_hash[@sort] else sort_title_name end
|
- toggle_text = if @sort.present? then sort_options_hash[@sort] else sort_title_name end
|
||||||
= dropdown_toggle(toggle_text, { toggle: 'dropdown' })
|
= dropdown_toggle(toggle_text, { toggle: 'dropdown' })
|
||||||
%ul.dropdown-menu.dropdown-menu-right
|
%ul.dropdown-menu.dropdown-menu-right
|
||||||
%li.dropdown-header
|
%li.dropdown-header
|
||||||
Sort by
|
Sort by
|
||||||
%li
|
%li
|
||||||
= link_to admin_users_path(sort: sort_value_name, filter: params[:filter]) do
|
- users_sort_options_hash.each do |value, title|
|
||||||
= sort_title_name
|
= link_to admin_users_path(sort: value, filter: params[:filter], search_query: params[:search_query]) do
|
||||||
= link_to admin_users_path(sort: sort_value_recently_signin, filter: params[:filter]) do
|
= title
|
||||||
= sort_title_recently_signin
|
|
||||||
= link_to admin_users_path(sort: sort_value_oldest_signin, filter: params[:filter]) do
|
|
||||||
= sort_title_oldest_signin
|
|
||||||
= link_to admin_users_path(sort: sort_value_recently_created, filter: params[:filter]) do
|
|
||||||
= sort_title_recently_created
|
|
||||||
= link_to admin_users_path(sort: sort_value_oldest_created, filter: params[:filter]) do
|
|
||||||
= sort_title_oldest_created
|
|
||||||
= link_to admin_users_path(sort: sort_value_recently_updated, filter: params[:filter]) do
|
|
||||||
= sort_title_recently_updated
|
|
||||||
= link_to admin_users_path(sort: sort_value_oldest_updated, filter: params[:filter]) do
|
|
||||||
= sort_title_oldest_updated
|
|
||||||
= link_to 'New user', new_admin_user_path, class: 'btn btn-success btn-search'
|
= link_to 'New user', new_admin_user_path, class: 'btn btn-success btn-search'
|
||||||
|
|
||||||
.top-area.scrolling-tabs-container.inner-page-scroll-tabs
|
.top-area.scrolling-tabs-container.inner-page-scroll-tabs
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Allow search and sort users at same time on admin users page
|
||||||
|
merge_request: 23439
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe "Admin::Users" do
|
describe "Admin::Users" do
|
||||||
|
include Spec::Support::Helpers::Features::RowsHelpers
|
||||||
|
|
||||||
let!(:user) do
|
let!(:user) do
|
||||||
create(:omniauth_user, provider: 'twitter', extern_uid: '123456')
|
create(:omniauth_user, provider: 'twitter', extern_uid: '123456')
|
||||||
end
|
end
|
||||||
|
@ -30,6 +32,41 @@ describe "Admin::Users" do
|
||||||
expect(page).to have_button('Delete user and contributions')
|
expect(page).to have_button('Delete user and contributions')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'search and sort' do
|
||||||
|
before do
|
||||||
|
create(:user, name: 'Foo Bar')
|
||||||
|
create(:user, name: 'Foo Baz')
|
||||||
|
create(:user, name: 'Dmitriy')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'search users by name' do
|
||||||
|
visit admin_users_path(search_query: 'Foo')
|
||||||
|
|
||||||
|
expect(page).to have_content('Foo Bar')
|
||||||
|
expect(page).to have_content('Foo Baz')
|
||||||
|
expect(page).not_to have_content('Dmitriy')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sorts users by name' do
|
||||||
|
visit admin_users_path
|
||||||
|
|
||||||
|
sort_by('Name')
|
||||||
|
|
||||||
|
expect(first_row.text).to include('Dmitriy')
|
||||||
|
expect(second_row.text).to include('Foo Bar')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sorts search results only' do
|
||||||
|
visit admin_users_path(search_query: 'Foo')
|
||||||
|
|
||||||
|
sort_by('Name')
|
||||||
|
|
||||||
|
expect(page).not_to have_content('Dmitriy')
|
||||||
|
expect(first_row.text).to include('Foo Bar')
|
||||||
|
expect(second_row.text).to include('Foo Baz')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'Two-factor Authentication filters' do
|
describe 'Two-factor Authentication filters' do
|
||||||
it 'counts users who have enabled 2FA' do
|
it 'counts users who have enabled 2FA' do
|
||||||
create(:user, :two_factor)
|
create(:user, :two_factor)
|
||||||
|
@ -566,4 +603,10 @@ describe "Admin::Users" do
|
||||||
def check_breadcrumb(content)
|
def check_breadcrumb(content)
|
||||||
expect(find('.breadcrumbs-sub-title')).to have_content(content)
|
expect(find('.breadcrumbs-sub-title')).to have_content(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sort_by(text)
|
||||||
|
page.within('.user-sort-dropdown') do
|
||||||
|
click_link text
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe 'Groups > Members > List members' do
|
describe 'Groups > Members > List members' do
|
||||||
include Select2Helper
|
include Select2Helper
|
||||||
|
include Spec::Support::Helpers::Features::RowsHelpers
|
||||||
|
|
||||||
let(:user1) { create(:user, name: 'John Doe') }
|
let(:user1) { create(:user, name: 'John Doe') }
|
||||||
let(:user2) { create(:user, name: 'Mary Jane') }
|
let(:user2) { create(:user, name: 'Mary Jane') }
|
||||||
|
@ -43,12 +44,4 @@ describe 'Groups > Members > List members' do
|
||||||
let(:user_with_status) { user2 }
|
let(:user_with_status) { user2 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_row
|
|
||||||
page.all('ul.content-list > li')[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
def second_row
|
|
||||||
page.all('ul.content-list > li')[1]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe 'Groups > Members > Manage members' do
|
describe 'Groups > Members > Manage members' do
|
||||||
include Select2Helper
|
include Select2Helper
|
||||||
|
include Spec::Support::Helpers::Features::RowsHelpers
|
||||||
|
|
||||||
let(:user1) { create(:user, name: 'John Doe') }
|
let(:user1) { create(:user, name: 'John Doe') }
|
||||||
let(:user2) { create(:user, name: 'Mary Jane') }
|
let(:user2) { create(:user, name: 'Mary Jane') }
|
||||||
|
@ -119,14 +120,6 @@ describe 'Groups > Members > Manage members' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_row
|
|
||||||
page.all('ul.content-list > li')[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
def second_row
|
|
||||||
page.all('ul.content-list > li')[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_user(id, role)
|
def add_user(id, role)
|
||||||
page.within ".users-group-form" do
|
page.within ".users-group-form" do
|
||||||
select2(id, from: "#user_ids", multiple: true)
|
select2(id, from: "#user_ids", multiple: true)
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe 'Project members list' do
|
describe 'Project members list' do
|
||||||
include Select2Helper
|
include Select2Helper
|
||||||
|
include Spec::Support::Helpers::Features::RowsHelpers
|
||||||
|
|
||||||
let(:user1) { create(:user, name: 'John Doe') }
|
let(:user1) { create(:user, name: 'John Doe') }
|
||||||
let(:user2) { create(:user, name: 'Mary Jane') }
|
let(:user2) { create(:user, name: 'Mary Jane') }
|
||||||
|
@ -83,14 +84,6 @@ describe 'Project members list' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_row
|
|
||||||
page.all('ul.content-list > li')[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
def second_row
|
|
||||||
page.all('ul.content-list > li')[1]
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_user(id, role)
|
def add_user(id, role)
|
||||||
page.within ".users-project-form" do
|
page.within ".users-project-form" do
|
||||||
select2(id, from: "#user_ids", multiple: true)
|
select2(id, from: "#user_ids", multiple: true)
|
||||||
|
|
27
spec/support/helpers/features/rows_helpers.rb
Normal file
27
spec/support/helpers/features/rows_helpers.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# These helpers allow you to access rows in the list
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# describe "..." do
|
||||||
|
# include Spec::Support::Helpers::Features::RowsHelpers
|
||||||
|
# ...
|
||||||
|
#
|
||||||
|
# expect(first_row.text).to include("John Doe")
|
||||||
|
# expect(second_row.text).to include("John Smith")
|
||||||
|
#
|
||||||
|
module Spec
|
||||||
|
module Support
|
||||||
|
module Helpers
|
||||||
|
module Features
|
||||||
|
module RowsHelpers
|
||||||
|
def first_row
|
||||||
|
page.all('ul.content-list > li')[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
def second_row
|
||||||
|
page.all('ul.content-list > li')[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue