Commit 094be8f5 authored by Nathan Friend's avatar Nathan Friend

Add release links in milestone detail page sidebar

This commit adds a new section to the milestone detail page sidebar -
"Releases". This section renders links to any releases associated to the
milestone.
parent fd86f88d
...@@ -170,6 +170,14 @@ module MilestonesHelper ...@@ -170,6 +170,14 @@ module MilestonesHelper
content.join('<br />').html_safe content.join('<br />').html_safe
end end
def milestone_releases_tooltip_text(milestone)
count = milestone.releases.count
return _("Releases") if count.zero?
n_("%{releases} release", "%{releases} releases", count) % { releases: count }
end
def recent_releases_with_counts(milestone) def recent_releases_with_counts(milestone)
total_count = milestone.releases.size total_count = milestone.releases.size
return [[], 0, 0] if total_count == 0 return [[], 0, 0] if total_count == 0
......
...@@ -138,6 +138,27 @@ ...@@ -138,6 +138,27 @@
Merged: Merged:
= milestone.merge_requests.merged.count = milestone.merge_requests.merged.count
- if project
- recent_releases, total_count, more_count = recent_releases_with_counts(milestone)
.block.releases
.sidebar-collapsed-icon.has-tooltip{ title: milestone_releases_tooltip_text(milestone), data: { container: 'body', placement: 'left', boundary: 'viewport' } }
%strong
= icon('rocket')
%span= total_count
.title.hide-collapsed= n_('Release', 'Releases', total_count)
.hide-collapsed
- if total_count.zero?
.no-value= _('None')
- else
.font-weight-bold
- recent_releases.each do |release|
= link_to release.name, project_releases_path(project, :anchor => release.tag)
- unless release == recent_releases.last
%span.font-weight-normal &bull;
- if more_count > 0
%span.font-weight-normal &bull;
= link_to n_('%{count} more release', '%{count} more releases', more_count) % { count: more_count }, project_releases_path(project), class: 'font-weight-normal'
- milestone_ref = milestone.try(:to_reference, full: true) - milestone_ref = milestone.try(:to_reference, full: true)
- if milestone_ref.present? - if milestone_ref.present?
.block.reference .block.reference
......
---
title: Add links to associated release(s) to the milestone detail page
merge_request: 17278
author:
type: added
...@@ -324,6 +324,11 @@ msgstr "" ...@@ -324,6 +324,11 @@ msgstr ""
msgid "%{percent}%% complete" msgid "%{percent}%% complete"
msgstr "" msgstr ""
msgid "%{releases} release"
msgid_plural "%{releases} releases"
msgstr[0] ""
msgstr[1] ""
msgid "%{service_title} activated." msgid "%{service_title} activated."
msgstr "" msgstr ""
......
...@@ -7,6 +7,18 @@ describe 'Project milestone' do ...@@ -7,6 +7,18 @@ describe 'Project milestone' do
let(:project) { create(:project, name: 'test', namespace: user.namespace) } let(:project) { create(:project, name: 'test', namespace: user.namespace) }
let(:milestone) { create(:milestone, project: project) } let(:milestone) { create(:milestone, project: project) }
def toggle_sidebar
find('.milestone-sidebar .gutter-toggle').click
end
def sidebar_release_block
find('.milestone-sidebar .block.releases')
end
def sidebar_release_block_collapsed_icon
find('.milestone-sidebar .block.releases .sidebar-collapsed-icon')
end
before do before do
sign_in(user) sign_in(user)
end end
...@@ -75,17 +87,96 @@ describe 'Project milestone' do ...@@ -75,17 +87,96 @@ describe 'Project milestone' do
describe 'the collapsed sidebar' do describe 'the collapsed sidebar' do
before do before do
find('.milestone-sidebar .gutter-toggle').click toggle_sidebar
end end
it 'shows the total MR and issue counts' do it 'shows the total MR and issue counts' do
find('.milestone-sidebar .block', match: :first) find('.milestone-sidebar .block', match: :first)
aggregate_failures 'MR and issue blocks' do aggregate_failures 'MR and issue blocks' do
expect(find('.milestone-sidebar .block.issues')).to have_content 1 expect(find('.milestone-sidebar .block.issues')).to have_content '1'
expect(find('.milestone-sidebar .block.merge-requests')).to have_content 0 expect(find('.milestone-sidebar .block.merge-requests')).to have_content '0'
end end
end end
end end
end end
context 'when the milestone is not associated with a release' do
before do
visit project_milestone_path(project, milestone)
end
it 'shows "None" in the "Releases" section' do
expect(sidebar_release_block).to have_content 'Releases None'
end
describe 'when the sidebar is collapsed' do
before do
toggle_sidebar
end
it 'shows "0" in the "Releases" section' do
expect(sidebar_release_block).to have_content '0'
end
it 'has a tooltip that reads "Releases"' do
expect(sidebar_release_block_collapsed_icon['title']).to eq 'Releases'
end
end
end
context 'when the milestone is associated with one release' do
before do
create(:release, project: project, name: 'Version 5', milestones: [milestone])
visit project_milestone_path(project, milestone)
end
it 'shows "Version 5" in the "Release" section' do
expect(sidebar_release_block).to have_content 'Release Version 5'
end
describe 'when the sidebar is collapsed' do
before do
toggle_sidebar
end
it 'shows "1" in the "Releases" section' do
expect(sidebar_release_block).to have_content '1'
end
it 'has a tooltip that reads "1 release"' do
expect(sidebar_release_block_collapsed_icon['title']).to eq '1 release'
end
end
end
context 'when the milestone is associated with multiple releases' do
before do
(5..10).each do |num|
released_at = Time.zone.parse('2019-10-04') + num.months
create(:release, project: project, name: "Version #{num}", milestones: [milestone], released_at: released_at)
end
visit project_milestone_path(project, milestone)
end
it 'shows a shortened list of releases in the "Releases" section' do
expect(sidebar_release_block).to have_content 'Releases Version 10 • Version 9 • Version 8 • 3 more releases'
end
describe 'when the sidebar is collapsed' do
before do
toggle_sidebar
end
it 'shows "6" in the "Releases" section' do
expect(sidebar_release_block).to have_content '6'
end
it 'has a tooltip that reads "6 releases"' do
expect(sidebar_release_block_collapsed_icon['title']).to eq '6 releases'
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