Commit 333e83a2 authored by Robert Speicher's avatar Robert Speicher

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
parents 13c00398 a4e41107
...@@ -143,6 +143,20 @@ module IssuablesHelper ...@@ -143,6 +143,20 @@ module IssuablesHelper
end end
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 private
def assigned_issuables_count(assignee, issuable_type, state) def assigned_issuables_count(assignee, issuable_type, state)
...@@ -165,10 +179,6 @@ module IssuablesHelper ...@@ -165,10 +179,6 @@ module IssuablesHelper
end end
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) def issuables_count_for_state(issuable_type, state)
issuables_finder = public_send("#{issuable_type}_finder") issuables_finder = public_send("#{issuable_type}_finder")
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
.filter-item.inline.labels-filter .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[]" } = 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 .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 .pull-right
- if boards_page - if boards_page
......
---
title: Refactor issuable_filters_present to reduce duplications
merge_request: 7776
author: Semyon Pupkov
...@@ -114,4 +114,25 @@ describe IssuablesHelper do ...@@ -114,4 +114,25 @@ describe IssuablesHelper do
end end
end 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 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