Commit 0ce7c1e4 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'label-tooltip' into 'master'

Add label description in tooltip to labels in issue index and sidebar

The tooltip can get quite big, but it’s so useful to inform people about what these labels mean
new

![Screen_Shot_2016-03-08_at_11.48.28](/uploads/894baaaa1f789c3a2069a924d541e64b/Screen_Shot_2016-03-08_at_11.48.28.png)

![Screen_Shot_2016-03-08_at_11.48.20](/uploads/efe4fa0960054c4071b8f6bf83024403/Screen_Shot_2016-03-08_at_11.48.20.png)

@JobV writes on Slack:
> yeah I think it’s better than not, but I’d have to try it 😃 
> 
> cautious yes, revert if it’s annoying 😉

See merge request !3124
parents cb124d14 9d15814e
...@@ -20,6 +20,7 @@ v 8.6.0 (unreleased) ...@@ -20,6 +20,7 @@ v 8.6.0 (unreleased)
- Memoize @group in Admin::GroupsController (Yatish Mehta) - Memoize @group in Admin::GroupsController (Yatish Mehta)
- Indicate how much an MR diverged from the target branch (Pierre de La Morinerie) - Indicate how much an MR diverged from the target branch (Pierre de La Morinerie)
- Added omniauth-auth0 Gem (Daniel Carraro) - Added omniauth-auth0 Gem (Daniel Carraro)
- Add label description in tooltip to labels in issue index and sidebar
- Strip leading and trailing spaces in URL validator (evuez) - Strip leading and trailing spaces in URL validator (evuez)
- Add "last_sign_in_at" and "confirmed_at" to GET /users/* API endpoints for admins (evuez) - Add "last_sign_in_at" and "confirmed_at" to GET /users/* API endpoints for admins (evuez)
- Return empty array instead of 404 when commit has no statuses in commit status API - Return empty array instead of 404 when commit has no statuses in commit status API
......
...@@ -32,7 +32,7 @@ module LabelsHelper ...@@ -32,7 +32,7 @@ module LabelsHelper
# link_to_label(label) { "My Custom Label Text" } # link_to_label(label) { "My Custom Label Text" }
# #
# Returns a String # Returns a String
def link_to_label(label, project: nil, type: :issue, &block) def link_to_label(label, project: nil, type: :issue, tooltip: true, &block)
project ||= @project || label.project project ||= @project || label.project
link = send("namespace_project_#{type.to_s.pluralize}_path", link = send("namespace_project_#{type.to_s.pluralize}_path",
project.namespace, project.namespace,
...@@ -42,7 +42,7 @@ module LabelsHelper ...@@ -42,7 +42,7 @@ module LabelsHelper
if block_given? if block_given?
link_to link, &block link_to link, &block
else else
link_to render_colored_label(label), link link_to render_colored_label(label, tooltip: tooltip), link
end end
end end
...@@ -50,23 +50,24 @@ module LabelsHelper ...@@ -50,23 +50,24 @@ module LabelsHelper
@project.labels.pluck(:title) @project.labels.pluck(:title)
end end
def render_colored_label(label, label_suffix = '') def render_colored_label(label, label_suffix = '', tooltip: true)
label_color = label.color || Label::DEFAULT_COLOR label_color = label.color || Label::DEFAULT_COLOR
text_color = text_color_for_bg(label_color) text_color = text_color_for_bg(label_color)
# Intentionally not using content_tag here so that this method can be called # Intentionally not using content_tag here so that this method can be called
# by LabelReferenceFilter # by LabelReferenceFilter
span = %(<span class="label color-label") + span = %(<span class="label color-label #{"has_tooltip" if tooltip}" ) +
%(style="background-color: #{label_color}; color: #{text_color}">) + %(style="background-color: #{label_color}; color: #{text_color}" ) +
%(title="#{escape_once(label.description)}" data-container="body">) +
%(#{escape_once(label.name)}#{label_suffix}</span>) %(#{escape_once(label.name)}#{label_suffix}</span>)
span.html_safe span.html_safe
end end
def render_colored_cross_project_label(label) def render_colored_cross_project_label(label, tooltip: true)
label_suffix = label.project.name_with_namespace label_suffix = label.project.name_with_namespace
label_suffix = " <i>in #{escape_once(label_suffix)}</i>" label_suffix = " <i>in #{escape_once(label_suffix)}</i>"
render_colored_label(label, label_suffix) render_colored_label(label, label_suffix, tooltip: tooltip)
end end
def suggested_colors def suggested_colors
......
%li{id: dom_id(label)} %li{id: dom_id(label)}
.label-row .label-row
= render_colored_label(label) = render_colored_label(label, tooltip: false)
= markdown(label.description, pipeline: :single_line) = markdown(label.description, pipeline: :single_line)
.pull-right .pull-right
= link_to 'Edit', edit_admin_label_path(label), class: 'btn btn-sm' = link_to 'Edit', edit_admin_label_path(label), class: 'btn btn-sm'
......
%span.label-row %span.label-row
= link_to_label(label) = link_to_label(label, tooltip: false)
%span.prepend-left-10 %span.prepend-left-10
= markdown(label.description, pipeline: :single_line) = markdown(label.description, pipeline: :single_line)
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
%li %li
%span.label-row %span.label-row
= link_to milestones_label_path(options) do = link_to milestones_label_path(options) do
- render_colored_label(label) - render_colored_label(label, tooltip: false)
%span.prepend-left-10 %span.prepend-left-10
= markdown(label.description, pipeline: :single_line) = markdown(label.description, pipeline: :single_line)
......
...@@ -11,7 +11,7 @@ describe LabelsHelper do ...@@ -11,7 +11,7 @@ describe LabelsHelper do
end end
it 'uses the instance variable' do it 'uses the instance variable' do
expect(link_to_label(label)).to match %r{<a href="/#{@project.to_reference}/issues\?label_name=#{label.name}">.*</a>} expect(link_to_label(label)).to match %r{<a href="/#{@project.to_reference}/issues\?label_name=#{label.name}"><span class="[\w\s\-]*has_tooltip".*</span></a>}
end end
end end
...@@ -39,6 +39,14 @@ describe LabelsHelper do ...@@ -39,6 +39,14 @@ describe LabelsHelper do
end end
end end
context 'with a tooltip argument' do
context 'set to false' do
it 'does not include the has_tooltip class' do
expect(link_to_label(label, tooltip: false)).not_to match %r{has_tooltip}
end
end
end
context 'with block' do context 'with block' do
it 'passes the block to link_to' do it 'passes the block to link_to' do
link = link_to_label(label) { 'Foo' } link = link_to_label(label) { 'Foo' }
...@@ -49,7 +57,7 @@ describe LabelsHelper do ...@@ -49,7 +57,7 @@ describe LabelsHelper do
context 'without block' do context 'without block' do
it 'uses render_colored_label as the link content' do it 'uses render_colored_label as the link content' do
expect(self).to receive(:render_colored_label). expect(self).to receive(:render_colored_label).
with(label).and_return('Foo') with(label, tooltip: true).and_return('Foo')
expect(link_to_label(label)).to match('Foo') expect(link_to_label(label)).to match('Foo')
end end
end end
......
...@@ -56,7 +56,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do ...@@ -56,7 +56,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
describe 'label span element' do describe 'label span element' do
it 'includes default classes' do it 'includes default classes' do
doc = reference_filter("Label #{reference}") doc = reference_filter("Label #{reference}")
expect(doc.css('a span').first.attr('class')).to eq 'label color-label' expect(doc.css('a span').first.attr('class')).to eq 'label color-label has_tooltip'
end end
it 'includes a style attribute' do it 'includes a style attribute' do
......
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