Commit 38f343e8 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'issuable_filters_present-refactor-ee' into 'master'

Refactor issuable_filters_present to reduce duplications

Port of gitlab-org/gitlab-ce!7776

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

See merge request !921
parents cb9fe028 1ea1e75d
......@@ -152,6 +152,21 @@ module IssuablesHelper
end
end
def issuable_filter_params
[
:search,
:author_id,
:assignee_id,
:milestone_title,
:label_name,
:weight
]
end
def issuable_filter_present?
issuable_filter_params.any? { |k| params.key?(k) }
end
private
def assigned_issuables_count(assignee, issuable_type, state)
......@@ -174,13 +189,9 @@ module IssuablesHelper
end
end
def issuable_filters_present
params[:search] || params[:author_id] || params[:assignee_id] || params[:milestone_title] || params[:label_name] || params[:weight]
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)
......
......@@ -41,9 +41,9 @@
%a{href: "#", data: { id: weight }, class: ("is-active" if params[:weight] == weight.to_s)}
= weight
- 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, :weight, :search])} Reset filters
%a{href: page_filter_path(without: issuable_filter_params)} Reset filters
.pull-right
- if boards_page
......
......@@ -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
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