Allow user to filter by Issues/Merge Requests without a Milestone
This commit is contained in:
parent
ea565653a0
commit
3ee3cb24d4
6 changed files with 104 additions and 4 deletions
|
@ -76,7 +76,7 @@ class IssuableFinder
|
||||||
return @milestones if defined?(@milestones)
|
return @milestones if defined?(@milestones)
|
||||||
|
|
||||||
@milestones =
|
@milestones =
|
||||||
if milestones? && params[:milestone_title] != NONE
|
if milestones? && params[:milestone_title] != NoMilestone.title
|
||||||
Milestone.where(title: params[:milestone_title])
|
Milestone.where(title: params[:milestone_title])
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
@ -183,7 +183,12 @@ class IssuableFinder
|
||||||
|
|
||||||
def by_milestone(items)
|
def by_milestone(items)
|
||||||
if milestones?
|
if milestones?
|
||||||
|
# `milestone_title` will still be present when "No Milestone" is selected
|
||||||
|
if params[:milestone_title] != NoMilestone.title
|
||||||
items = items.where(milestone_id: milestones.try(:pluck, :id))
|
items = items.where(milestone_id: milestones.try(:pluck, :id))
|
||||||
|
else
|
||||||
|
items = items.where(milestone_id: NoMilestone.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
items
|
items
|
||||||
|
|
|
@ -29,6 +29,8 @@ module MilestonesHelper
|
||||||
end.active
|
end.active
|
||||||
|
|
||||||
grouped_milestones = Milestones::GroupService.new(milestones).execute
|
grouped_milestones = Milestones::GroupService.new(milestones).execute
|
||||||
|
grouped_milestones.unshift(NoMilestone)
|
||||||
|
|
||||||
options_from_collection_for_select(grouped_milestones, 'title', 'title', params[:milestone_title])
|
options_from_collection_for_select(grouped_milestones, 'title', 'title', params[:milestone_title])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
13
app/models/no_milestone.rb
Normal file
13
app/models/no_milestone.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# NoMilestone
|
||||||
|
#
|
||||||
|
# Represents a "No Milestone" state used for filtering Issues and Merge Requests
|
||||||
|
# that have no milestone assigned.
|
||||||
|
class NoMilestone
|
||||||
|
def self.id
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.title
|
||||||
|
'No Milestone'
|
||||||
|
end
|
||||||
|
end
|
|
@ -43,11 +43,15 @@
|
||||||
placeholder: 'Author', class: 'trigger-submit', any_user: true, first_user: true)
|
placeholder: 'Author', class: 'trigger-submit', any_user: true, first_user: true)
|
||||||
|
|
||||||
.filter-item.inline.milestone-filter
|
.filter-item.inline.milestone-filter
|
||||||
= select_tag('milestone_title', projects_milestones_options, class: "select2 trigger-submit", prompt: 'Milestone')
|
= select_tag('milestone_title', projects_milestones_options,
|
||||||
|
class: 'select2 trigger-submit', include_blank: true,
|
||||||
|
data: {placeholder: 'Milestone'})
|
||||||
|
|
||||||
- if @project
|
- if @project
|
||||||
.filter-item.inline.labels-filter
|
.filter-item.inline.labels-filter
|
||||||
= select_tag('label_name', project_labels_options(@project), class: "select2 trigger-submit", prompt: 'Label')
|
= select_tag('label_name', project_labels_options(@project),
|
||||||
|
class: 'select2 trigger-submit', include_blank: true,
|
||||||
|
data: {placeholder: 'Label'})
|
||||||
|
|
||||||
.pull-right
|
.pull-right
|
||||||
= render 'shared/sort_dropdown'
|
= render 'shared/sort_dropdown'
|
||||||
|
|
38
spec/features/issues/filter_by_milestone_spec.rb
Normal file
38
spec/features/issues/filter_by_milestone_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
feature 'Issue filtering by Milestone' do
|
||||||
|
include Select2Helper
|
||||||
|
|
||||||
|
let(:project) { create(:empty_project) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
login_as(:admin)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User filters by Issues without a Milestone', js: true do
|
||||||
|
create(:issue, project: project)
|
||||||
|
|
||||||
|
visit_issues
|
||||||
|
filter_by_milestone(NoMilestone.title)
|
||||||
|
|
||||||
|
expect(page).to have_css('.issue-title', count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User filters by Issues with a specific Milestone', js: true do
|
||||||
|
milestone = create(:milestone, project: project)
|
||||||
|
create(:issue, project: project, milestone: milestone)
|
||||||
|
|
||||||
|
visit_issues
|
||||||
|
filter_by_milestone(milestone.title)
|
||||||
|
|
||||||
|
expect(page).to have_css('.issue-title', count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def visit_issues
|
||||||
|
visit namespace_project_issues_path(project.namespace, project)
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_by_milestone(title)
|
||||||
|
select2(title, from: '#milestone_title')
|
||||||
|
end
|
||||||
|
end
|
38
spec/features/merge_requests/filter_by_milestone_spec.rb
Normal file
38
spec/features/merge_requests/filter_by_milestone_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
feature 'Merge Request filtering by Milestone' do
|
||||||
|
include Select2Helper
|
||||||
|
|
||||||
|
let(:project) { create(:project) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
login_as(:admin)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User filters by Merge Requests without a Milestone', js: true do
|
||||||
|
create(:merge_request, :simple, source_project: project)
|
||||||
|
|
||||||
|
visit_merge_requests
|
||||||
|
filter_by_milestone(NoMilestone.title)
|
||||||
|
|
||||||
|
expect(page).to have_css('.merge-request-title', count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'User filters by Merge Requests with a specific Milestone', js: true do
|
||||||
|
milestone = create(:milestone, project: project)
|
||||||
|
create(:merge_request, :simple, source_project: project, milestone: milestone)
|
||||||
|
|
||||||
|
visit_merge_requests
|
||||||
|
filter_by_milestone(milestone.title)
|
||||||
|
|
||||||
|
expect(page).to have_css('.merge-request-title', count: 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def visit_merge_requests
|
||||||
|
visit namespace_project_merge_requests_path(project.namespace, project)
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_by_milestone(title)
|
||||||
|
select2(title, from: '#milestone_title')
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue