Commit 3ee3cb24 authored by Robert Speicher's avatar Robert Speicher

Allow user to filter by Issues/Merge Requests without a Milestone

parent ea565653
......@@ -76,7 +76,7 @@ class IssuableFinder
return @milestones if defined?(@milestones)
@milestones =
if milestones? && params[:milestone_title] != NONE
if milestones? && params[:milestone_title] != NoMilestone.title
Milestone.where(title: params[:milestone_title])
else
nil
......@@ -183,7 +183,12 @@ class IssuableFinder
def by_milestone(items)
if milestones?
items = items.where(milestone_id: milestones.try(:pluck, :id))
# `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))
else
items = items.where(milestone_id: NoMilestone.id)
end
end
items
......
......@@ -29,6 +29,8 @@ module MilestonesHelper
end.active
grouped_milestones = Milestones::GroupService.new(milestones).execute
grouped_milestones.unshift(NoMilestone)
options_from_collection_for_select(grouped_milestones, 'title', 'title', params[:milestone_title])
end
end
# 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)
.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
.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
= render 'shared/sort_dropdown'
......
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
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
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