Commit 29db3f2c authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'filter-by-any-user' into 'master'

Filter issuables by any user

![any-user](/uploads/c9626b9ac355747344a7073f61dc0c82/any-user.gif)

Closes #2836

See merge request !3820
parents fb83f4bf dddcab7e
......@@ -93,7 +93,9 @@ class @UsersSelect
$dropdown.glDropdown(
data: (term, callback) =>
@users term, (users) =>
isAuthorFilter = $('.js-author-search')
@users term, term is '' and isAuthorFilter, (users) =>
if term.length is 0
showDivider = 0
......@@ -138,7 +140,7 @@ class @UsersSelect
toggleLabel: (selected) ->
if selected && 'id' of selected
selected.name
if selected.text then selected.text else selected.name
else
defaultLabel
......@@ -219,7 +221,7 @@ class @UsersSelect
multiple: $(select).hasClass('multiselect')
minimumInputLength: 0
query: (query) =>
@users query.term, (users) =>
@users query.term, @projectId?, (users) =>
data = { results: users }
if query.term.length == 0
......@@ -302,7 +304,7 @@ class @UsersSelect
# Return users list. Filtered by query
# Only active users retrieved
users: (query, callback) =>
users: (query, fromProject, callback) =>
url = @buildUrl(@usersPath)
$.ajax(
......@@ -311,7 +313,7 @@ class @UsersSelect
search: query
per_page: 20
active: true
project_id: @projectId
project_id: @projectId if fromProject
group_id: @groupId
current_user: @showCurrentUser
author_id: @authorId
......
......@@ -50,14 +50,10 @@ module IssuablesHelper
end
def user_dropdown_label(user_id, default_label)
return default_label if user_id.nil?
return "Unassigned" if user_id == "0"
if @project
member = @project.team.find_member(user_id)
user = member.user if member
else
user = User.find_by(id: user_id)
end
if user
user.name
......
......@@ -12,7 +12,7 @@
- if params[:author_id].present?
= hidden_field_tag(:author_id, params[:author_id])
= dropdown_tag(user_dropdown_label(params[:author_id], "Author"), options: { toggle_class: "js-user-search js-filter-submit js-author-search", title: "Filter by author", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit",
placeholder: "Search authors", data: { any_user: "Any Author", first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: "author_id", default_label: "Author" } })
placeholder: "Search authors", data: { any_user: "Any Author", first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author], field_name: "author_id", default_label: "Author" } })
.filter-item.inline
- if params[:assignee_id].present?
......
......@@ -294,4 +294,40 @@ describe 'Filter issues', feature: true do
end
end
end
describe 'filter by any author', js: true do
before do
user2 = create(:user, name: "tester")
create(:issue, project: project, author: user)
create(:issue, project: project, author: user2)
visit namespace_project_issues_path(project.namespace, project)
end
it 'should show filter by any author link' do
click_button "Author"
fill_in "Search authors", with: "tester"
page.within ".dropdown-menu-author" do
expect(page).to have_content "tester"
end
end
it 'should show filter issues by any author' do
page.within '.issues-list' do
expect(page).to have_selector ".issue", count: 2
end
click_button "Author"
fill_in "Search authors", with: "tester"
page.within ".dropdown-menu-author" do
click_link "tester"
end
page.within '.issues-list' do
expect(page).to have_selector ".issue", count: 1
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment