Take filters in account in issuable counters

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2016-09-23 15:16:11 +02:00
parent f9887a10d4
commit 9b361a3f44
8 changed files with 145 additions and 137 deletions

View File

@ -12,6 +12,7 @@ v 8.13.0 (unreleased)
- Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison)
- Use a ConnectionPool for Rails.cache on Sidekiq servers
- Only update issuable labels if they have been changed
- Take filters in account in issuable counters. !6496
- Revoke button in Applications Settings underlines on hover.
- Fix Long commit messages overflow viewport in file tree
- Update ruby-prof to 0.16.2. !6026 (Elan Ruusamäe)

View File

@ -183,17 +183,12 @@ class IssuableFinder
end
def by_state(items)
case params[:state]
when 'closed'
items.closed
when 'merged'
items.respond_to?(:merged) ? items.merged : items.closed
when 'all'
items
when 'opened'
items.opened
params[:state] ||= 'all'
if items.respond_to?(params[:state])
items.public_send(params[:state])
else
raise 'You must specify default state'
items
end
end

View File

@ -280,27 +280,24 @@ module ApplicationHelper
end
end
def state_filters_text_for(entity, project)
def issuables_state_counter_text(state, issuables)
titles = {
opened: "Open"
}
entity_title = titles[entity] || entity.to_s.humanize
state_title = titles[state] || state.to_s.humanize
count =
if project.nil?
nil
elsif current_controller?(:issues)
project.issues.visible_to_user(current_user).send(entity).count
elsif current_controller?(:merge_requests)
project.merge_requests.send(entity).count
if @issues || @merge_requests
issuables_finder = @issues ? issues_finder : merge_requests_finder
issuables_finder.params[:state] = state
issuables_finder.execute.page(1).total_count
end
html = content_tag :span, entity_title
html = content_tag(:span, state_title)
if count.present?
html += " "
html += content_tag :span, number_with_delimiter(count), class: 'badge'
html << " " << content_tag(:span, number_with_delimiter(count), class: 'badge')
end
html.html_safe

View File

@ -1,25 +1,25 @@
- type = local_assigns.fetch(:type, :issues)
- page_context_word = type.to_s.humanize(capitalize: false)
- issuables = @issues || @merge_requests
%ul.nav-links.issues-state-filters
- if defined?(type) && type == :merge_requests
- page_context_word = 'merge requests'
- else
- page_context_word = 'issues'
%li{class: ("active" if params[:state] == 'opened')}
= link_to page_filter_path(state: 'opened', label: true), title: "Filter by #{page_context_word} that are currently opened." do
#{state_filters_text_for(:opened, @project)}
#{issuables_state_counter_text(:opened, issuables)}
- if defined?(type) && type == :merge_requests
- if type == :merge_requests
%li{class: ("active" if params[:state] == 'merged')}
= link_to page_filter_path(state: 'merged', label: true), title: 'Filter by merge requests that are currently merged.' do
#{state_filters_text_for(:merged, @project)}
#{issuables_state_counter_text(:merged, issuables)}
%li{class: ("active" if params[:state] == 'closed')}
= link_to page_filter_path(state: 'closed', label: true), title: 'Filter by merge requests that are currently closed and unmerged.' do
#{state_filters_text_for(:closed, @project)}
#{issuables_state_counter_text(:closed, issuables)}
- else
%li{class: ("active" if params[:state] == 'closed')}
= link_to page_filter_path(state: 'closed', label: true), title: 'Filter by issues that are currently closed.' do
#{state_filters_text_for(:closed, @project)}
#{issuables_state_counter_text(:closed, issuables)}
%li{class: ("active" if params[:state] == 'all')}
= link_to page_filter_path(state: 'all', label: true), title: "Show all #{page_context_word}." do
#{state_filters_text_for(:all, @project)}
#{issuables_state_counter_text(:all, issuables)}

View File

