only search branches

target branch select dropdown doesnt care about tags so we dont need to waste time searching them
This commit is contained in:
Phil Hughes 2018-01-12 12:59:08 +00:00
parent 4b81b6a181
commit 5f5249d759
No known key found for this signature in database
GPG key ID: 32245528C52E0F9F
3 changed files with 13 additions and 21 deletions

View file

@ -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 {
maxWidth: offsetParentWidth, maxWidth: offsetParentWidth,
}; };
}, },
}); };
return this;
} }
} }

View file

@ -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 {
@ -113,6 +114,7 @@ export default class IssuableForm {
initTargetBranchDropdown() { initTargetBranchDropdown() {
this.$targetBranchSelect.select2({ this.$targetBranchSelect.select2({
...AutoWidthDropdownSelect.selectOptions('js-target-branch-select'),
ajax: { ajax: {
url: this.$targetBranchSelect.data('endpoint'), url: this.$targetBranchSelect.data('endpoint'),
dataType: 'JSON', dataType: 'JSON',
@ -124,6 +126,7 @@ export default class IssuableForm {
}, },
results(data) { results(data) {
return { 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 => ({ results: data[Object.keys(data)[0]].map(name => ({
id: name, id: name,
text: name, text: name,
@ -139,23 +142,6 @@ export default class IssuableForm {
text: val, text: val,
}); });
}, },
dropdownCss: () => {
let resultantWidth = 'auto';
// We have to look at the parent because
// `offsetParent` on a `display: none;` is `null`
const offsetParentWidth = this.$targetBranchSelect.parent().offsetParent().width();
// Reset any width to let it naturally flow
this.$targetBranchSelect.css('width', 'auto');
if (this.$targetBranchSelect.outerWidth(false) > offsetParentWidth) {
resultantWidth = offsetParentWidth;
}
return {
width: resultantWidth,
maxWidth: offsetParentWidth,
};
},
}); });
} }
} }

View file

@ -18,7 +18,7 @@
= form.hidden_field(:target_branch, = form.hidden_field(:target_branch,
{ 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", endpoint: refs_project_path(@project, sort: 'updated_desc') }}) 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)