Commit 44847ab2 authored by Illya Klymov's avatar Illya Klymov

Merge branch '216054-add-reviewers-to-mr-form' into 'master'

Add reviewers to MR form

Closes #216054

See merge request gitlab-org/gitlab!40330
parents ed62e7fc 27d10aef
...@@ -66,6 +66,7 @@ export default class IssuableForm { ...@@ -66,6 +66,7 @@ export default class IssuableForm {
gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources, gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources,
).setup(); ).setup();
this.usersSelect = new UsersSelect(); this.usersSelect = new UsersSelect();
this.reviewersSelect = new UsersSelect(undefined, '.js-reviewer-search');
this.zenMode = new ZenMode(); this.zenMode = new ZenMode();
this.titleField = this.form.find('input[name*="[title]"]'); this.titleField = this.form.find('input[name*="[title]"]');
......
...@@ -55,6 +55,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -55,6 +55,7 @@ function UsersSelect(currentUser, els, options = {}) {
const defaultLabel = $dropdown.data('defaultLabel'); const defaultLabel = $dropdown.data('defaultLabel');
const issueURL = $dropdown.data('issueUpdate'); const issueURL = $dropdown.data('issueUpdate');
const $selectbox = $dropdown.closest('.selectbox'); const $selectbox = $dropdown.closest('.selectbox');
const $assignToMeLink = $selectbox.next('.assign-to-me-link');
let $block = $selectbox.closest('.block'); let $block = $selectbox.closest('.block');
const abilityName = $dropdown.data('abilityName'); const abilityName = $dropdown.data('abilityName');
let $value = $block.find('.value'); let $value = $block.find('.value');
...@@ -161,7 +162,7 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -161,7 +162,7 @@ function UsersSelect(currentUser, els, options = {}) {
}); });
}; };
$('.assign-to-me-link').on('click', e => { $assignToMeLink.on('click', e => {
e.preventDefault(); e.preventDefault();
$(e.currentTarget).hide(); $(e.currentTarget).hide();
...@@ -451,9 +452,9 @@ function UsersSelect(currentUser, els, options = {}) { ...@@ -451,9 +452,9 @@ function UsersSelect(currentUser, els, options = {}) {
} }
if (getSelected().find(u => u === gon.current_user_id)) { if (getSelected().find(u => u === gon.current_user_id)) {
$('.assign-to-me-link').hide(); $assignToMeLink.hide();
} else { } else {
$('.assign-to-me-link').show(); $assignToMeLink.show();
} }
} }
......
...@@ -55,6 +55,29 @@ module FormHelper ...@@ -55,6 +55,29 @@ module FormHelper
dropdown_data dropdown_data
end end
def reviewers_dropdown_options(issuable_type)
{
toggle_class: 'js-reviewer-search js-multiselect js-save-user-data',
title: 'Request review from',
filter: true,
dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-reviewer',
placeholder: _('Search users'),
data: {
first_user: current_user&.username,
null_user: true,
current_user: true,
project_id: (@target_project || @project)&.id,
field_name: "#{issuable_type}[reviewer_ids][]",
default_label: 'Unassigned',
'dropdown-header': 'Reviewer(s)',
multi_select: true,
'input-meta': 'name',
'always-show-selectbox': true,
current_user_info: UserSerializer.new.represent(current_user)
}
}
end
# Overwritten # Overwritten
def issue_supports_multiple_assignees? def issue_supports_multiple_assignees?
false false
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
.form-group.row.merge-request-assignee .form-group.row.merge-request-assignee
= render "shared/issuable/form/metadata_issuable_assignee", issuable: issuable, form: form, has_due_date: has_due_date = render "shared/issuable/form/metadata_issuable_assignee", issuable: issuable, form: form, has_due_date: has_due_date
- if issuable.allows_reviewers?
.form-group.row.merge-request-reviewer
= render "shared/issuable/form/metadata_issuable_reviewer", issuable: issuable, form: form, has_due_date: has_due_date
= render_if_exists "shared/issuable/form/epic", issuable: issuable, form: form, project: project = render_if_exists "shared/issuable/form/epic", issuable: issuable, form: form, project: project
- if issuable.supports_milestone? - if issuable.supports_milestone?
......
= form.label :reviewer_id, "Reviewer", class: "col-form-label #{has_due_date ? "col-md-2 col-lg-4" : "col-sm-2"}"
.col-sm-10{ class: ("col-md-8" if has_due_date) }
.issuable-form-select-holder.selectbox
- issuable.reviewers.each do |reviewer|
= hidden_field_tag "#{issuable.to_ability_name}[reviewer_ids][]", reviewer.id, id: nil, data: { meta: reviewer.name, avatar_url: reviewer.avatar_url, name: reviewer.name, username: reviewer.username }
- if issuable.reviewers.empty?
= hidden_field_tag "#{issuable.to_ability_name}[reviewer_ids][]", 0, id: nil, data: { meta: '' }
= dropdown_tag(users_dropdown_label(issuable.reviewers), options: reviewers_dropdown_options(issuable.to_ability_name))
...@@ -20,4 +20,32 @@ RSpec.describe 'Merge request > User edits MR' do ...@@ -20,4 +20,32 @@ RSpec.describe 'Merge request > User edits MR' do
include_context 'merge request edit context' include_context 'merge request edit context'
it_behaves_like 'an editable merge request' it_behaves_like 'an editable merge request'
end end
context 'when merge_request_reviewers is turned on' do
before do
stub_feature_flags(merge_request_reviewers: true)
end
context 'non-fork merge request' do
include_context 'merge request edit context'
it_behaves_like 'an editable merge request with reviewers'
end
context 'for a forked project' do
let(:source_project) { fork_project(target_project, nil, repository: true) }
include_context 'merge request edit context'
it_behaves_like 'an editable merge request with reviewers'
end
end
context 'when merge_request_reviewers is turned off' do
before do
stub_feature_flags(merge_request_reviewers: false)
end
it 'does not render reviewers dropdown' do
expect(page).not_to have_selector('.js-reviewer-search')
end
end
end end
...@@ -124,3 +124,16 @@ end ...@@ -124,3 +124,16 @@ end
def get_textarea_height def get_textarea_height
page.evaluate_script('document.getElementById("merge_request_description").offsetHeight') page.evaluate_script('document.getElementById("merge_request_description").offsetHeight')
end end
RSpec.shared_examples 'an editable merge request with reviewers' do
it 'updates merge request', :js do
find('.js-reviewer-search').click
page.within '.dropdown-menu-user' do
click_link user.name
end
expect(find('input[name="merge_request[reviewer_ids][]"]', visible: false).value).to match(user.id.to_s)
page.within '.js-reviewer-search' do
expect(page).to have_content user.name
end
end
end
...@@ -20,6 +20,7 @@ RSpec.describe 'projects/merge_requests/edit.html.haml' do ...@@ -20,6 +20,7 @@ RSpec.describe 'projects/merge_requests/edit.html.haml' do
target_project: project, target_project: project,
author: user, author: user,
assignees: [user], assignees: [user],
reviewers: [user],
milestone: milestone) milestone: milestone)
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