@ -21,6 +21,11 @@ describe "Dashboard Issues filtering", feature: true, js: true do
click_link 'No Milestone'
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
expect(page).to have_selector('.issue', count: 1)
end
@ -29,6 +34,11 @@ describe "Dashboard Issues filtering", feature: true, js: true do
click_link 'Any Milestone'
page.within '.issues-state-filters' do
expect(page).to have_content('Open 2')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 2')
end
expect(page).to have_selector('.issue', count: 2)
end
@ -39,6 +49,11 @@ describe "Dashboard Issues filtering", feature: true, js: true do
click_link milestone.title
end
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
expect(page).to have_selector('.issue', count: 1)
end
end

View File

@ -1,10 +1,10 @@
require 'rails_helper'
feature 'Issue filtering by Labels', feature: true do
feature 'Issue filtering by Labels', feature: true, js: true do
include WaitForAjax
let(:project) { create(:project, :public) }
let!(:user) { create(:user)}
let!(:user) { create(:user) }
let!(:label) { create(:label, project: project) }
before do
@ -28,156 +28,85 @@ feature 'Issue filtering by Labels', feature: true do
visit namespace_project_issues_path(project.namespace, project)
end
context 'filter by label bug', js: true do
context 'filter by label bug' do
before do
page.find('.js-label-select').click
wait_for_ajax
execute_script("$('.dropdown-menu-labels li:contains(\"bug\") a').click()")
page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
wait_for_ajax
select_labels('bug')
end
it 'shows issue "Bugfix1" and "Bugfix2" in issues list' do
it 'apply the filter' do
expect(page).to have_content "Bugfix1"
expect(page).to have_content "Bugfix2"
end
it 'does not show "Feature1" in issues list' do
expect(page).not_to have_content "Feature1"
end
it 'shows label "bug" in filtered-labels' do
expect(find('.filtered-labels')).to have_content "bug"
end
it 'does not show label "feature" and "enhancement" in filtered-labels' do
expect(find('.filtered-labels')).not_to have_content "feature"
expect(find('.filtered-labels')).not_to have_content "enhancement"
end
it 'removes label "bug"' do
find('.js-label-filter-remove').click
wait_for_ajax
expect(find('.filtered-labels', visible: false)).to have_no_content "bug"
end
end
context 'filter by label feature', js: true do
context 'filter by label feature' do
before do
page.find('.js-label-select').click
wait_for_ajax
execute_script("$('.dropdown-menu-labels li:contains(\"feature\") a').click()")
page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
wait_for_ajax
select_labels('feature')
end
it 'shows issue "Feature1" in issues list' do
it 'applies the filter' do
expect(page).to have_content "Feature1"
end
it 'does not show "Bugfix1" and "Bugfix2" in issues list' do
expect(page).not_to have_content "Bugfix2"
expect(page).not_to have_content "Bugfix1"
end
it 'shows label "feature" in filtered-labels' do
expect(find('.filtered-labels')).to have_content "feature"
end
it 'does not show label "bug" and "enhancement" in filtered-labels' do
expect(find('.filtered-labels')).not_to have_content "bug"
expect(find('.filtered-labels')).not_to have_content "enhancement"
end
end
context 'filter by label enhancement', js: true do
context 'filter by label enhancement' do
before do
page.find('.js-label-select').click
wait_for_ajax
execute_script("$('.dropdown-menu-labels li:contains(\"enhancement\") a').click()")
page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
wait_for_ajax
select_labels('enhancement')
end
it 'shows issue "Bugfix2" in issues list' do
it 'applies the filter' do
expect(page).to have_content "Bugfix2"
end
it 'does not show "Feature1" and "Bugfix1" in issues list' do
expect(page).not_to have_content "Feature1"
expect(page).not_to have_content "Bugfix1"
end
it 'shows label "enhancement" in filtered-labels' do
expect(find('.filtered-labels')).to have_content "enhancement"
end
it 'does not show label "feature" and "bug" in filtered-labels' do
expect(find('.filtered-labels')).not_to have_content "bug"
expect(find('.filtered-labels')).not_to have_content "feature"
end
end
context 'filter by label enhancement or feature', js: true do
context 'filter by label enhancement and bug in issues list' do
before do
page.find('.js-label-select').click
wait_for_ajax
execute_script("$('.dropdown-menu-labels li:contains(\"enhancement\") a').click()")
execute_script("$('.dropdown-menu-labels li:contains(\"feature\") a').click()")
page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
wait_for_ajax
select_labels('bug', 'enhancement')
end
it 'does not show "Bugfix1" or "Feature1" in issues list' do
expect(page).not_to have_content "Bugfix1"
expect(page).not_to have_content "Feature1"
end
it 'shows label "enhancement" and "feature" in filtered-labels' do
expect(find('.filtered-labels')).to have_content "enhancement"
expect(find('.filtered-labels')).to have_content "feature"
end
it 'does not show label "bug" in filtered-labels' do
expect(find('.filtered-labels')).not_to have_content "bug"
end
it 'removes label "enhancement"' do
find('.js-label-filter-remove', match: :first).click
wait_for_ajax
expect(find('.filtered-labels')).to have_no_content "enhancement"
end
end
context 'filter by label enhancement and bug in issues list', js: true do
before do
page.find('.js-label-select').click
wait_for_ajax
execute_script("$('.dropdown-menu-labels li:contains(\"enhancement\") a').click()")
execute_script("$('.dropdown-menu-labels li:contains(\"bug\") a').click()")
page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
wait_for_ajax
end
it 'shows issue "Bugfix2" in issues list' do
it 'applies the filters' do
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
expect(page).to have_content "Bugfix2"
end
it 'does not show "Feature1"' do
expect(page).not_to have_content "Feature1"
end
it 'shows label "bug" and "enhancement" in filtered-labels' do
expect(find('.filtered-labels')).to have_content "bug"
expect(find('.filtered-labels')).to have_content "enhancement"
end
expect(find('.filtered-labels')).not_to have_content "feature"
it 'does not show label "feature" in filtered-labels' do
find('.js-label-filter-remove', match: :first).click
wait_for_ajax
expect(page).to have_content "Bugfix2"
expect(page).not_to have_content "Feature1"
expect(page).not_to have_content "Bugfix1"
expect(find('.filtered-labels')).not_to have_content "bug"
expect(find('.filtered-labels')).to have_content "enhancement"
expect(find('.filtered-labels')).not_to have_content "feature"
end
end
context 'remove filtered labels', js: true do
context 'remove filtered labels' do
before do
page.within '.labels-filter' do
click_button 'Label'
@ -200,7 +129,7 @@ feature 'Issue filtering by Labels', feature: true do
end
end
context 'dropdown filtering', js: true do
context 'dropdown filtering' do
it 'filters by label name' do
page.within '.labels-filter' do
click_button 'Label'
@ -214,4 +143,14 @@ feature 'Issue filtering by Labels', feature: true do
end
end
end
def select_labels(*labels)
page.find('.js-label-select').click
wait_for_ajax
labels.each do |label|
execute_script("$('.dropdown-menu-labels li:contains(\"#{label}\") a').click()")
end
page.first('.labels-filter .dropdown-title .dropdown-menu-close-icon').click
wait_for_ajax
end
end

