diff options
author | Robert Speicher <robert@gitlab.com> | 2016-11-28 11:37:53 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-11-28 11:37:53 +0000 |
commit | 333e83a2ef29a0fce10b3e1b0110cd30685eea15 (patch) | |
tree | 9df60da3fbfb9c44b30756b90e9becb866b54a6c | |
parent | 13c0039891fb33a6f3cf88e9c62e1d493a5f75da (diff) | |
parent | a4e41107005c538e0d6be342a2ba626f25816d37 (diff) | |
download | gitlab-ce-333e83a2ef29a0fce10b3e1b0110cd30685eea15.tar.gz |
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
-rw-r--r-- | app/helpers/issuables_helper.rb | 20 | ||||
-rw-r--r-- | app/views/shared/issuable/_filter.html.haml | 4 | ||||
-rw-r--r-- | changelogs/unreleased/issuable_filters_present-refactor.yml | 4 | ||||
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 21 |
4 files changed, 42 insertions, 7 deletions
diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 8bebda07787..6584aa3edd5 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -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) diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml index b7e5e928993..e3503981afe 100644 --- a/app/views/shared/issuable/_filter.html.haml +++ b/app/views/shared/issuable/_filter.html.haml @@ -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 diff --git a/changelogs/unreleased/issuable_filters_present-refactor.yml b/changelogs/unreleased/issuable_filters_present-refactor.yml new file mode 100644 index 00000000000..c131f9cb68e --- /dev/null +++ b/changelogs/unreleased/issuable_filters_present-refactor.yml @@ -0,0 +1,4 @@ +--- +title: Refactor issuable_filters_present to reduce duplications +merge_request: 7776 +author: Semyon Pupkov diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb index 62cc10f579a..a4f08dc4af0 100644 --- a/spec/helpers/issuables_helper_spec.rb +++ b/spec/helpers/issuables_helper_spec.rb @@ -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 |