Commit 806b038a authored by Jacob Schatz's avatar Jacob Schatz

Merge branch 'ref-switcher-perf' into 'master'

Improved ref switcher dropdown performance

Closes #18202

See merge request !7239
parents 52ea5051 50d58c14
...@@ -58,6 +58,11 @@ ...@@ -58,6 +58,11 @@
}; };
Project.prototype.initRefSwitcher = function() { Project.prototype.initRefSwitcher = function() {
var refListItem = document.createElement('li'),
refLink = document.createElement('a');
refLink.href = '#';
return $('.js-project-refs-dropdown').each(function() { return $('.js-project-refs-dropdown').each(function() {
var $dropdown, selected; var $dropdown, selected;
$dropdown = $(this); $dropdown = $(this);
...@@ -67,7 +72,8 @@ ...@@ -67,7 +72,8 @@
return $.ajax({ return $.ajax({
url: $dropdown.data('refs-url'), url: $dropdown.data('refs-url'),
data: { data: {
ref: $dropdown.data('ref') ref: $dropdown.data('ref'),
search: term
}, },
dataType: "json" dataType: "json"
}).done(function(refs) { }).done(function(refs) {
...@@ -76,16 +82,29 @@ ...@@ -76,16 +82,29 @@
}, },
selectable: true, selectable: true,
filterable: true, filterable: true,
filterRemote: true,
filterByText: true, filterByText: true,
fieldName: $dropdown.data('field-name'), fieldName: $dropdown.data('field-name'),
renderRow: function(ref) { renderRow: function(ref) {
var link; var li = refListItem.cloneNode(false);
if (ref.header != null) { if (ref.header != null) {
return $('<li />').addClass('dropdown-header').text(ref.header); li.className = 'dropdown-header';
li.textContent = ref.header;
} else { } else {
link = $('<a />').attr('href', '#').addClass(ref === selected ? 'is-active' : '').text(ref).attr('data-ref', ref); var link = refLink.cloneNode(false);
return $('<li />').append(link);
if (ref === selected) {
link.className = 'is-active';
}
link.textContent = ref;
link.dataset.ref = ref;
li.appendChild(link);
} }
return li;
}, },
id: function(obj, $el) { id: function(obj, $el) {
return $el.attr('data-ref'); return $el.attr('data-ref');
......
...@@ -49,7 +49,7 @@ class ProtectedBranchDropdown { ...@@ -49,7 +49,7 @@ class ProtectedBranchDropdown {
onClickCreateWildcard() { onClickCreateWildcard() {
// Refresh the dropdown's data, which ends up calling `getProtectedBranches` // Refresh the dropdown's data, which ends up calling `getProtectedBranches`
this.$dropdown.data('glDropdown').remote.execute(); this.$dropdown.data('glDropdown').remote.execute();
this.$dropdown.data('glDropdown').selectRowAtIndex(0); this.$dropdown.data('glDropdown').selectRowAtIndex();
} }
getProtectedBranches(term, callback) { getProtectedBranches(term, callback) {
......
...@@ -231,12 +231,16 @@ class ProjectsController < Projects::ApplicationController ...@@ -231,12 +231,16 @@ class ProjectsController < Projects::ApplicationController
end end
def refs def refs
branches = BranchesFinder.new(@repository, params).execute.map(&:name)
options = { options = {
'Branches' => @repository.branch_names, 'Branches' => branches.take(100),
} }
unless @repository.tag_count.zero? 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 end
# If reference is commit id - we should add it to branch/tag selectbox # If reference is commit id - we should add it to branch/tag selectbox
......
...@@ -17,14 +17,15 @@ feature 'Ref switcher', feature: true, js: true do ...@@ -17,14 +17,15 @@ feature 'Ref switcher', feature: true, js: true do
page.within '.project-refs-form' do page.within '.project-refs-form' do
input = find('input[type="search"]') 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 :down input.native.send_keys :down
input.native.send_keys :enter input.native.send_keys :enter
end end
expect(page).to have_title 'expand-collapse-files' expect(page).to have_title 'binary-encoding'
end end
it "user selects ref with special characters" do it "user selects ref with special characters" do
......
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