Commit f698f167 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Added cancel button

- replaced button with GlButton components
parent d4fcc206
...@@ -86,6 +86,7 @@ export default { ...@@ -86,6 +86,7 @@ export default {
}, },
hideForm() { hideForm() {
this.isFormRendered = false; this.isFormRendered = false;
this.discussionComment = '';
}, },
showForm() { showForm() {
this.isFormRendered = true; this.isFormRendered = true;
......
<script> <script>
import { GlButton, GlModal } from '@gitlab/ui';
import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import MarkdownField from '~/vue_shared/components/markdown/field.vue';
export default { export default {
name: 'DesignReplyForm', name: 'DesignReplyForm',
components: { components: {
MarkdownField, MarkdownField,
GlButton,
GlModal,
}, },
props: { props: {
markdownPreviewPath: { markdownPreviewPath: {
...@@ -33,12 +36,19 @@ export default { ...@@ -33,12 +36,19 @@ export default {
submitForm() { submitForm() {
if (this.hasValue) this.$emit('submitForm'); if (this.hasValue) this.$emit('submitForm');
}, },
cancelComment() {
if (this.hasValue) {
this.$refs.cancelCommentModal.show();
} else {
this.$emit('cancelForm');
}
},
}, },
}; };
</script> </script>
<template> <template>
<form class="new-note common-note-form"> <form class="new-note common-note-form" @submit.prevent>
<markdown-field <markdown-field
:markdown-preview-path="markdownPreviewPath" :markdown-preview-path="markdownPreviewPath"
:can-attach-file="false" :can-attach-file="false"
...@@ -46,34 +56,47 @@ export default { ...@@ -46,34 +56,47 @@ export default {
markdown-docs-path="/help/user/markdown" markdown-docs-path="/help/user/markdown"
class="bordered-box" class="bordered-box"
> >
<textarea <template #textarea>
slot="textarea" <textarea
ref="textarea" ref="textarea"
:value="value" :value="value"
class="note-textarea js-gfm-input js-autosize markdown-area" class="note-textarea js-gfm-input js-autosize markdown-area"
dir="auto" dir="auto"
data-supports-quick-actions="false" data-supports-quick-actions="false"
data-qa-selector="note_textarea" data-qa-selector="note_textarea"
:aria-label="__('Description')" :aria-label="__('Description')"
:placeholder="__('Write a comment…')" :placeholder="__('Write a comment…')"
@input="$emit('input', $event.target.value)" @input="$emit('input', $event.target.value)"
@keydown.meta.enter="submitForm" @keydown.meta.enter="submitForm"
@keydown.ctrl.enter="submitForm" @keydown.ctrl.enter="submitForm"
@keyup.esc.stop="$emit('cancelForm')" @keyup.esc.stop="cancelComment"
> >
</textarea> </textarea>
</template>
</markdown-field> </markdown-field>
<div class="note-form-actions"> <div class="note-form-actions d-flex justify-content-between">
<button <gl-button
ref="submitButton"
:disabled="!hasValue || isSaving" :disabled="!hasValue || isSaving"
class="btn btn-success js-comment-button js-comment-submit-button" variant="success"
type="submit" type="submit"
data-track-event="click_button" data-track-event="click_button"
data-qa-selector="save_comment_button" data-qa-selector="save_comment_button"
@click.prevent="$emit('submitForm')" @click="$emit('submitForm')"
> >
{{ __('Save comment') }} {{ __('Comment') }}
</button> </gl-button>
<gl-button ref="cancelButton" @click="cancelComment">{{ __('Cancel') }}</gl-button>
</div> </div>
<gl-modal
ref="cancelCommentModal"
ok-variant="danger"
:title="s__('DesignManagement|Cancel comment confirmation')"
:ok-title="s__('DesignManagement|Discard comment')"
:cancel-title="s__('DesignManagement|Keep comment')"
modal-id="cancel-comment-modal"
@ok="$emit('cancelForm')"
>{{ s__('DesignManagement|Are you sure you want to cancel creating this comment?') }}
</gl-modal>
</form> </form>
</template> </template>
---
title: Add ability to cancel a design discussion
merge_request: 22241
author:
type: added
...@@ -99,4 +99,23 @@ describe('Design discussions component', () => { ...@@ -99,4 +99,23 @@ describe('Design discussions component', () => {
expect(findReplyForm().exists()).toBe(false); expect(findReplyForm().exists()).toBe(false);
}); });
}); });
it('clears the discussion comment on closing comment form', () => {
wrapper.setData({
discussionComment: 'test',
isFormRendered: true,
});
return wrapper.vm
.$nextTick()
.then(() => {
findReplyForm().vm.$emit('cancelForm');
expect(wrapper.vm.discussionComment).toBe('');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(findReplyForm().exists()).toBe(false);
});
});
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlModal } from '@gitlab/ui';
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import DesignReplyForm from 'ee/design_management/components/design_notes/design_reply_form.vue'; import DesignReplyForm from 'ee/design_management/components/design_notes/design_reply_form.vue';
...@@ -6,7 +8,9 @@ describe('Design reply form component', () => { ...@@ -6,7 +8,9 @@ describe('Design reply form component', () => {
let wrapper; let wrapper;
const findTextarea = () => wrapper.find('textarea'); const findTextarea = () => wrapper.find('textarea');
const findSubmitButton = () => wrapper.find('.js-comment-submit-button'); const findSubmitButton = () => wrapper.find({ ref: 'submitButton' });
const findCancelButton = () => wrapper.find({ ref: 'cancelButton' });
const findModal = () => wrapper.find({ ref: 'cancelCommentModal' });
function createComponent(props = {}) { function createComponent(props = {}) {
wrapper = shallowMount(DesignReplyForm, { wrapper = shallowMount(DesignReplyForm, {
...@@ -15,6 +19,7 @@ describe('Design reply form component', () => { ...@@ -15,6 +19,7 @@ describe('Design reply form component', () => {
isSaving: false, isSaving: false,
...props, ...props,
}, },
stubs: { MarkdownField, GlModal },
}); });
} }
...@@ -58,6 +63,18 @@ describe('Design reply form component', () => { ...@@ -58,6 +63,18 @@ describe('Design reply form component', () => {
expect(wrapper.emitted('submitForm')).toBeFalsy(); expect(wrapper.emitted('submitForm')).toBeFalsy();
}); });
}); });
it('emits cancelForm event on pressing escape button on textarea', () => {
findTextarea().trigger('keyup.esc');
expect(wrapper.emitted('cancelForm')).toBeTruthy();
});
it('emits cancelForm event on clicking Cancel button', () => {
findCancelButton().vm.$emit('click');
expect(wrapper.emitted('cancelForm')).toHaveLength(1);
});
}); });
describe('when form has text', () => { describe('when form has text', () => {
...@@ -71,8 +88,8 @@ describe('Design reply form component', () => { ...@@ -71,8 +88,8 @@ describe('Design reply form component', () => {
expect(findSubmitButton().attributes().disabled).toBeFalsy(); expect(findSubmitButton().attributes().disabled).toBeFalsy();
}); });
it('emits submitForm event on button click', () => { it('emits submitForm event on Comment button click', () => {
findSubmitButton().trigger('click'); findSubmitButton().vm.$emit('click');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('submitForm')).toBeTruthy(); expect(wrapper.emitted('submitForm')).toBeTruthy();
...@@ -107,12 +124,23 @@ describe('Design reply form component', () => { ...@@ -107,12 +124,23 @@ describe('Design reply form component', () => {
}); });
}); });
it('emits cancelForm event on pressing escape button on textarea', () => { it('opens confirmation modal on pressing Escape button', () => {
findTextarea().trigger('keyup.esc'); findTextarea().trigger('keyup.esc');
return wrapper.vm.$nextTick().then(() => { expect(findModal().exists()).toBe(true);
expect(wrapper.emitted('cancelForm')).toBeTruthy(); });
});
it('opens confirmation modal on Cancel button click', () => {
findCancelButton().vm.$emit('click');
expect(findModal().exists()).toBe(true);
});
it('emits cancelForm event on modal Ok button click', () => {
findTextarea().trigger('keyup.esc');
findModal().vm.$emit('ok');
expect(wrapper.emitted('cancelForm')).toBeTruthy();
}); });
}); });
}); });
...@@ -199,6 +199,33 @@ describe('Design management design index page', () => { ...@@ -199,6 +199,33 @@ describe('Design management design index page', () => {
}); });
}); });
it('closes the form and clears the comment on canceling form', () => {
setDesign();
wrapper.setData({
design: {
...design,
discussions: {
edges: [],
},
},
annotationCoordinates,
comment: newComment,
});
return wrapper.vm
.$nextTick()
.then(() => {
findDiscussionForm().vm.$emit('cancelForm');
expect(wrapper.vm.comment).toBe('');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(findDiscussionForm().exists()).toBe(false);
});
});
describe('with error', () => { describe('with error', () => {
beforeEach(() => { beforeEach(() => {
setDesign(); setDesign();
...@@ -213,6 +240,7 @@ describe('Design management design index page', () => { ...@@ -213,6 +240,7 @@ describe('Design management design index page', () => {
errorMessage: 'woops', errorMessage: 'woops',
}); });
}); });
it('GlAlert is rendered in correct position with correct content', () => { it('GlAlert is rendered in correct position with correct content', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
......
...@@ -6156,9 +6156,15 @@ msgstr "" ...@@ -6156,9 +6156,15 @@ msgstr ""
msgid "DesignManagement|Adding a design with the same filename replaces the file in a new version." msgid "DesignManagement|Adding a design with the same filename replaces the file in a new version."
msgstr "" msgstr ""
msgid "DesignManagement|Are you sure you want to cancel creating this comment?"
msgstr ""
msgid "DesignManagement|Are you sure you want to delete the selected designs?" msgid "DesignManagement|Are you sure you want to delete the selected designs?"
msgstr "" msgstr ""
msgid "DesignManagement|Cancel comment confirmation"
msgstr ""
msgid "DesignManagement|Could not add a new comment. Please try again." msgid "DesignManagement|Could not add a new comment. Please try again."
msgstr "" msgstr ""
...@@ -6177,6 +6183,9 @@ msgstr "" ...@@ -6177,6 +6183,9 @@ msgstr ""
msgid "DesignManagement|Deselect all" msgid "DesignManagement|Deselect all"
msgstr "" msgstr ""
msgid "DesignManagement|Discard comment"
msgstr ""
msgid "DesignManagement|Error uploading a new design. Please try again." msgid "DesignManagement|Error uploading a new design. Please try again."
msgstr "" msgstr ""
...@@ -6189,6 +6198,9 @@ msgstr "" ...@@ -6189,6 +6198,9 @@ msgstr ""
msgid "DesignManagement|Go to previous design" msgid "DesignManagement|Go to previous design"
msgstr "" msgstr ""
msgid "DesignManagement|Keep comment"
msgstr ""
msgid "DesignManagement|Requested design version does not exist. Showing latest version instead" msgid "DesignManagement|Requested design version does not exist. Showing latest version instead"
msgstr "" msgstr ""
......
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