Commit de69f0ca authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '241990-show-full-path-where-labels-come-from' into 'master'

Show labels origin path on project labels page

See merge request gitlab-org/gitlab!43858
parents 016e6c98 ac6ec268
...@@ -247,6 +247,7 @@ ...@@ -247,6 +247,7 @@
.label-badge { .label-badge {
color: $gray-900; color: $gray-900;
display: inline-block;
font-weight: $gl-font-weight-normal; font-weight: $gl-font-weight-normal;
padding: $gl-padding-4 $gl-padding-8; padding: $gl-padding-4 $gl-padding-8;
border-radius: $border-radius-default; border-radius: $border-radius-default;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class LabelPresenter < Gitlab::View::Presenter::Delegated class LabelPresenter < Gitlab::View::Presenter::Delegated
presents :label presents :label
delegate :name, :full_name, to: :label_subject, prefix: :subject
def edit_path def edit_path
case label case label
...@@ -39,8 +40,8 @@ class LabelPresenter < Gitlab::View::Presenter::Delegated ...@@ -39,8 +40,8 @@ class LabelPresenter < Gitlab::View::Presenter::Delegated
label.is_a?(ProjectLabel) label.is_a?(ProjectLabel)
end end
def subject_name def label_subject
label.subject.name @label_subject ||= label.subject
end end
private private
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
%li.label-list-item{ id: label_css_id, data: { id: label.id } } %li.label-list-item{ id: label_css_id, data: { id: label.id } }
= render "shared/label_row", label: label, force_priority: force_priority = render "shared/label_row", label: label, force_priority: force_priority
%ul.label-actions-list %ul.label-actions-list
- if @project
%li.inline
.label-badge.gl-bg-gray-50= label.model_name.human.capitalize
- if can?(current_user, :admin_label, @project) - if can?(current_user, :admin_label, @project)
%li.inline.js-toggle-priority{ data: { url: remove_priority_project_label_path(@project, label), %li.inline.js-toggle-priority{ data: { url: remove_priority_project_label_path(@project, label),
dom_id: dom_id(label), type: label.type } } dom_id: dom_id(label), type: label.type } }
......
- full_path = label.subject_full_name
.label-badge.gl-bg-gray-50.gl-max-w-full.gl-text-truncate{ title: full_path }
= full_path
...@@ -3,22 +3,28 @@ ...@@ -3,22 +3,28 @@
- show_label_issues_link = subject_or_group_defined && show_label_issuables_link?(label, :issues) - show_label_issues_link = subject_or_group_defined && show_label_issuables_link?(label, :issues)
- show_label_merge_requests_link = subject_or_group_defined && show_label_issuables_link?(label, :merge_requests) - show_label_merge_requests_link = subject_or_group_defined && show_label_issuables_link?(label, :merge_requests)
.label-name.gl-flex-shrink-0.gl-mr-3 .label-name.gl-flex-shrink-0.gl-mt-2.gl-mr-3
= render_label(label, tooltip: false) = render_label(label, tooltip: false)
.label-description.gl-flex-grow-1.gl-mr-3.gl-w-full .label-description.gl-flex-grow-1.gl-overflow-hidden
.gl-display-flex.gl-align-items-center.gl-flex-wrap.gl-mt-2
.description-text.gl-flex-grow-1.gl-overflow-hidden
- if label.description.present? - if label.description.present?
.description-text.gl-mb-3
= markdown_field(label, :description) = markdown_field(label, :description)
- elsif @project
= render 'shared/label_full_path', label: label
%ul.label-links.gl-m-0.gl-p-0.gl-white-space-nowrap %ul.label-links.gl-m-0.gl-p-0.gl-white-space-nowrap
- if show_label_issues_link - if show_label_issues_link
%li.inline.gl-text-blue-600 %li.inline
= link_to_label(label, css_class: 'gl-text-blue-600!') { _('Issues') } = link_to_label(label, css_class: 'gl-text-blue-600!') { _('Issues') }
- if show_label_merge_requests_link - if show_label_merge_requests_link
&middot; &middot;
%li.inline.gl-text-blue-600 %li.inline
= link_to_label(label, type: :merge_request, css_class: 'gl-text-blue-600!') { _('Merge requests') } = link_to_label(label, type: :merge_request, css_class: 'gl-text-blue-600!') { _('Merge requests') }
= render_if_exists 'shared/label_row_epics_link', label: label = render_if_exists 'shared/label_row_epics_link', label: label
- if force_priority - if force_priority
&middot; &middot;
%li.js-priority-badge.inline.gl-ml-3 %li.js-priority-badge.inline.gl-ml-3
.label-badge.gl-bg-blue-50= _('Prioritized label') .label-badge.gl-bg-blue-50= _('Prioritized label')
- if @project && label.description.present?
.gl-mt-3
= render 'shared/label_full_path', label: label
---
title: Show labels origin path on project labels page
merge_request: 43858
author:
type: added
...@@ -52,8 +52,9 @@ and edit labels. ...@@ -52,8 +52,9 @@ and edit labels.
View the project labels list by going to the project and clicking **Issues > Labels**. View the project labels list by going to the project and clicking **Issues > Labels**.
The list includes all labels that are defined at the project level, as well as all The list includes all labels that are defined at the project level, as well as all
labels inherited from the immediate parent group. You can filter the list by entering a search labels inherited from the immediate parent group.
query at the top and clicking search (**{search}**). For each label, you can see the project or group path from where it was created.
You can filter the list by entering a search query at the top and clicking search (**{search}**).
To create a new project label: To create a new project label:
......
...@@ -91,4 +91,18 @@ RSpec.describe LabelPresenter do ...@@ -91,4 +91,18 @@ RSpec.describe LabelPresenter do
it { is_expected.to eq(label.project.name) } it { is_expected.to eq(label.project.name) }
end end
end end
describe '#subject_full_name' do
context 'with group label' do
subject { group_label.subject_full_name }
it { is_expected.to eq(group_label.group.full_name) }
end
context 'with project label' do
subject { label.subject_full_name }
it { is_expected.to eq(label.project.full_name) }
end
end
end end
...@@ -2,43 +2,83 @@ ...@@ -2,43 +2,83 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'shared/_label_row.html.haml' do RSpec.describe 'shared/_label_row.html.haml' do
label_types = { let_it_be(:group) { create(:group) }
'project label': :label, let(:label) { build_stubbed(:group_label, group: group).present(issuable_subject: group) }
'group label': :group_label
}
label_types.each do |label_type, label_factory| before do
let!(:label) do allow(view).to receive(:label) { label }
label_record = create(label_factory) # rubocop: disable Rails/SaveBang
label_record.present(issuable_subject: label_record.subject)
end end
context "for a #{label_type}" do context 'with a project context' do
let_it_be(:project) { create(:project, group: group) }
let(:label) { build_stubbed(:label, project: project).present(issuable_subject: project) }
before do before do
if label.project_label? assign(:project, label.project)
@project = label.project
else render
@group = label.group
end
end end
it 'has a non-linked label title' do it 'has a non-linked label title' do
render 'shared/label_row', label: label
expect(rendered).not_to have_css('a', text: label.title) expect(rendered).not_to have_css('a', text: label.title)
end end
it "has Issues link for #{label_type}" do it "has Issues link" do
render 'shared/label_row', label: label
expect(rendered).to have_css('a', text: 'Issues') expect(rendered).to have_css('a', text: 'Issues')
end end
it "has Merge request link for #{label_type}" do it "has Merge request link" do
render 'shared/label_row', label: label expect(rendered).to have_css('a', text: 'Merge requests')
end
it "shows the path from where the label was created" do
expect(rendered).to have_css('.label-badge', text: project.full_name)
end
end
context 'with a group context' do
before do
assign(:group, label.group)
render
end
it 'has a non-linked label title' do
expect(rendered).not_to have_css('a', text: label.title)
end
it "has Issues link" do
expect(rendered).to have_css('a', text: 'Issues')
end
it "has Merge request link" do
expect(rendered).to have_css('a', text: 'Merge requests') expect(rendered).to have_css('a', text: 'Merge requests')
end end
it "does not show a path from where the label was created" do
expect(rendered).not_to have_css('.label-badge')
end
end
context 'with an admin context' do
before do
render
end
it 'has a non-linked label title' do
expect(rendered).not_to have_css('a', text: label.title)
end
it "does not show Issues link" do
expect(rendered).not_to have_css('a', text: 'Issues')
end
it "does not show Merge request link" do
expect(rendered).not_to have_css('a', text: 'Merge requests')
end
it "does not show a path from where the label was created" do
expect(rendered).not_to have_css('.label-badge')
end 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