Commit ad2b6cae authored by Joseph Frazier's avatar Joseph Frazier

Append issue template to existing description

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/21733

Add two newlines before the template if the existing description isn't
empty. This makes it easier to see where the template begins.

Don't append the template when "Reset template" is selected, of course.

Don't append template if it equals the existing description. This makes
it so that selecting a template twice doesn't duplicate it.
parent a1aea326
...@@ -27,6 +27,7 @@ v 8.13.0 (unreleased) ...@@ -27,6 +27,7 @@ v 8.13.0 (unreleased)
- Only update issuable labels if they have been changed - Only update issuable labels if they have been changed
- Take filters in account in issuable counters. !6496 - Take filters in account in issuable counters. !6496
- Use custom Ruby images to test builds (registry.dev.gitlab.org/gitlab/gitlab-build-images:*) - Use custom Ruby images to test builds (registry.dev.gitlab.org/gitlab/gitlab-build-images:*)
- Append issue template to existing description !6149 (Joseph Frazier)
- Revoke button in Applications Settings underlines on hover. - Revoke button in Applications Settings underlines on hover.
- Add missing values to linter !6276 (Katarzyna Kobierska Ula Budziszewska) - Add missing values to linter !6276 (Katarzyna Kobierska Ula Budziszewska)
- Fix Long commit messages overflow viewport in file tree - Fix Long commit messages overflow viewport in file tree
......
...@@ -72,8 +72,13 @@ ...@@ -72,8 +72,13 @@
// To be implemented on the extending class // To be implemented on the extending class
// e.g. // e.g.
// Api.gitignoreText item.name, @requestFileSuccess.bind(@) // Api.gitignoreText item.name, @requestFileSuccess.bind(@)
TemplateSelector.prototype.requestFileSuccess = function(file, skipFocus) { TemplateSelector.prototype.requestFileSuccess = function(file, skipFocus, append) {
this.editor.setValue(file.content, 1); var oldValue = this.editor.getValue();
var newValue = file.content;
if (append && oldValue.length && oldValue !== newValue) {
newValue = oldValue + '\n\n' + newValue;
}
this.editor.setValue(newValue, 1);
if (!skipFocus) this.editor.focus(); if (!skipFocus) this.editor.focus();
if (this.editor instanceof jQuery) { if (this.editor instanceof jQuery) {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
if (initialQuery.name) this.requestFile(initialQuery); if (initialQuery.name) this.requestFile(initialQuery);
$('.reset-template', this.dropdown.parent()).on('click', () => { $('.reset-template', this.dropdown.parent()).on('click', () => {
if (this.currentTemplate) this.setInputValueToTemplateContent(); if (this.currentTemplate) this.setInputValueToTemplateContent(false);
}); });
} }
...@@ -26,22 +26,24 @@ ...@@ -26,22 +26,24 @@
this.currentTemplate = currentTemplate; this.currentTemplate = currentTemplate;
if (err) return; // Error handled by global AJAX error handler if (err) return; // Error handled by global AJAX error handler
this.stopLoadingSpinner(); this.stopLoadingSpinner();
this.setInputValueToTemplateContent(); this.setInputValueToTemplateContent(true);
}); });
return; return;
} }
setInputValueToTemplateContent() { setInputValueToTemplateContent(append) {
// `this.requestFileSuccess` sets the value of the description input field // `this.requestFileSuccess` sets the value of the description input field
// to the content of the template selected. // to the content of the template selected. If `append` is true, the
// template content will be appended to the previous value of the field,
// separated by a blank line if the previous value is non-empty.
if (this.titleInput.val() === '') { if (this.titleInput.val() === '') {
// If the title has not yet been set, focus the title input and // If the title has not yet been set, focus the title input and
// skip focusing the description input by setting `true` as the 2nd // skip focusing the description input by setting `true` as the 2nd
// argument to `requestFileSuccess`. // argument to `requestFileSuccess`.
this.requestFileSuccess(this.currentTemplate, true); this.requestFileSuccess(this.currentTemplate, true, append);
this.titleInput.focus(); this.titleInput.focus();
} else { } else {
this.requestFileSuccess(this.currentTemplate); this.requestFileSuccess(this.currentTemplate, false, append);
} }
return; return;
} }
......
...@@ -26,7 +26,7 @@ feature 'issuable templates', feature: true, js: true do ...@@ -26,7 +26,7 @@ feature 'issuable templates', feature: true, js: true do
scenario 'user selects "bug" template' do scenario 'user selects "bug" template' do
select_template 'bug' select_template 'bug'
wait_for_ajax wait_for_ajax
preview_template preview_template(template_content)
save_changes save_changes
end end
...@@ -42,6 +42,26 @@ feature 'issuable templates', feature: true, js: true do ...@@ -42,6 +42,26 @@ feature 'issuable templates', feature: true, js: true do
end end
end end
context 'user creates an issue using templates, with a prior description' do
let(:prior_description) { 'test issue description' }
let(:template_content) { 'this is a test "bug" template' }
let(:issue) { create(:issue, author: user, assignee: user, project: project) }
background do
project.repository.commit_file(user, '.gitlab/issue_templates/bug.md', template_content, 'added issue template', 'master', false)
visit edit_namespace_project_issue_path project.namespace, project, issue
fill_in :'issue[title]', with: 'test issue title'
fill_in :'issue[description]', with: prior_description
end
scenario 'user selects "bug" template' do
select_template 'bug'
wait_for_ajax
preview_template("#{prior_description}\n\n#{template_content}")
save_changes
end
end
context 'user creates a merge request using templates' do context 'user creates a merge request using templates' do
let(:template_content) { 'this is a test "feature-proposal" template' } let(:template_content) { 'this is a test "feature-proposal" template' }
let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) } let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) }
...@@ -55,7 +75,7 @@ feature 'issuable templates', feature: true, js: true do ...@@ -55,7 +75,7 @@ feature 'issuable templates', feature: true, js: true do
scenario 'user selects "feature-proposal" template' do scenario 'user selects "feature-proposal" template' do
select_template 'feature-proposal' select_template 'feature-proposal'
wait_for_ajax wait_for_ajax
preview_template preview_template(template_content)
save_changes save_changes
end end
end end
...@@ -82,16 +102,16 @@ feature 'issuable templates', feature: true, js: true do ...@@ -82,16 +102,16 @@ feature 'issuable templates', feature: true, js: true do
scenario 'user selects template' do scenario 'user selects template' do
select_template 'feature-proposal' select_template 'feature-proposal'
wait_for_ajax wait_for_ajax
preview_template preview_template(template_content)
save_changes save_changes
end end
end end
end end
end end
def preview_template def preview_template(expected_content)
click_link 'Preview' click_link 'Preview'
expect(page).to have_content template_content expect(page).to have_content expected_content
end end
def save_changes def save_changes
......
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