Commit e6ddb2ee authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'merge-request-target-branch-perf' into 'master'

Improved performance of merge requests target branch dropdown

See merge request gitlab-org/gitlab-ce!16428
parents b4bc9bd5 13d70796
...@@ -26,7 +26,6 @@ import ProjectsList from './projects_list'; ...@@ -26,7 +26,6 @@ import ProjectsList from './projects_list';
import UserCallout from './user_callout'; import UserCallout from './user_callout';
import ShortcutsWiki from './shortcuts_wiki'; import ShortcutsWiki from './shortcuts_wiki';
import BlobViewer from './blob/viewer/index'; import BlobViewer from './blob/viewer/index';
import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
import UsersSelect from './users_select'; import UsersSelect from './users_select';
import GfmAutoComplete from './gfm_auto_complete'; import GfmAutoComplete from './gfm_auto_complete';
import Star from './star'; import Star from './star';
...@@ -255,7 +254,6 @@ import Activities from './activities'; ...@@ -255,7 +254,6 @@ import Activities from './activities';
new LabelsSelect(); new LabelsSelect();
new MilestoneSelect(); new MilestoneSelect();
new IssuableTemplateSelectors(); new IssuableTemplateSelectors();
new AutoWidthDropdownSelect($('.js-target-branch-select')).init();
break; break;
case 'projects:tags:new': case 'projects:tags:new':
import('./pages/projects/tags/new') import('./pages/projects/tags/new')
......
...@@ -11,6 +11,14 @@ class AutoWidthDropdownSelect { ...@@ -11,6 +11,14 @@ class AutoWidthDropdownSelect {
const dropdownClass = this.dropdownClass; const dropdownClass = this.dropdownClass;
this.$selectElement.select2({ this.$selectElement.select2({
dropdownCssClass: dropdownClass, dropdownCssClass: dropdownClass,
...AutoWidthDropdownSelect.selectOptions(this.dropdownClass),
});
return this;
}
static selectOptions(dropdownClass) {
return {
dropdownCss() { dropdownCss() {
let resultantWidth = 'auto'; let resultantWidth = 'auto';
const $dropdown = $(`.${dropdownClass}`); const $dropdown = $(`.${dropdownClass}`);
...@@ -29,9 +37,7 @@ class AutoWidthDropdownSelect { ...@@ -29,9 +37,7 @@ class AutoWidthDropdownSelect {
maxWidth: offsetParentWidth, maxWidth: offsetParentWidth,
}; };
}, },
}); };
return this;
} }
} }
......
...@@ -6,6 +6,7 @@ import Autosave from './autosave'; ...@@ -6,6 +6,7 @@ import Autosave from './autosave';
import UsersSelect from './users_select'; import UsersSelect from './users_select';
import GfmAutoComplete from './gfm_auto_complete'; import GfmAutoComplete from './gfm_auto_complete';
import ZenMode from './zen_mode'; import ZenMode from './zen_mode';
import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
import { parsePikadayDate, pikadayToString } from './lib/utils/datefix'; import { parsePikadayDate, pikadayToString } from './lib/utils/datefix';
export default class IssuableForm { export default class IssuableForm {
...@@ -46,6 +47,12 @@ export default class IssuableForm { ...@@ -46,6 +47,12 @@ export default class IssuableForm {
}); });
calendar.setDate(parsePikadayDate($issuableDueDate.val())); calendar.setDate(parsePikadayDate($issuableDueDate.val()));
} }
this.$targetBranchSelect = $('.js-target-branch-select', this.form);
if (this.$targetBranchSelect.length) {
this.initTargetBranchDropdown();
}
} }
initAutosave() { initAutosave() {
...@@ -104,4 +111,37 @@ export default class IssuableForm { ...@@ -104,4 +111,37 @@ export default class IssuableForm {
addWip() { addWip() {
this.titleField.val(`WIP: ${(this.titleField.val())}`); this.titleField.val(`WIP: ${(this.titleField.val())}`);
} }
initTargetBranchDropdown() {
this.$targetBranchSelect.select2({
...AutoWidthDropdownSelect.selectOptions('js-target-branch-select'),
ajax: {
url: this.$targetBranchSelect.data('endpoint'),
dataType: 'JSON',
quietMillis: 250,
data(search) {
return {
search,
};
},
results(data) {
return {
// `data` keys are translated so we can't just access them with a string based key
results: data[Object.keys(data)[0]].map(name => ({
id: name,
text: name,
})),
};
},
},
initSelection(el, callback) {
const val = el.val();
callback({
id: val,
text: val,
});
},
});
}
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
= f.hidden_field :source_project_id = f.hidden_field :source_project_id
= f.hidden_field :source_branch = f.hidden_field :source_branch
= f.hidden_field :target_project_id = f.hidden_field :target_project_id
= f.hidden_field :target_branch = f.hidden_field :target_branch, id: ''
.mr-compare.merge-request.js-merge-request-new-submit{ 'data-mr-submit-action': "#{j params[:tab].presence || 'new'}" } .mr-compare.merge-request.js-merge-request-new-submit{ 'data-mr-submit-action': "#{j params[:tab].presence || 'new'}" }
- if @commits.empty? - if @commits.empty?
......
...@@ -15,11 +15,10 @@ ...@@ -15,11 +15,10 @@
= form.label :target_branch, class: 'control-label' = form.label :target_branch, class: 'control-label'
.col-sm-10.target-branch-select-dropdown-container .col-sm-10.target-branch-select-dropdown-container
.issuable-form-select-holder .issuable-form-select-holder
= form.select(:target_branch, issuable.target_branches, = form.hidden_field(:target_branch,
{ include_blank: true },
{ class: 'target_branch js-target-branch-select ref-name', { class: 'target_branch js-target-branch-select ref-name',
disabled: issuable.new_record?, disabled: issuable.new_record?,
data: { placeholder: "Select branch" }}) data: { placeholder: "Select branch", endpoint: refs_project_path(@project, sort: 'updated_desc', find: 'branches') }})
- if issuable.new_record? - if issuable.new_record?
   
= link_to 'Change branches', mr_change_branches_path(issuable) = link_to 'Change branches', mr_change_branches_path(issuable)
---
title: Improve performance of target branch dropdown
merge_request:
author:
type: performance
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