BigW Consortium Gitlab

Commit b3e3e75b by Sean McGivern Committed by Robert Speicher

Merge branch 'issue_37143_2' into 'master'

Remove unnecessary query from labels dropdown Closes #37143 See merge request gitlab-org/gitlab-ce!16520
parent 722d8906
...@@ -71,7 +71,7 @@ class LabelsFinder < UnionFinder ...@@ -71,7 +71,7 @@ class LabelsFinder < UnionFinder
end end
def projects? def projects?
params[:project_ids].present? params[:project_ids]
end end
def only_group_labels? def only_group_labels?
......
...@@ -304,6 +304,12 @@ module IssuablesHelper ...@@ -304,6 +304,12 @@ module IssuablesHelper
issuable.model_name.human.downcase issuable.model_name.human.downcase
end end
def selected_labels
Array(params[:label_name]).map do |label_name|
Label.new(title: label_name)
end
end
private private
def sidebar_gutter_collapsed? def sidebar_gutter_collapsed?
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
= render "shared/issuable/milestone_dropdown", selected: finder.milestones.try(:first), name: :milestone_title, show_any: true, show_upcoming: true, show_started: true = render "shared/issuable/milestone_dropdown", selected: finder.milestones.try(:first), name: :milestone_title, show_any: true, show_upcoming: true, show_started: true
.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: selected_labels, use_id: false, selected_toggle: params[:label_name], data_options: { field_name: "label_name[]" }
- if issuable_filter_present? - if issuable_filter_present?
.filter-item.inline.reset-filters .filter-item.inline.reset-filters
......
---
title: Remove unecessary query from labels filter
merge_request:
author:
type: performance
...@@ -192,4 +192,33 @@ describe IssuablesHelper do ...@@ -192,4 +192,33 @@ describe IssuablesHelper do
expect(JSON.parse(helper.issuable_initial_data(issue))).to eq(expected_data) expect(JSON.parse(helper.issuable_initial_data(issue))).to eq(expected_data)
end end
end end
describe '#selected_labels' do
context 'if label_name param is a string' do
it 'returns a new label with title' do
allow(helper).to receive(:params)
.and_return(ActionController::Parameters.new(label_name: 'test label'))
labels = helper.selected_labels
expect(labels).to be_an(Array)
expect(labels.size).to eq(1)
expect(labels.first.title).to eq('test label')
end
end
context 'if label_name param is an array' do
it 'returns a new label with title for each element' do
allow(helper).to receive(:params)
.and_return(ActionController::Parameters.new(label_name: ['test label 1', 'test label 2']))
labels = helper.selected_labels
expect(labels).to be_an(Array)
expect(labels.size).to eq(2)
expect(labels.first.title).to eq('test label 1')
expect(labels.second.title).to eq('test label 2')
end
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