Commit 0a11d5e2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Sort labels alphabetically

Sorts labels alphabetically on issues (and merge requests) list.
Before it was order id desc.
Now it will be consistent with sidebar and labels page.
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent c8bf9f78
...@@ -227,6 +227,10 @@ module LabelsHelper ...@@ -227,6 +227,10 @@ module LabelsHelper
"#{action} at #{level} level" "#{action} at #{level} level"
end end
def labels_sorted_by_title(labels)
labels.sort_by(&:title)
end
# Required for Banzai::Filter::LabelReferenceFilter # Required for Banzai::Filter::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once module_function :render_colored_label, :text_color_for_bg, :escape_once
end end
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
= issue.due_date.to_s(:medium) = issue.due_date.to_s(:medium)
- if issue.labels.any? - if issue.labels.any?
&nbsp; &nbsp;
- issue.labels.each do |label| - labels_sorted_by_title(issue.labels).each do |label|
= link_to_label(label, subject: issue.project, css_class: 'label-link') = link_to_label(label, subject: issue.project, css_class: 'label-link')
.issuable-meta .issuable-meta
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
= merge_request.target_branch = merge_request.target_branch
- if merge_request.labels.any? - if merge_request.labels.any?
&nbsp; &nbsp;
- merge_request.labels.each do |label| - labels_sorted_by_title(merge_request.labels).each do |label|
= link_to_label(label, subject: merge_request.project, type: :merge_request, css_class: 'label-link') = link_to_label(label, subject: merge_request.project, type: :merge_request, css_class: 'label-link')
.issuable-meta .issuable-meta
......
---
title: Sort labels alphabetically on issues and merge requests list
merge_request: 25470
author:
type: changed
...@@ -28,6 +28,22 @@ describe 'issuable list' do ...@@ -28,6 +28,22 @@ describe 'issuable list' do
expect(first('.fa-thumbs-down').find(:xpath, '..')).to have_content(1) expect(first('.fa-thumbs-down').find(:xpath, '..')).to have_content(1)
expect(first('.fa-comments').find(:xpath, '..')).to have_content(2) expect(first('.fa-comments').find(:xpath, '..')).to have_content(2)
end end
it 'sorts labels alphabetically' do
label1 = create(:label, project: project, title: 'a')
label2 = create(:label, project: project, title: 'z')
label3 = create(:label, project: project, title: 'X')
label4 = create(:label, project: project, title: 'B')
issuable = create_issuable(issuable_type)
issuable.labels << [label1, label2, label3, label4]
visit_issuable_list(issuable_type)
expect(all('.label-link')[0].text).to have_content('B')
expect(all('.label-link')[1].text).to have_content('X')
expect(all('.label-link')[2].text).to have_content('a')
expect(all('.label-link')[3].text).to have_content('z')
end
end end
it "counts merge requests closing issues icons for each issue" do it "counts merge requests closing issues icons for each issue" do
...@@ -45,6 +61,14 @@ describe 'issuable list' do ...@@ -45,6 +61,14 @@ describe 'issuable list' do
end end
end end
def create_issuable(issuable_type)
if issuable_type == :issue
create(:issue, project: project)
else
create(:merge_request, source_project: project)
end
end
def create_issuables(issuable_type) def create_issuables(issuable_type)
3.times do |n| 3.times do |n|
issuable = issuable =
......
...@@ -236,4 +236,17 @@ describe LabelsHelper do ...@@ -236,4 +236,17 @@ describe LabelsHelper do
expect(labels_filter_path(format: :json)).to eq(dashboard_labels_path(format: :json)) expect(labels_filter_path(format: :json)).to eq(dashboard_labels_path(format: :json))
end end
end end
describe 'labels_sorted_by_title' do
it 'sorts labels alphabetically' do
label1 = double(:label, title: 'a')
label2 = double(:label, title: 'B')
label3 = double(:label, title: 'c')
label4 = double(:label, title: 'D')
labels = [label1, label2, label3, label4]
expect(labels_sorted_by_title(labels))
.to match_array([label2, label4, label1, label3])
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