From 400cc09f72eb4aca4900d154ab3c02594e870834 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 3 Sep 2018 19:00:28 +0300 Subject: [PATCH 1/2] Add search to group labels page [ci skip] Signed-off-by: Dmitriy Zaporozhets --- app/controllers/groups/labels_controller.rb | 6 +-- app/views/groups/labels/index.html.haml | 26 +++++++--- .../groups/labels/search_labels_spec.rb | 48 +++++++++++++++++++ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 spec/features/groups/labels/search_labels_spec.rb diff --git a/app/controllers/groups/labels_controller.rb b/app/controllers/groups/labels_controller.rb index 863f50e8e66..3e0076ac935 100644 --- a/app/controllers/groups/labels_controller.rb +++ b/app/controllers/groups/labels_controller.rb @@ -11,7 +11,7 @@ class Groups::LabelsController < Groups::ApplicationController def index respond_to do |format| format.html do - @labels = @group.labels.page(params[:page]) + @labels = @available_labels.page(params[:page]) end format.json do render json: LabelSerializer.new.represent_appearance(@available_labels) @@ -113,7 +113,7 @@ class Groups::LabelsController < Groups::ApplicationController group_id: @group.id, only_group_labels: params[:only_group_labels], include_ancestor_groups: params[:include_ancestor_groups], - include_descendant_groups: params[:include_descendant_groups] - ).execute + include_descendant_groups: params[:include_descendant_groups], + search: params[:search]).execute end end diff --git a/app/views/groups/labels/index.html.haml b/app/views/groups/labels/index.html.haml index e1e38a7e82f..d63ef477177 100644 --- a/app/views/groups/labels/index.html.haml +++ b/app/views/groups/labels/index.html.haml @@ -3,26 +3,38 @@ - can_admin_label = can?(current_user, :admin_label, @group) - hide = @available_labels.empty? || (params[:page].present? && params[:page] != '1') - issuables = ['issues', 'merge requests'] +- search = params[:search] - if can_admin_label - content_for(:header_content) do .nav-controls = link_to _('New label'), new_group_label_path(@group), class: "btn btn-new" -- if @labels.exists? +- if @labels.exists? || search.present? #promote-label-modal %div{ class: container_class } .top-area.adjust .nav-text = _('Labels can be applied to %{features}. Group labels are available for any project within the group.') % { features: issuables.to_sentence } + .nav-controls + = form_tag group_labels_path(@group), method: :get do + .input-group + = search_field_tag :search, params[:search], { placeholder: _('Filter'), id: 'label-search', class: 'form-control search-text-input input-short', spellcheck: false } + %span.input-group-append + %button.btn.btn-default{ type: "submit", "aria-label" => _('Submit search') } + = icon("search") .labels-container.prepend-top-5 - .other-labels - - if can_admin_label - %h5{ class: ('hide' if hide) } Labels - %ul.content-list.manage-labels-list.js-other-labels - = render partial: 'shared/label', subject: @group, collection: @labels, as: :label, locals: { use_label_priority: false } - = paginate @labels, theme: 'gitlab' + - if @labels.any? + .other-labels + - if can_admin_label + %h5{ class: ('hide' if hide) } Labels + %ul.content-list.manage-labels-list.js-other-labels + = render partial: 'shared/label', subject: @group, collection: @labels, as: :label, locals: { use_label_priority: false } + = paginate @labels, theme: 'gitlab' + - elsif search.present? + .nothing-here-block + = _('No labels with such name or description') - else = render 'shared/empty_states/labels' diff --git a/spec/features/groups/labels/search_labels_spec.rb b/spec/features/groups/labels/search_labels_spec.rb new file mode 100644 index 00000000000..14b88a561b1 --- /dev/null +++ b/spec/features/groups/labels/search_labels_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Search for labels', :js do + let(:user) { create(:user) } + let(:group) { create(:group) } + let!(:label1) { create(:group_label, title: 'Foo', description: 'Lorem ipsum', group: group) } + let!(:label2) { create(:group_label, title: 'Bar', description: 'Fusce consequat', group: group) } + + before do + group.add_maintainer(user) + sign_in(user) + + visit group_labels_path(group) + end + + it 'searches for label by title' do + fill_in 'label-search', with: 'Bar' + find('#label-search').native.send_keys(:enter) + + expect(page).to have_content(label2.title) + expect(page).to have_content(label2.description) + expect(page).not_to have_content(label1.title) + expect(page).not_to have_content(label1.description) + end + + it 'searches for label by description' do + fill_in 'label-search', with: 'Lorem' + find('#label-search').native.send_keys(:enter) + + expect(page).to have_content(label1.title) + expect(page).to have_content(label1.description) + expect(page).not_to have_content(label2.title) + expect(page).not_to have_content(label2.description) + end + + it 'shows nothing found message' do + fill_in 'label-search', with: 'nonexistent' + find('#label-search').native.send_keys(:enter) + + expect(page).to have_content('No labels with such name or description') + expect(page).not_to have_content(label1.title) + expect(page).not_to have_content(label1.description) + expect(page).not_to have_content(label2.title) + expect(page).not_to have_content(label2.description) + end +end From 329f7cbe9e605322985192b0fb6faa8de2222735 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 3 Sep 2018 19:03:04 +0300 Subject: [PATCH 2/2] Add changelog for group labels feature Signed-off-by: Dmitriy Zaporozhets --- changelogs/unreleased/dz-group-labels-search.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/dz-group-labels-search.yml diff --git a/changelogs/unreleased/dz-group-labels-search.yml b/changelogs/unreleased/dz-group-labels-search.yml new file mode 100644 index 00000000000..bb4719df22d --- /dev/null +++ b/changelogs/unreleased/dz-group-labels-search.yml @@ -0,0 +1,5 @@ +--- +title: Add search to a group labels page +merge_request: 21480 +author: +type: added