summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-01-12 12:59:08 +0000
committerPhil Hughes <me@iamphill.com>2018-01-16 11:49:24 +0000
commit5f5249d759d9324e23f274056d27931dbf299094 (patch)
treeb95f0ace75d61b0333b0e0d9f91eee29dfcb21ff
parent4b81b6a181f22ceb46ab9187bbd4c8d76edd01a3 (diff)
downloadgitlab-ce-5f5249d759d9324e23f274056d27931dbf299094.tar.gz
only search branches
target branch select dropdown doesnt care about tags so we dont need to waste time searching them
-rw-r--r--app/assets/javascripts/issuable/auto_width_dropdown_select.js12
-rw-r--r--app/assets/javascripts/issuable_form.js20
-rw-r--r--app/views/shared/issuable/form/_branch_chooser.html.haml2
3 files changed, 13 insertions, 21 deletions
diff --git a/app/assets/javascripts/issuable/auto_width_dropdown_select.js b/app/assets/javascripts/issuable/auto_width_dropdown_select.js
index 2203a56315e..14a2bfbe4e0 100644
--- a/app/assets/javascripts/issuable/auto_width_dropdown_select.js
+++ b/app/assets/javascripts/issuable/auto_width_dropdown_select.js
@@ -11,6 +11,14 @@ class AutoWidthDropdownSelect {
const dropdownClass = this.dropdownClass;
this.$selectElement.select2({
dropdownCssClass: dropdownClass,
+ ...AutoWidthDropdownSelect.selectOptions(this.dropdownClass),
+ });
+
+ return this;
+ }
+
+ static selectOptions(dropdownClass) {
+ return {
dropdownCss() {
let resultantWidth = 'auto';
const $dropdown = $(`.${dropdownClass}`);
@@ -29,9 +37,7 @@ class AutoWidthDropdownSelect {
maxWidth: offsetParentWidth,
};
},
- });
-
- return this;
+ };
}
}
diff --git a/app/assets/javascripts/issuable_form.js b/app/assets/javascripts/issuable_form.js
index 8380499748e..76c40bca1bd 100644
--- a/app/assets/javascripts/issuable_form.js
+++ b/app/assets/javascripts/issuable_form.js
@@ -6,6 +6,7 @@ import Autosave from './autosave';
import UsersSelect from './users_select';
import GfmAutoComplete from './gfm_auto_complete';
import ZenMode from './zen_mode';
+import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
import { parsePikadayDate, pikadayToString } from './lib/utils/datefix';
export default class IssuableForm {
@@ -113,6 +114,7 @@ export default class IssuableForm {
initTargetBranchDropdown() {
this.$targetBranchSelect.select2({
+ ...AutoWidthDropdownSelect.selectOptions('js-target-branch-select'),
ajax: {
url: this.$targetBranchSelect.data('endpoint'),
dataType: 'JSON',
@@ -124,6 +126,7 @@ export default class IssuableForm {
},
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,
@@ -139,23 +142,6 @@ export default class IssuableForm {
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,
- };
- },
});
}
}
diff --git a/app/views/shared/issuable/form/_branch_chooser.html.haml b/app/views/shared/issuable/form/_branch_chooser.html.haml
index ee9087558d7..9a589387255 100644
--- a/app/views/shared/issuable/form/_branch_chooser.html.haml
+++ b/app/views/shared/issuable/form/_branch_chooser.html.haml
@@ -18,7 +18,7 @@
= form.hidden_field(:target_branch,
{ class: 'target_branch js-target-branch-select ref-name',
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?
&nbsp;
= link_to 'Change branches', mr_change_branches_path(issuable)