From ba5de9eb725a925091c895283f82f0521e993b4c Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 29 May 2018 17:58:57 -0300 Subject: Show prioritized labels for guest users --- app/assets/javascripts/init_labels.js | 1 + app/helpers/labels_helper.rb | 7 +++++++ app/views/projects/labels/index.html.haml | 24 ++++++++++------------ changelogs/unreleased/issue_38104.yml | 5 +++++ .../projects/labels/user_views_labels_spec.rb | 12 ++++++++++- 5 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 changelogs/unreleased/issue_38104.yml diff --git a/app/assets/javascripts/init_labels.js b/app/assets/javascripts/init_labels.js index 15da5d5cceb..d955b8cab10 100644 --- a/app/assets/javascripts/init_labels.js +++ b/app/assets/javascripts/init_labels.js @@ -4,6 +4,7 @@ import GroupLabelSubscription from './group_label_subscription'; import ProjectLabelSubscription from './project_label_subscription'; export default () => { + debugger if ($('.prioritized-labels').length) { new LabelManager(); // eslint-disable-line no-new } diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index c4a6a1e4bb3..cd926ad5ce1 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -211,6 +211,13 @@ module LabelsHelper end end + def labels_list_class(can_admin_label, sortable = false) + list_classes = "manage-labels-list" + list_classes += " js-prioritized-labels" if can_admin_label && sortable + + list_classes + end + # Required for Banzai::Filter::LabelReferenceFilter module_function :render_colored_label, :text_color_for_bg, :escape_once end diff --git a/app/views/projects/labels/index.html.haml b/app/views/projects/labels/index.html.haml index 9c78bade254..0988667aaaf 100644 --- a/app/views/projects/labels/index.html.haml +++ b/app/views/projects/labels/index.html.haml @@ -18,22 +18,20 @@ New label .labels - - if can_admin_label - -# Only show it in the first page - - hide = @available_labels.empty? || (params[:page].present? && params[:page] != '1') - .prioritized-labels{ class: ('hide' if hide) } - %h5 Prioritized Labels - %ul.content-list.manage-labels-list.js-prioritized-labels{ "data-url" => set_priorities_project_labels_path(@project) } - #js-priority-labels-empty-state{ class: "#{'hidden' unless @prioritized_labels.empty?}" } - = render 'shared/empty_states/priority_labels' - - if @prioritized_labels.present? - = render partial: 'shared/label', subject: @project, collection: @prioritized_labels, as: :label + -# Only show it in the first page + - hide = @available_labels.empty? || (params[:page].present? && params[:page] != '1') + .prioritized-labels{ class: ('hide' if hide) } + %h5 Prioritized Labels + %ul.content-list{ class: labels_list_class(can_admin_label, true), "data-url": set_priorities_project_labels_path(@project) } + #js-priority-labels-empty-state{ class: "#{'hidden' unless @prioritized_labels.empty?}" } + = render 'shared/empty_states/priority_labels' + - if @prioritized_labels.present? + = render partial: 'shared/label', subject: @project, collection: @prioritized_labels, as: :label - if @labels.present? .other-labels - - if can_admin_label - %h5{ class: ('hide' if hide) } Other Labels - %ul.content-list.manage-labels-list.js-other-labels + %h5{ class: ('hide' if hide) } Other Labels + %ul.content-list.js-other-labels{ class: labels_list_class(can_admin_label) } = render partial: 'shared/label', subject: @project, collection: @labels, as: :label = paginate @labels, theme: 'gitlab' - else diff --git a/changelogs/unreleased/issue_38104.yml b/changelogs/unreleased/issue_38104.yml new file mode 100644 index 00000000000..a7d10176f04 --- /dev/null +++ b/changelogs/unreleased/issue_38104.yml @@ -0,0 +1,5 @@ +--- +title: Show prioritized labels for guest users +merge_request: +author: +type: fixed diff --git a/spec/features/projects/labels/user_views_labels_spec.rb b/spec/features/projects/labels/user_views_labels_spec.rb index 0cbeca4e392..36922b3f5ab 100644 --- a/spec/features/projects/labels/user_views_labels_spec.rb +++ b/spec/features/projects/labels/user_views_labels_spec.rb @@ -5,9 +5,11 @@ describe "User views labels" do set(:user) { create(:user) } LABEL_TITLES = %w[bug enhancement feature].freeze + PRIORITIZED_LABELS_TITLES = %w[p1 p2 p3].freeze before do LABEL_TITLES.each { |title| create(:label, project: project, title: title) } + PRIORITIZED_LABELS_TITLES.each { |title| create(:label, project: project, title: title, priority: rand(3)) } project.add_guest(user) sign_in(user) @@ -15,9 +17,17 @@ describe "User views labels" do visit(project_labels_path(project)) end - it "shows all labels" do + it "shows all labels without priority" do page.within('.other-labels .manage-labels-list') do LABEL_TITLES.each { |title| expect(page).to have_content(title) } end end + + it "shows all prioritized labels" do + expect(page).not_to have_selector('.js-prioritized-labels') + + page.within('.prioritized-labels .manage-labels-list') do + PRIORITIZED_LABELS_TITLES.each { |title| expect(page).to have_content(title) } + end + end end -- cgit v1.2.1