View File

@ -7,15 +7,15 @@ describe 'Filter issues', feature: true do
let!(:user) { create(:user)}
let!(:milestone) { create(:milestone, project: project) }
let!(:label) { create(:label, project: project) }
let!(:issue1) { create(:issue, project: project) }
let!(:wontfix) { create(:label, project: project, title: "Won't fix") }
before do
project.team << [user, :master]
login_as(user)
create(:issue, project: project)
end
describe 'Filter issues for assignee from issues#index' do
describe 'for assignee from issues#index' do
before do
visit namespace_project_issues_path(project.namespace, project)
@ -45,7 +45,7 @@ describe 'Filter issues', feature: true do
end
end
describe 'Filter issues for milestone from issues#index' do
describe 'for milestone from issues#index' do
before do
visit namespace_project_issues_path(project.namespace, project)
@ -75,7 +75,7 @@ describe 'Filter issues', feature: true do
end
end
describe 'Filter issues for label from issues#index', js: true do
describe 'for label from issues#index', js: true do
before do
visit namespace_project_issues_path(project.namespace, project)
find('.js-label-select').click
@ -115,6 +115,7 @@ describe 'Filter issues', feature: true do
expect(page).to have_content wontfix.title
click_link wontfix.title
end
expect(find('.js-label-select .dropdown-toggle-text')).to have_content(wontfix.title)
end
@ -146,7 +147,7 @@ describe 'Filter issues', feature: true do
end
end
describe 'Filter issues for assignee and label from issues#index' do
describe 'for assignee and label from issues#index' do
before do
visit namespace_project_issues_path(project.namespace, project)
@ -226,6 +227,11 @@ describe 'Filter issues', feature: true do
it 'filters by text and label' do
fill_in 'issuable_search', with: 'Bug'
page.within '.issues-state-filters' do
expect(page).to have_content('Open 2')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 2')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 2)
end
@ -236,6 +242,11 @@ describe 'Filter issues', feature: true do
end
find('.dropdown-menu-close-icon').click
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 1)
end
@ -244,6 +255,11 @@ describe 'Filter issues', feature: true do
it 'filters by text and milestone' do
fill_in 'issuable_search', with: 'Bug'
page.within '.issues-state-filters' do
expect(page).to have_content('Open 2')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 2')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 2)
end
@ -253,6 +269,11 @@ describe 'Filter issues', feature: true do
click_link '8'
end
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 1)
end
@ -261,6 +282,11 @@ describe 'Filter issues', feature: true do
it 'filters by text and assignee' do
fill_in 'issuable_search', with: 'Bug'
page.within '.issues-state-filters' do
expect(page).to have_content('Open 2')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 2')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 2)
end
@ -270,6 +296,11 @@ describe 'Filter issues', feature: true do
click_link user.name
end
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 1)
end
@ -278,6 +309,11 @@ describe 'Filter issues', feature: true do
it 'filters by text and author' do
fill_in 'issuable_search', with: 'Bug'
page.within '.issues-state-filters' do
expect(page).to have_content('Open 2')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 2')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 2)
end
@ -287,6 +323,11 @@ describe 'Filter issues', feature: true do
click_link user.name
end
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 1)
end
@ -315,6 +356,11 @@ describe 'Filter issues', feature: true do
find('.dropdown-menu-close-icon').click
wait_for_ajax
page.within '.issues-state-filters' do
expect(page).to have_content('Open 2')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 2')
end
page.within '.issues-list' do
expect(page).to have_selector('.issue', count: 2)
end

View File

@ -17,6 +17,11 @@ feature 'Merge Request filtering by Milestone', feature: true do
visit_merge_requests(project)
filter_by_milestone(Milestone::None.title)
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
expect(page).to have_css('.merge-request', count: 1)
end
@ -39,6 +44,11 @@ feature 'Merge Request filtering by Milestone', feature: true do
visit_merge_requests(project)
filter_by_milestone(Milestone::Upcoming.title)
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
expect(page).to have_css('.merge-request', count: 1)
end
@ -61,6 +71,11 @@ feature 'Merge Request filtering by Milestone', feature: true do
visit_merge_requests(project)
filter_by_milestone(milestone.title)
page.within '.issues-state-filters' do
expect(page).to have_content('Open 1')
expect(page).to have_content('Closed 0')
expect(page).to have_content('All 1')
end
expect(page).to have_css('.merge-request', count: 1)
end