diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-05-10 17:34:10 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-05-10 17:34:10 +0300 |
commit | 9b03ed0a182c9ad96957085826cc85f8f229569c (patch) | |
tree | 8afeecefb87f8e0592d43df00a125e33227c1487 | |
parent | a24e8bfc68da79bcae3d05f353ad6ecd49cded0e (diff) | |
parent | d891e5f731562fd46948116a4cef30f61748f410 (diff) |
Merge branch 'search-restrict-projects-to-group' into 'master'
Filter projects by group on search page
Closes #29489
See merge request !11169
-rw-r--r-- | app/assets/javascripts/search.js | 34 | ||||
-rw-r--r-- | app/views/search/_filter.html.haml | 2 | ||||
-rw-r--r-- | changelogs/unreleased/search-restrict-projects-to-group.yml | 4 | ||||
-rw-r--r-- | spec/features/search_spec.rb | 19 |
4 files changed, 50 insertions, 9 deletions
diff --git a/app/assets/javascripts/search.js b/app/assets/javascripts/search.js index 15f5963353a..39e4006ac4e 100644 --- a/app/assets/javascripts/search.js +++ b/app/assets/javascripts/search.js @@ -1,4 +1,5 @@ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, object-shorthand, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-else-return, max-len */ +/* global Flash */ /* global Api */ (function() { @@ -7,6 +8,7 @@ var $groupDropdown, $projectDropdown; $groupDropdown = $('.js-search-group-dropdown'); $projectDropdown = $('.js-search-project-dropdown'); + this.groupId = $groupDropdown.data('group-id'); this.eventListeners(); $groupDropdown.glDropdown({ selectable: true, @@ -46,14 +48,18 @@ search: { fields: ['name'] }, - data: function(term, callback) { - return Api.projects(term, { order_by: 'id' }, function(data) { - data.unshift({ - name_with_namespace: 'Any' - }); - data.splice(1, 0, 'divider'); - return callback(data); - }); + data: (term, callback) => { + this.getProjectsData(term) + .then((data) => { + data.unshift({ + name_with_namespace: 'Any' + }); + data.splice(1, 0, 'divider'); + + return data; + }) + .then(data => callback(data)) + .catch(() => new Flash('Error fetching projects')); }, id: function(obj) { return obj.id; @@ -95,6 +101,18 @@ return $('.js-search-input').val('').trigger('keyup').focus(); }; + Search.prototype.getProjectsData = function(term) { + return new Promise((resolve) => { + if (this.groupId) { + Api.groupProjects(this.groupId, term, resolve); + } else { + Api.projects(term, { + order_by: 'id', + }, resolve); + } + }); + }; + return Search; })(); }).call(window); diff --git a/app/views/search/_filter.html.haml b/app/views/search/_filter.html.haml index 938be20c7cf..e43796e9654 100644 --- a/app/views/search/_filter.html.haml +++ b/app/views/search/_filter.html.haml @@ -3,7 +3,7 @@ - if params[:project_id].present? = hidden_field_tag :project_id, params[:project_id] .dropdown - %button.dropdown-menu-toggle.js-search-group-dropdown{ type: "button", data: { toggle: "dropdown", default_label: "Group:" } } + %button.dropdown-menu-toggle.js-search-group-dropdown{ type: "button", data: { toggle: "dropdown", default_label: "Group:", group_id: params[:group_id] } } %span.dropdown-toggle-text Group: - if @group.present? diff --git a/changelogs/unreleased/search-restrict-projects-to-group.yml b/changelogs/unreleased/search-restrict-projects-to-group.yml new file mode 100644 index 00000000000..ac134bc5bce --- /dev/null +++ b/changelogs/unreleased/search-restrict-projects-to-group.yml @@ -0,0 +1,4 @@ +--- +title: Restricts search projects dropdown to group projects when group is selected +merge_request: +author: diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb index 498a4a5cba0..f2866d071dc 100644 --- a/spec/features/search_spec.rb +++ b/spec/features/search_spec.rb @@ -20,6 +20,7 @@ describe "Search", feature: true do context 'search filters', js: true do let(:group) { create(:group) } + let!(:group_project) { create(:empty_project, group: group) } before do group.add_owner(user) @@ -36,6 +37,24 @@ describe "Search", feature: true do expect(find('.js-search-group-dropdown')).to have_content(group.name) end + it 'filters by group projects after filtering by group' do + find('.js-search-group-dropdown').click + wait_for_ajax + + page.within '.search-holder' do + click_link group.name + end + + expect(find('.js-search-group-dropdown')).to have_content(group.name) + + page.within('.project-filter') do + find('.js-search-project-dropdown').click + wait_for_ajax + + expect(page).to have_link(group_project.name_with_namespace) + end + end + it 'shows project name after filtering' do page.within('.project-filter') do find('.js-search-project-dropdown').click |