diff options
author | Jacob Schatz <jschatz@gitlab.com> | 2017-02-03 15:03:57 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2017-02-03 15:03:57 +0000 |
commit | 806b038a44cda37fa7d8ba9afae4b7adb07afe94 (patch) | |
tree | f8841e93eb070feae34fa2cc5f61e0efecf88bd0 | |
parent | 52ea505126da19717c9137e6bb301f55965eb6e4 (diff) | |
parent | 50d58c14cd2cd1b8fb1bb9e4a7a1091b5af90c04 (diff) | |
download | gitlab-ce-806b038a44cda37fa7d8ba9afae4b7adb07afe94.tar.gz |
Merge branch 'ref-switcher-perf' into 'master'
Improved ref switcher dropdown performance
Closes #18202
See merge request !7239
-rw-r--r-- | app/assets/javascripts/project.js | 29 | ||||
-rw-r--r-- | app/assets/javascripts/protected_branches/protected_branch_dropdown.js.es6 | 2 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 8 | ||||
-rw-r--r-- | spec/features/projects/ref_switcher_spec.rb | 5 |
4 files changed, 34 insertions, 10 deletions
diff --git a/app/assets/javascripts/project.js b/app/assets/javascripts/project.js index 7cf630a1d76..67f8804666d 100644 --- a/app/assets/javascripts/project.js +++ b/app/assets/javascripts/project.js @@ -58,6 +58,11 @@ }; Project.prototype.initRefSwitcher = function() { + var refListItem = document.createElement('li'), + refLink = document.createElement('a'); + + refLink.href = '#'; + return $('.js-project-refs-dropdown').each(function() { var $dropdown, selected; $dropdown = $(this); @@ -67,7 +72,8 @@ return $.ajax({ url: $dropdown.data('refs-url'), data: { - ref: $dropdown.data('ref') + ref: $dropdown.data('ref'), + search: term }, dataType: "json" }).done(function(refs) { @@ -76,16 +82,29 @@ }, selectable: true, filterable: true, + filterRemote: true, filterByText: true, fieldName: $dropdown.data('field-name'), renderRow: function(ref) { - var link; + var li = refListItem.cloneNode(false); + if (ref.header != null) { - return $('<li />').addClass('dropdown-header').text(ref.header); + li.className = 'dropdown-header'; + li.textContent = ref.header; } else { - link = $('<a />').attr('href', '#').addClass(ref === selected ? 'is-active' : '').text(ref).attr('data-ref', ref); - return $('<li />').append(link); + var link = refLink.cloneNode(false); + + if (ref === selected) { + link.className = 'is-active'; + } + + link.textContent = ref; + link.dataset.ref = ref; + + li.appendChild(link); } + + return li; }, id: function(obj, $el) { return $el.attr('data-ref'); diff --git a/app/assets/javascripts/protected_branches/protected_branch_dropdown.js.es6 b/app/assets/javascripts/protected_branches/protected_branch_dropdown.js.es6 index 03f4531abf5..5cf28aa7a73 100644 --- a/app/assets/javascripts/protected_branches/protected_branch_dropdown.js.es6 +++ b/app/assets/javascripts/protected_branches/protected_branch_dropdown.js.es6 @@ -49,7 +49,7 @@ class ProtectedBranchDropdown { onClickCreateWildcard() { // Refresh the dropdown's data, which ends up calling `getProtectedBranches` this.$dropdown.data('glDropdown').remote.execute(); - this.$dropdown.data('glDropdown').selectRowAtIndex(0); + this.$dropdown.data('glDropdown').selectRowAtIndex(); } getProtectedBranches(term, callback) { diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 444ff837bb3..acca821782c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -231,12 +231,16 @@ class ProjectsController < Projects::ApplicationController end def refs + branches = BranchesFinder.new(@repository, params).execute.map(&:name) + options = { - 'Branches' => @repository.branch_names, + 'Branches' => branches.take(100), } unless @repository.tag_count.zero? - options['Tags'] = VersionSorter.rsort(@repository.tag_names) + tags = TagsFinder.new(@repository, params).execute.map(&:name) + + options['Tags'] = tags.take(100) end # If reference is commit id - we should add it to branch/tag selectbox diff --git a/spec/features/projects/ref_switcher_spec.rb b/spec/features/projects/ref_switcher_spec.rb index 472491188c9..38fe2d92885 100644 --- a/spec/features/projects/ref_switcher_spec.rb +++ b/spec/features/projects/ref_switcher_spec.rb @@ -17,14 +17,15 @@ feature 'Ref switcher', feature: true, js: true do page.within '.project-refs-form' do input = find('input[type="search"]') - input.set 'expand' + input.set 'binary' + wait_for_ajax input.native.send_keys :down input.native.send_keys :down input.native.send_keys :enter end - expect(page).to have_title 'expand-collapse-files' + expect(page).to have_title 'binary-encoding' end it "user selects ref with special characters" do |