Commit 91e8f770 authored by Jacob Schatz's avatar Jacob Schatz

Merge branch '30329-web-gui-unable-to-create-new-branch-from-commit-sha' into 'master'

Resolve "Web GUI: Unable to create new branch from commit SHA"

Closes #30329

See merge request !10738
parents 3a2b60f7 41d0f231
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
filterByText: true, filterByText: true,
remote: false, remote: false,
fieldName: $branchSelect.data('field-name'), fieldName: $branchSelect.data('field-name'),
filterInput: 'input[type="search"]',
selectable: true, selectable: true,
isSelectable: function(branch, $el) { isSelectable: function(branch, $el) {
return !$el.hasClass('is-active'); return !$el.hasClass('is-active');
...@@ -50,6 +51,21 @@ ...@@ -50,6 +51,21 @@
} }
} }
}); });
const $dropdownContainer = $branchSelect.closest('.dropdown');
const $fieldInput = $(`input[name="${$branchSelect.data('field-name')}"]`, $dropdownContainer);
const $filterInput = $('input[type="search"]', $dropdownContainer);
$filterInput.on('keyup', (e) => {
const keyCode = e.keyCode || e.which;
if (keyCode !== 13) return;
const text = $filterInput.val();
$fieldInput.val(text);
$('.dropdown-toggle-text', $branchSelect).text(text);
$dropdownContainer.removeClass('open');
});
}; };
NewBranchForm.prototype.setupRestrictions = function() { NewBranchForm.prototype.setupRestrictions = function() {
......
- page_title "New Branch" - page_title "New Branch"
- default_ref = params[:ref] || @project.default_branch
- if @error - if @error
.alert.alert-danger .alert.alert-danger
...@@ -16,12 +17,11 @@ ...@@ -16,12 +17,11 @@
.help-block.text-danger.js-branch-name-error .help-block.text-danger.js-branch-name-error
.form-group .form-group
= label_tag :ref, 'Create from', class: 'control-label' = label_tag :ref, 'Create from', class: 'control-label'
.col-sm-10 .col-sm-10.dropdown.create-from
= hidden_field_tag :ref, params[:ref] || @project.default_branch = hidden_field_tag :ref, default_ref
= dropdown_tag(params[:ref] || @project.default_branch, = button_tag type: 'button', title: default_ref, class: 'dropdown-toggle form-control js-branch-select', required: true, data: { toggle: 'dropdown', selected: default_ref, field_name: 'ref' } do
options: { toggle_class: 'js-branch-select wide', .text-left.dropdown-toggle-text= default_ref
filter: true, dropdown_class: "dropdown-menu-selectable", placeholder: "Search branches", = render 'shared/ref_dropdown', dropdown_class: 'wide'
data: { selected: params[:ref] || @project.default_branch, field_name: 'ref' } })
.help-block Existing branch name, tag, or commit SHA .help-block Existing branch name, tag, or commit SHA
.form-actions .form-actions
= button_tag 'Create branch', class: 'btn btn-create', tabindex: 3 = button_tag 'Create branch', class: 'btn btn-create', tabindex: 3
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
= hidden_field_tag :from, params[:from] = hidden_field_tag :from, params[:from]
= button_tag type: 'button', title: params[:from], class: "form-control compare-dropdown-toggle js-compare-dropdown has-tooltip", required: true, data: { refs_url: refs_namespace_project_path(@project.namespace, @project), toggle: "dropdown", target: ".js-compare-from-dropdown", selected: params[:from], field_name: :from } do = button_tag type: 'button', title: params[:from], class: "form-control compare-dropdown-toggle js-compare-dropdown has-tooltip", required: true, data: { refs_url: refs_namespace_project_path(@project.namespace, @project), toggle: "dropdown", target: ".js-compare-from-dropdown", selected: params[:from], field_name: :from } do
.dropdown-toggle-text.str-truncated= params[:from] || 'Select branch/tag' .dropdown-toggle-text.str-truncated= params[:from] || 'Select branch/tag'
= render "ref_dropdown" = render 'shared/ref_dropdown'
.compare-ellipsis.inline ... .compare-ellipsis.inline ...
.form-group.dropdown.compare-form-group.to.js-compare-to-dropdown .form-group.dropdown.compare-form-group.to.js-compare-to-dropdown
.input-group.inline-input-group .input-group.inline-input-group
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
= hidden_field_tag :to, params[:to] = hidden_field_tag :to, params[:to]
= button_tag type: 'button', title: params[:to], class: "form-control compare-dropdown-toggle js-compare-dropdown has-tooltip", required: true, data: { refs_url: refs_namespace_project_path(@project.namespace, @project), toggle: "dropdown", target: ".js-compare-to-dropdown", selected: params[:to], field_name: :to } do = button_tag type: 'button', title: params[:to], class: "form-control compare-dropdown-toggle js-compare-dropdown has-tooltip", required: true, data: { refs_url: refs_namespace_project_path(@project.namespace, @project), toggle: "dropdown", target: ".js-compare-to-dropdown", selected: params[:to], field_name: :to } do
.dropdown-toggle-text.str-truncated= params[:to] || 'Select branch/tag' .dropdown-toggle-text.str-truncated= params[:to] || 'Select branch/tag'
= render "ref_dropdown" = render 'shared/ref_dropdown'
   
= button_tag "Compare", class: "btn btn-create commits-compare-btn" = button_tag "Compare", class: "btn btn-create commits-compare-btn"
- if @merge_request.present? - if @merge_request.present?
......
.dropdown-menu.dropdown-menu-selectable - dropdown_class = local_assigns.fetch(:dropdown_class, '')
.dropdown-menu.dropdown-menu-selectable{ class: dropdown_class }
= dropdown_title "Select Git revision" = dropdown_title "Select Git revision"
= dropdown_filter "Filter by Git revision" = dropdown_filter "Filter by Git revision"
= dropdown_content = dropdown_content
......
require 'spec_helper'
describe 'New Branch Ref Dropdown', :js, :feature do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:toggle) { find('.create-from .dropdown-toggle') }
before do
project.add_master(user)
login_as(user)
visit new_namespace_project_branch_path(project.namespace, project)
end
it 'filters a list of branches and tags' do
toggle.click
filter_by('v1.0.0')
expect(items_count).to be(1)
filter_by('video')
expect(items_count).to be(1)
find('.create-from .dropdown-content li').click
expect(toggle).to have_content 'video'
end
it 'accepts a manually entered commit SHA' do
toggle.click
filter_by('somecommitsha')
find('.create-from input[type=search]').send_keys(:enter)
expect(toggle).to have_content 'somecommitsha'
end
def items_count
all('.create-from .dropdown-content li').length
end
def filter_by(filter_text)
fill_in 'Filter by Git revision', with: filter_text
end
end
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