Commit 627ace3a authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'jnnkl-modal-noteable-note' into 'master'

Replace window.confirm with GlModal for noteable notes delete and edit

See merge request gitlab-org/gitlab!78879
parents 765884f5 67679f46
...@@ -3,6 +3,7 @@ import { GlSprintf, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlSprintf, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
import $ from 'jquery'; import $ from 'jquery';
import { escape, isEmpty } from 'lodash'; import { escape, isEmpty } from 'lodash';
import { mapGetters, mapActions } from 'vuex'; import { mapGetters, mapActions } from 'vuex';
import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
import { INLINE_DIFF_LINES_KEY } from '~/diffs/constants'; import { INLINE_DIFF_LINES_KEY } from '~/diffs/constants';
import createFlash from '~/flash'; import createFlash from '~/flash';
import httpStatusCodes from '~/lib/utils/http_status'; import httpStatusCodes from '~/lib/utils/http_status';
...@@ -243,14 +244,18 @@ export default { ...@@ -243,14 +244,18 @@ export default {
this.setSelectedCommentPositionHover(); this.setSelectedCommentPositionHover();
this.$emit('handleEdit'); this.$emit('handleEdit');
}, },
deleteHandler() { async deleteHandler() {
const typeOfComment = this.note.isDraft ? __('pending comment') : __('comment'); const typeOfComment = this.note.isDraft ? __('pending comment') : __('comment');
if (
// eslint-disable-next-line no-alert const msg = sprintf(__('Are you sure you want to delete this %{typeOfComment}?'), {
window.confirm( typeOfComment,
sprintf(__('Are you sure you want to delete this %{typeOfComment}?'), { typeOfComment }), });
) const confirmed = await confirmAction(msg, {
) { primaryBtnVariant: 'danger',
primaryBtnText: __('Delete Comment'),
});
if (confirmed) {
this.isDeleting = true; this.isDeleting = true;
this.$emit('handleDeleteNote', this.note); this.$emit('handleDeleteNote', this.note);
...@@ -345,10 +350,11 @@ export default { ...@@ -345,10 +350,11 @@ export default {
parent: this.$el, parent: this.$el,
}); });
}, },
formCancelHandler({ shouldConfirm, isDirty }) { async formCancelHandler({ shouldConfirm, isDirty }) {
if (shouldConfirm && isDirty) { if (shouldConfirm && isDirty) {
// eslint-disable-next-line no-alert const msg = __('Are you sure you want to cancel editing this comment?');
if (!window.confirm(__('Are you sure you want to cancel editing this comment?'))) return; const confirmed = await confirmAction(msg);
if (!confirmed) return;
} }
this.$refs.noteBody.resetAutoSave(); this.$refs.noteBody.resetAutoSave();
if (this.oldContent) { if (this.oldContent) {
......
...@@ -64,7 +64,11 @@ RSpec.describe 'Merge request > Batch comments', :js do ...@@ -64,7 +64,11 @@ RSpec.describe 'Merge request > Batch comments', :js do
it 'deletes draft note' do it 'deletes draft note' do
write_diff_comment write_diff_comment
accept_alert { find('.js-note-delete').click } find('.js-note-delete').click
page.within('.modal') do
click_button('Delete Comment', match: :first)
end
wait_for_requests wait_for_requests
......
...@@ -238,8 +238,11 @@ RSpec.describe 'User comments on a diff', :js do ...@@ -238,8 +238,11 @@ RSpec.describe 'User comments on a diff', :js do
page.within('.diff-file:nth-of-type(1) .discussion .note') do page.within('.diff-file:nth-of-type(1) .discussion .note') do
find('.more-actions').click find('.more-actions').click
find('.more-actions .dropdown-menu li', match: :first) find('.more-actions .dropdown-menu li', match: :first)
find('.js-note-delete').click
end
accept_confirm { find('.js-note-delete').click } page.within('.modal') do
click_button('Delete Comment', match: :first)
end end
page.within('.merge-request-tabs') do page.within('.merge-request-tabs') do
......
...@@ -103,7 +103,7 @@ RSpec.describe 'Merge request > User posts diff notes', :js do ...@@ -103,7 +103,7 @@ RSpec.describe 'Merge request > User posts diff notes', :js do
it 'allows commenting' do it 'allows commenting' do
should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]')) should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"]'))
accept_confirm do accept_gl_confirm(button_text: 'Delete Comment') do
first('button.more-actions-toggle').click first('button.more-actions-toggle').click
first('.js-note-delete').click first('.js-note-delete').click
end end
......
...@@ -165,11 +165,13 @@ RSpec.describe 'Merge request > User posts notes', :js do ...@@ -165,11 +165,13 @@ RSpec.describe 'Merge request > User posts notes', :js do
it 'resets the edit note form textarea with the original content of the note if cancelled' do it 'resets the edit note form textarea with the original content of the note if cancelled' do
within('.current-note-edit-form') do within('.current-note-edit-form') do
fill_in 'note[note]', with: 'Some new content' fill_in 'note[note]', with: 'Some new content'
accept_confirm do
find('[data-testid="cancel"]').click find('[data-testid="cancel"]').click
end end
page.within('.modal') do
click_button('OK', match: :first)
end end
expect(find('.js-note-text').text).to eq '' expect(find('.js-note-text').text).to eq ''
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
include Spec::Support::Helpers::ModalHelpers # rubocop:disable Style/MixinUsage
RSpec.describe 'Merge request > User sees avatars on diff notes', :js do RSpec.describe 'Merge request > User sees avatars on diff notes', :js do
include NoteInteractionHelpers include NoteInteractionHelpers
include Spec::Support::Helpers::ModalHelpers
let(:project) { create(:project, :public, :repository) } let(:project) { create(:project, :public, :repository) }
let(:user) { project.creator } let(:user) { project.creator }
...@@ -121,8 +123,8 @@ RSpec.describe 'Merge request > User sees avatars on diff notes', :js do ...@@ -121,8 +123,8 @@ RSpec.describe 'Merge request > User sees avatars on diff notes', :js do
it 'removes avatar when note is deleted' do it 'removes avatar when note is deleted' do
open_more_actions_dropdown(note) open_more_actions_dropdown(note)
page.within find(".note-row-#{note.id}") do accept_gl_confirm(button_text: 'Delete Comment') do
accept_confirm { find('.js-note-delete').click } find(".note-row-#{note.id} .js-note-delete").click
end end
wait_for_requests wait_for_requests
......
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