Commit d343c7a1 authored by Jacob Schatz's avatar Jacob Schatz
Browse files

Merge branch 'comment-discard-button' into 'master'

Added discard button to comment form

Also changed the labels on the buttons to better match the action they are completing.

Closes #8057

See merge request !3085
parents 1f083636 6690d8e2
...@@ -54,6 +54,9 @@ class @Notes ...@@ -54,6 +54,9 @@ class @Notes
$(document).on "ajax:complete", ".js-main-target-form", @reenableTargetFormSubmitButton $(document).on "ajax:complete", ".js-main-target-form", @reenableTargetFormSubmitButton
$(document).on "ajax:success", ".js-main-target-form", @resetMainTargetForm $(document).on "ajax:success", ".js-main-target-form", @resetMainTargetForm
# reset main target form when clicking discard
$(document).on "click", ".js-note-discard", @resetMainTargetForm
# update the file name when an attachment is selected # update the file name when an attachment is selected
$(document).on "change", ".js-note-attachment-input", @updateFormAttachment $(document).on "change", ".js-note-attachment-input", @updateFormAttachment
...@@ -88,6 +91,7 @@ class @Notes ...@@ -88,6 +91,7 @@ class @Notes
$(document).off "keyup", ".js-note-text" $(document).off "keyup", ".js-note-text"
$(document).off "click", ".js-note-target-reopen" $(document).off "click", ".js-note-target-reopen"
$(document).off "click", ".js-note-target-close" $(document).off "click", ".js-note-target-close"
$(document).off "click", ".js-note-discard"
$('.note .js-task-list-container').taskList('disable') $('.note .js-task-list-container').taskList('disable')
$(document).off 'tasklist:changed', '.note .js-task-list-container' $(document).off 'tasklist:changed', '.note .js-task-list-container'
...@@ -222,7 +226,7 @@ class @Notes ...@@ -222,7 +226,7 @@ class @Notes
Resets text and preview. Resets text and preview.
Resets buttons. Resets buttons.
### ###
resetMainTargetForm: -> resetMainTargetForm: (e) =>
form = $(".js-main-target-form") form = $(".js-main-target-form")
# remove validation errors # remove validation errors
...@@ -234,6 +238,8 @@ class @Notes ...@@ -234,6 +238,8 @@ class @Notes
form.find(".js-note-text").data("autosave").reset() form.find(".js-note-text").data("autosave").reset()
@updateTargetButtons(e)
reenableTargetFormSubmitButton: -> reenableTargetFormSubmitButton: ->
form = $(".js-main-target-form") form = $(".js-main-target-form")
...@@ -277,8 +283,10 @@ class @Notes ...@@ -277,8 +283,10 @@ class @Notes
form.removeClass "js-new-note-form" form.removeClass "js-new-note-form"
form.find('.div-dropzone').remove() form.find('.div-dropzone').remove()
# hide discard button
form.find('.js-note-discard').hide()
# setup preview buttons # setup preview buttons
form.find(".js-md-write-button, .js-md-preview-button").tooltip placement: "left"
previewButton = form.find(".js-md-preview-button") previewButton = form.find(".js-md-preview-button")
textarea = form.find(".js-note-text") textarea = form.find(".js-note-text")
...@@ -476,6 +484,11 @@ class @Notes ...@@ -476,6 +484,11 @@ class @Notes
form.find("#note_line_code").val dataHolder.data("lineCode") form.find("#note_line_code").val dataHolder.data("lineCode")
form.find("#note_noteable_type").val dataHolder.data("noteableType") form.find("#note_noteable_type").val dataHolder.data("noteableType")
form.find("#note_noteable_id").val dataHolder.data("noteableId") form.find("#note_noteable_id").val dataHolder.data("noteableId")
form.find('.js-note-discard')
.show()
.removeClass('js-note-discard')
.addClass('js-close-discussion-note-form')
.text(form.find('.js-close-discussion-note-form').data('cancel-text'))
@setupNoteForm form @setupNoteForm form
form.find(".js-note-text").focus() form.find(".js-note-text").focus()
form.addClass "js-discussion-note-form" form.addClass "js-discussion-note-form"
...@@ -575,21 +588,52 @@ class @Notes ...@@ -575,21 +588,52 @@ class @Notes
updateCloseButton: (e) => updateCloseButton: (e) =>
textarea = $(e.target) textarea = $(e.target)
form = textarea.parents('form') form = textarea.parents('form')
form.find('.js-note-target-close').text('Close') closebtn = form.find('.js-note-target-close')
closebtn.text(closebtn.data('original-text'))
updateTargetButtons: (e) => updateTargetButtons: (e) =>
textarea = $(e.target) textarea = $(e.target)
form = textarea.parents('form') form = textarea.parents('form')
reopenbtn = form.find('.js-note-target-reopen')
closebtn = form.find('.js-note-target-close')
discardbtn = form.find('.js-note-discard')
if textarea.val().trim().length > 0 if textarea.val().trim().length > 0
form.find('.js-note-target-reopen').text('Comment & reopen') reopentext = reopenbtn.data('alternative-text')
form.find('.js-note-target-close').text('Comment & close') closetext = closebtn.data('alternative-text')
form.find('.js-note-target-reopen').addClass('btn-comment-and-reopen')
form.find('.js-note-target-close').addClass('btn-comment-and-close') if reopenbtn.text() isnt reopentext
reopenbtn.text(reopentext)
if closebtn.text() isnt closetext
closebtn.text(closetext)
if reopenbtn.is(':not(.btn-comment-and-reopen)')
reopenbtn.addClass('btn-comment-and-reopen')
if closebtn.is(':not(.btn-comment-and-close)')
closebtn.addClass('btn-comment-and-close')
if discardbtn.is(':hidden')
discardbtn.show()
else else
form.find('.js-note-target-reopen').text('Reopen') reopentext = reopenbtn.data('original-text')
form.find('.js-note-target-close').text('Close') closetext = closebtn.data('original-text')
form.find('.js-note-target-reopen').removeClass('btn-comment-and-reopen')
form.find('.js-note-target-close').removeClass('btn-comment-and-close') if reopenbtn.text() isnt reopentext
reopenbtn.text(reopentext)
if closebtn.text() isnt closetext
closebtn.text(closetext)
if reopenbtn.is(':not(.btn-comment-and-reopen)')
reopenbtn.removeClass('btn-comment-and-reopen')
if closebtn.is(':not(.btn-comment-and-close)')
closebtn.removeClass('btn-comment-and-close')
if discardbtn.is(':visible')
discardbtn.hide()
initTaskList: -> initTaskList: ->
@enableTaskList() @enableTaskList()
......
- content_for :note_actions do - content_for :note_actions do
- if can?(current_user, :update_issue, @issue) - if can?(current_user, :update_issue, @issue)
= link_to 'Reopen issue', issue_path(@issue, issue: {state_event: :reopen}, status_only: true, format: 'json'), data: {no_turbolink: true}, class: "btn btn-nr btn-grouped btn-reopen btn-comment js-note-target-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen issue' = link_to 'Reopen issue', issue_path(@issue, issue: {state_event: :reopen}, status_only: true, format: 'json'), data: {no_turbolink: true, original_text: "Reopen issue", alternative_text: "Comment & reopen issue"}, class: "btn btn-nr btn-grouped btn-reopen btn-comment js-note-target-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen issue'
= link_to 'Close issue', issue_path(@issue, issue: {state_event: :close}, status_only: true, format: 'json'), data: {no_turbolink: true}, class: "btn btn-nr btn-grouped btn-close btn-comment js-note-target-close #{issue_button_visibility(@issue, true)}", title: 'Close issue' = link_to 'Close issue', issue_path(@issue, issue: {state_event: :close}, status_only: true, format: 'json'), data: {no_turbolink: true, original_text: "Close issue", alternative_text: "Comment & close issue"}, class: "btn btn-nr btn-grouped btn-close btn-comment js-note-target-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
#notes #notes
= render 'projects/notes/notes_with_form' = render 'projects/notes/notes_with_form'
- content_for :note_actions do - content_for :note_actions do
- if can?(current_user, :update_merge_request, @merge_request) - if can?(current_user, :update_merge_request, @merge_request)
- if @merge_request.open? - if @merge_request.open?
= link_to 'Close', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-nr btn-comment btn-grouped btn-close close-mr-link js-note-target-close", title: "Close merge request" = link_to 'Close merge request', merge_request_path(@merge_request, merge_request: {state_event: :close }), method: :put, class: "btn btn-nr btn-comment btn-grouped btn-close close-mr-link js-note-target-close", title: "Close merge request", data: {original_text: "Close merge request", alternative_text: "Comment & close merge request"}
- if @merge_request.closed? - if @merge_request.closed?
= link_to 'Reopen', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-grouped btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request" = link_to 'Reopen merge request', merge_request_path(@merge_request, merge_request: {state_event: :reopen }), method: :put, class: "btn btn-nr btn-comment btn-grouped btn-reopen reopen-mr-link js-note-target-reopen", title: "Reopen merge request", data: {original_text: "Reopen merge request", alternative_text: "Comment & reopen merge request"}
#notes= render "projects/notes/notes_with_form" #notes= render "projects/notes/notes_with_form"
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
.error-alert .error-alert
.note-form-actions.clearfix .note-form-actions.clearfix
= f.submit 'Add Comment', class: "btn btn-nr btn-create comment-btn btn-grouped js-comment-button" = f.submit 'Comment', class: "btn btn-nr btn-create comment-btn btn-grouped js-comment-button"
= yield(:note_actions) = yield(:note_actions)
%a.btn.btn-nr.btn-cancel.js-close-discussion-note-form Cancel %a.btn.btn-cancel.js-note-discard{role: "button", data: {cancel_text: "Cancel"}}
Discard draft
...@@ -79,7 +79,7 @@ class Spinach::Features::AwardEmoji < Spinach::FeatureSteps ...@@ -79,7 +79,7 @@ class Spinach::Features::AwardEmoji < Spinach::FeatureSteps
step 'I leave comment with a single emoji' do step 'I leave comment with a single emoji' do
page.within('.js-main-target-form') do page.within('.js-main-target-form') do
fill_in 'note[note]', with: ':smile:' fill_in 'note[note]', with: ':smile:'
click_button 'Add Comment' click_button 'Comment'
end end
end end
......
...@@ -268,7 +268,7 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps ...@@ -268,7 +268,7 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps
step 'I leave a comment with code block' do step 'I leave a comment with code block' do
page.within(".js-main-target-form") do page.within(".js-main-target-form") do
fill_in "note[note]", with: "```\nCommand [1]: /usr/local/bin/git , see [text](doc/text)\n```" fill_in "note[note]", with: "```\nCommand [1]: /usr/local/bin/git , see [text](doc/text)\n```"
click_button "Add Comment" click_button "Comment"
sleep 0.05 sleep 0.05
end end
end end
......
...@@ -419,7 +419,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -419,7 +419,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.within(".js-discussion-note-form") do page.within(".js-discussion-note-form") do
fill_in "note_note", with: "Line is correct" fill_in "note_note", with: "Line is correct"
click_button "Add Comment" click_button "Comment"
end end
page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do page.within ".files [id^=diff]:nth-child(2) .note-body > .note-text" do
...@@ -432,7 +432,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps ...@@ -432,7 +432,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
page.within(".js-discussion-note-form") do page.within(".js-discussion-note-form") do
fill_in "note_note", with: "Line is wrong on here" fill_in "note_note", with: "Line is wrong on here"
click_button "Add Comment" click_button "Comment"
end end
end end
...@@ -528,7 +528,7 @@ def init_diff_note ...@@ -528,7 +528,7 @@ def init_diff_note
def leave_comment(message) def leave_comment(message)
page.within(".js-discussion-note-form", visible: true) do page.within(".js-discussion-note-form", visible: true) do
fill_in "note_note", with: message fill_in "note_note", with: message
click_button "Add Comment" click_button "Comment"
end end
page.within(".notes_holder", visible: true) do page.within(".notes_holder", visible: true) do
expect(page).to have_content message expect(page).to have_content message
......
...@@ -77,7 +77,7 @@ class Spinach::Features::ProjectSnippets < Spinach::FeatureSteps ...@@ -77,7 +77,7 @@ class Spinach::Features::ProjectSnippets < Spinach::FeatureSteps
step 'I leave a comment like "Good snippet!"' do step 'I leave a comment like "Good snippet!"' do
page.within('.js-main-target-form') do page.within('.js-main-target-form') do
fill_in "note_note", with: "Good snippet!" fill_in "note_note", with: "Good snippet!"
click_button "Add Comment" click_button "Comment"
end end
end end
......
...@@ -93,14 +93,14 @@ module SharedDiffNote ...@@ -93,14 +93,14 @@ module SharedDiffNote
page.within("form[id$='#{sample_commit.line_code}']") do page.within("form[id$='#{sample_commit.line_code}']") do
fill_in 'note[note]', with: ':smile:' fill_in 'note[note]', with: ':smile:'
click_button('Add Comment') click_button('Comment')
end end
end end
end end
step 'I submit the diff comment' do step 'I submit the diff comment' do
page.within(diff_file_selector) do page.within(diff_file_selector) do
click_button("Add Comment") click_button("Comment")
end end
end end
......
...@@ -182,7 +182,7 @@ def leave_reference_comment(issuable:, from_project_name:) ...@@ -182,7 +182,7 @@ def leave_reference_comment(issuable:, from_project_name:)
page.within('.js-main-target-form') do page.within('.js-main-target-form') do
fill_in 'note[note]', with: "##{issuable.to_reference(project)}" fill_in 'note[note]', with: "##{issuable.to_reference(project)}"
click_button 'Add Comment' click_button 'Comment'
end end
end end
......
...@@ -17,7 +17,7 @@ module SharedNote ...@@ -17,7 +17,7 @@ module SharedNote
step 'I leave a comment like "XML attached"' do step 'I leave a comment like "XML attached"' do
page.within(".js-main-target-form") do page.within(".js-main-target-form") do
fill_in "note[note]", with: "XML attached" fill_in "note[note]", with: "XML attached"
click_button "Add Comment" click_button "Comment"
end end
end end
...@@ -30,7 +30,7 @@ module SharedNote ...@@ -30,7 +30,7 @@ module SharedNote
step 'I submit the comment' do step 'I submit the comment' do
page.within(".js-main-target-form") do page.within(".js-main-target-form") do
click_button "Add Comment" click_button "Comment"
end end
end end
...@@ -115,7 +115,7 @@ module SharedNote ...@@ -115,7 +115,7 @@ module SharedNote
step 'I leave a comment with a header containing "Comment with a header"' do step 'I leave a comment with a header containing "Comment with a header"' do
page.within(".js-main-target-form") do page.within(".js-main-target-form") do
fill_in "note[note]", with: "# Comment with a header" fill_in "note[note]", with: "# Comment with a header"
click_button "Add Comment" click_button "Comment"
sleep 0.05 sleep 0.05
end end
end end
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
it 'should be valid' do it 'should be valid' do
is_expected.to have_css('.js-main-target-form', visible: true, count: 1) is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
expect(find('.js-main-target-form input[type=submit]').value). expect(find('.js-main-target-form input[type=submit]').value).
to eq('Add Comment') to eq('Comment')
page.within('.js-main-target-form') do page.within('.js-main-target-form') do
expect(page).not_to have_link('Cancel') expect(page).not_to have_link('Cancel')
end end
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
page.within('.js-main-target-form') do page.within('.js-main-target-form') do
fill_in 'note[note]', with: 'This is awsome!' fill_in 'note[note]', with: 'This is awsome!'
find('.js-md-preview-button').click find('.js-md-preview-button').click
click_button 'Add Comment' click_button 'Comment'
end end
end end
...@@ -202,7 +202,7 @@ ...@@ -202,7 +202,7 @@
before do before do
page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do page.within("tr[id='#{line_code_2}'] + .js-temp-notes-holder") do
fill_in 'note[note]', with: 'Another comment on line 10' fill_in 'note[note]', with: 'Another comment on line 10'
click_button('Add Comment') click_button('Comment')
end end
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