Merge branch 'issuable_filters_present-refactor' into 'master'

Refactor issuable_filters_present to reduce duplications

See https://gitlab.com/gitlab-org/gitlab-ce/issues/23546

See merge request !7776
This commit is contained in:
Robert Speicher 2016-11-28 11:37:53 +00:00
commit 333e83a2ef
4 changed files with 42 additions and 7 deletions

View file

@ -143,6 +143,20 @@ module IssuablesHelper
end
end
def issuable_filter_params
[
:search,
:author_id,
:assignee_id,
:milestone_title,
:label_name
]
end
def issuable_filter_present?
issuable_filter_params.any? { |k| params.key?(k) }
end
private
def assigned_issuables_count(assignee, issuable_type, state)
@ -165,13 +179,9 @@ module IssuablesHelper
end
end
def issuable_filters_present
params[:search] || params[:author_id] || params[:assignee_id] || params[:milestone_title] || params[:label_name]
end
def issuables_count_for_state(issuable_type, state)
issuables_finder = public_send("#{issuable_type}_finder")
params = issuables_finder.params.merge(state: state)
finder = issuables_finder.class.new(issuables_finder.current_user, params)

View file

@ -29,9 +29,9 @@
.filter-item.inline.labels-filter
= render "shared/issuable/label_dropdown", selected: finder.labels.select(:title).uniq, use_id: false, selected_toggle: params[:label_name], data_options: { field_name: "label_name[]" }
- if issuable_filters_present
- if issuable_filter_present?
.filter-item.inline.reset-filters
%a{href: page_filter_path(without: [:assignee_id, :author_id, :milestone_title, :label_name, :search])} Reset filters
%a{href: page_filter_path(without: issuable_filter_params)} Reset filters
.pull-right
- if boards_page

View file

@ -0,0 +1,4 @@
---
title: Refactor issuable_filters_present to reduce duplications
merge_request: 7776
author: Semyon Pupkov

View file

@ -114,4 +114,25 @@ describe IssuablesHelper do
end
end
end
describe '#issuable_filter_present?' do
it 'returns true when any key is present' do
allow(helper).to receive(:params).and_return(
ActionController::Parameters.new(milestone_title: 'Velit consectetur asperiores natus delectus.',
project_id: 'gitlabhq',
scope: 'all')
)
expect(helper.issuable_filter_present?).to be_truthy
end
it 'returns false when no key is present' do
allow(helper).to receive(:params).and_return(
ActionController::Parameters.new(project_id: 'gitlabhq',
scope: 'all')
)
expect(helper.issuable_filter_present?).to be_falsey
end
end
end