From 05ba1c97503ee44a143de5cea06f1dbbb15a65b8 Mon Sep 17 00:00:00 2001
From: crash <chris@enderacorp.com>
Date: Thu, 20 Jul 2023 18:23:24 +0000
Subject: [PATCH] Tooltip for long labels on Labels list

Changelog: fixed
---
 app/helpers/labels_helper.rb                   |  8 ++++----
 app/views/shared/_label_row.html.haml          |  2 +-
 ee/app/helpers/ee/labels_helper.rb             |  2 +-
 spec/helpers/labels_helper_spec.rb             | 15 ++++++++++++---
 spec/views/shared/_label_row.html.haml_spec.rb | 16 ++++++++--------
 5 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index c4967a42a451e..79bab0969d1c8 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -46,11 +46,11 @@ def link_to_label(label, type: :issue, tooltip: true, small: false, css_class: n
     end
   end
 
-  def render_label(label, link: nil, tooltip: true, dataset: nil, small: false)
+  def render_label(label, link: nil, tooltip: true, dataset: nil, small: false, tooltip_shows_title: false)
     html = render_colored_label(label)
 
     if link
-      title = label_tooltip_title(label) if tooltip
+      title = label_tooltip_title(label, tooltip_shows_title: tooltip_shows_title) if tooltip
       html = render_label_link(html, link: link, title: title, dataset: dataset)
     end
 
@@ -74,8 +74,8 @@ def wrap_label_html(label_html, small:, label:)
     %(<span class="#{wrapper_classes.join(' ')}">#{label_html}</span>).html_safe
   end
 
-  def label_tooltip_title(label)
-    Sanitize.clean(label.description)
+  def label_tooltip_title(label, tooltip_shows_title: false)
+    Sanitize.clean(tooltip_shows_title ? label.title : label.description)
   end
 
   def suggested_colors
diff --git a/app/views/shared/_label_row.html.haml b/app/views/shared/_label_row.html.haml
index 19489981d9491..5058455dcd790 100644
--- a/app/views/shared/_label_row.html.haml
+++ b/app/views/shared/_label_row.html.haml
@@ -4,7 +4,7 @@
 - show_label_merge_requests_link = subject_or_group_defined && show_label_issuables_link?(label, :merge_requests)
 
 .label-name.gl-flex-shrink-0.gl-mr-5
-  = render_label(label, tooltip: false)
+  = render_label(label, link: '#', tooltip: true, tooltip_shows_title: true)
   - if show_labels_full_path?(@project, @group)
     .gl-mt-2
       = render 'shared/label_full_path', label: label
diff --git a/ee/app/helpers/ee/labels_helper.rb b/ee/app/helpers/ee/labels_helper.rb
index f60da732f515a..a9e0d1da0f25b 100644
--- a/ee/app/helpers/ee/labels_helper.rb
+++ b/ee/app/helpers/ee/labels_helper.rb
@@ -33,7 +33,7 @@ def wrap_label_html(label_html, small:, label:)
       %(<span class="#{wrapper_classes.join(' ')}" style="--label-inset-border: inset 0 0 0 #{border_width} #{html_escape(label.color)}; color: #{html_escape(label.color)}">#{label_html}</span>).html_safe
     end
 
-    def label_tooltip_title(label)
+    def label_tooltip_title(label, tooltip_shows_title: false)
       tooltip = super
       tooltip = %(<span class='font-weight-bold scoped-label-tooltip-title'>Scoped label</span><br>#{tooltip}) if label.scoped_label?
 
diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb
index b45496308133a..4877ab1ff0338 100644
--- a/spec/helpers/labels_helper_spec.rb
+++ b/spec/helpers/labels_helper_spec.rb
@@ -275,9 +275,18 @@
     let(:html) { '<img src="example.png">This is an image</img>' }
     let(:label_with_html_content) { create(:label, title: 'test', description: html) }
 
-    it 'removes HTML' do
-      tooltip = label_tooltip_title(label_with_html_content)
-      expect(tooltip).to eq('This is an image')
+    context 'tooltip shows description' do
+      it 'removes HTML' do
+        tooltip = label_tooltip_title(label_with_html_content)
+        expect(tooltip).to eq('This is an image')
+      end
+    end
+
+    context 'tooltip shows title' do
+      it 'shows title' do
+        tooltip = label_tooltip_title(label_with_html_content, tooltip_shows_title: true)
+        expect(tooltip).to eq('test')
+      end
     end
   end
 
diff --git a/spec/views/shared/_label_row.html.haml_spec.rb b/spec/views/shared/_label_row.html.haml_spec.rb
index eb277930c1d27..ef5a479d736fc 100644
--- a/spec/views/shared/_label_row.html.haml_spec.rb
+++ b/spec/views/shared/_label_row.html.haml_spec.rb
@@ -25,8 +25,8 @@
       expect(rendered).to have_text(label.title)
     end
 
-    it 'has a non-linked label title' do
-      expect(rendered).not_to have_link(label.title)
+    it 'has a linked label title' do
+      expect(rendered).to have_link(label.title)
     end
 
     it 'has Issues link' do
@@ -57,8 +57,8 @@
       expect(rendered).to have_text(label.title)
     end
 
-    it 'has a non-linked label title' do
-      expect(rendered).not_to have_link(label.title)
+    it 'has a linked label title' do
+      expect(rendered).to have_link(label.title)
     end
 
     it 'has Issues link' do
@@ -85,8 +85,8 @@
       expect(rendered).to have_text(label.title)
     end
 
-    it 'has a non-linked label title' do
-      expect(rendered).not_to have_link(label.title)
+    it 'has a linked label title' do
+      expect(rendered).to have_link(label.title)
     end
 
     it 'has Issues link' do
@@ -111,8 +111,8 @@
       expect(rendered).to have_text(label.title)
     end
 
-    it 'has a non-linked label title' do
-      expect(rendered).not_to have_link(label.title)
+    it 'has a linked label title' do
+      expect(rendered).to have_link(label.title)
     end
 
     it 'does not show Issues link' do
-- 
GitLab