2020-05-24 23:13:21 +05:30
|
|
|
<script>
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlButton, GlModal } from '@gitlab/ui';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { helpPagePath } from '~/helpers/help_page_helper';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { s__ } from '~/locale';
|
|
|
|
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DesignReplyForm',
|
|
|
|
components: {
|
|
|
|
MarkdownField,
|
2020-11-24 15:15:51 +05:30
|
|
|
GlButton,
|
2020-05-24 23:13:21 +05:30
|
|
|
GlModal,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
markdownPreviewPath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isSaving: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isNewComment: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
formText: this.value,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
hasValue() {
|
|
|
|
return this.value.trim().length > 0;
|
|
|
|
},
|
|
|
|
modalSettings() {
|
|
|
|
if (this.isNewComment) {
|
|
|
|
return {
|
|
|
|
title: s__('DesignManagement|Cancel comment confirmation'),
|
|
|
|
okTitle: s__('DesignManagement|Discard comment'),
|
|
|
|
cancelTitle: s__('DesignManagement|Keep comment'),
|
|
|
|
content: s__('DesignManagement|Are you sure you want to cancel creating this comment?'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
title: s__('DesignManagement|Cancel comment update confirmation'),
|
|
|
|
okTitle: s__('DesignManagement|Cancel changes'),
|
|
|
|
cancelTitle: s__('DesignManagement|Keep changes'),
|
|
|
|
content: s__('DesignManagement|Are you sure you want to cancel changes to this comment?'),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
buttonText() {
|
|
|
|
return this.isNewComment
|
|
|
|
? s__('DesignManagement|Comment')
|
|
|
|
: s__('DesignManagement|Save comment');
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
markdownDocsPath() {
|
|
|
|
return helpPagePath('user/markdown');
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
mounted() {
|
2020-07-28 23:09:34 +05:30
|
|
|
this.focusInput();
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
submitForm() {
|
2020-11-24 15:15:51 +05:30
|
|
|
if (this.hasValue) this.$emit('submit-form');
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
cancelComment() {
|
|
|
|
if (this.hasValue && this.formText !== this.value) {
|
|
|
|
this.$refs.cancelCommentModal.show();
|
|
|
|
} else {
|
2020-11-24 15:15:51 +05:30
|
|
|
this.$emit('cancel-form');
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
focusInput() {
|
|
|
|
this.$refs.textarea.focus();
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<form class="new-note common-note-form" @submit.prevent>
|
|
|
|
<markdown-field
|
|
|
|
:markdown-preview-path="markdownPreviewPath"
|
|
|
|
:can-attach-file="false"
|
|
|
|
:enable-autocomplete="true"
|
|
|
|
:textarea-value="value"
|
2021-03-08 18:12:59 +05:30
|
|
|
:markdown-docs-path="markdownDocsPath"
|
2020-05-24 23:13:21 +05:30
|
|
|
class="bordered-box"
|
|
|
|
>
|
|
|
|
<template #textarea>
|
|
|
|
<textarea
|
|
|
|
ref="textarea"
|
|
|
|
:value="value"
|
|
|
|
class="note-textarea js-gfm-input js-autosize markdown-area"
|
|
|
|
dir="auto"
|
|
|
|
data-supports-quick-actions="false"
|
|
|
|
data-qa-selector="note_textarea"
|
|
|
|
:aria-label="__('Description')"
|
|
|
|
:placeholder="__('Write a comment…')"
|
|
|
|
@input="$emit('input', $event.target.value)"
|
|
|
|
@keydown.meta.enter="submitForm"
|
|
|
|
@keydown.ctrl.enter="submitForm"
|
|
|
|
@keyup.esc.stop="cancelComment"
|
|
|
|
>
|
|
|
|
</textarea>
|
|
|
|
</template>
|
|
|
|
</markdown-field>
|
2021-01-29 00:20:46 +05:30
|
|
|
<slot name="resolve-checkbox"></slot>
|
2021-06-08 01:23:25 +05:30
|
|
|
<div class="note-form-actions gl-display-flex">
|
2020-11-24 15:15:51 +05:30
|
|
|
<gl-button
|
2020-05-24 23:13:21 +05:30
|
|
|
ref="submitButton"
|
|
|
|
:disabled="!hasValue || isSaving"
|
2021-06-08 01:23:25 +05:30
|
|
|
class="gl-mr-3 gl-w-auto!"
|
2020-11-24 15:15:51 +05:30
|
|
|
category="primary"
|
2021-06-08 01:23:25 +05:30
|
|
|
variant="confirm"
|
2020-05-24 23:13:21 +05:30
|
|
|
type="submit"
|
2021-11-11 11:23:49 +05:30
|
|
|
data-track-action="click_button"
|
2020-05-24 23:13:21 +05:30
|
|
|
data-qa-selector="save_comment_button"
|
2020-11-24 15:15:51 +05:30
|
|
|
@click="$emit('submit-form')"
|
2020-05-24 23:13:21 +05:30
|
|
|
>
|
|
|
|
{{ buttonText }}
|
2020-11-24 15:15:51 +05:30
|
|
|
</gl-button>
|
2021-06-08 01:23:25 +05:30
|
|
|
<gl-button
|
|
|
|
ref="cancelButton"
|
|
|
|
class="gl-w-auto!"
|
|
|
|
variant="default"
|
|
|
|
category="primary"
|
|
|
|
@click="cancelComment"
|
|
|
|
>{{ __('Cancel') }}</gl-button
|
|
|
|
>
|
2020-05-24 23:13:21 +05:30
|
|
|
</div>
|
|
|
|
<gl-modal
|
|
|
|
ref="cancelCommentModal"
|
|
|
|
ok-variant="danger"
|
|
|
|
:title="modalSettings.title"
|
|
|
|
:ok-title="modalSettings.okTitle"
|
|
|
|
:cancel-title="modalSettings.cancelTitle"
|
|
|
|
modal-id="cancel-comment-modal"
|
2020-11-24 15:15:51 +05:30
|
|
|
@ok="$emit('cancel-form')"
|
2020-05-24 23:13:21 +05:30
|
|
|
>{{ modalSettings.content }}
|
|
|
|
</gl-modal>
|
|
|
|
</form>
|
|
|
|
</template>
|