summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/note_form.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/notes/components/note_form.vue')
-rw-r--r--app/assets/javascripts/notes/components/note_form.vue224
1 files changed, 116 insertions, 108 deletions
diff --git a/app/assets/javascripts/notes/components/note_form.vue b/app/assets/javascripts/notes/components/note_form.vue
index 1a13fdbeb7c..c59a2e7a406 100644
--- a/app/assets/javascripts/notes/components/note_form.vue
+++ b/app/assets/javascripts/notes/components/note_form.vue
@@ -1,128 +1,136 @@
<script>
- import { mapGetters, mapActions } from 'vuex';
- import eventHub from '../event_hub';
- import issueWarning from '../../vue_shared/components/issue/issue_warning.vue';
- import markdownField from '../../vue_shared/components/markdown/field.vue';
- import issuableStateMixin from '../mixins/issuable_state';
- import resolvable from '../mixins/resolvable';
+import { mapGetters, mapActions } from 'vuex';
+import eventHub from '../event_hub';
+import issueWarning from '../../vue_shared/components/issue/issue_warning.vue';
+import markdownField from '../../vue_shared/components/markdown/field.vue';
+import issuableStateMixin from '../mixins/issuable_state';
+import resolvable from '../mixins/resolvable';
- export default {
- name: 'IssueNoteForm',
- components: {
- issueWarning,
- markdownField,
+export default {
+ name: 'IssueNoteForm',
+ components: {
+ issueWarning,
+ markdownField,
+ },
+ mixins: [issuableStateMixin, resolvable],
+ props: {
+ noteBody: {
+ type: String,
+ required: false,
+ default: '',
},
- mixins: [
- issuableStateMixin,
- resolvable,
- ],
- props: {
- noteBody: {
- type: String,
- required: false,
- default: '',
- },
- noteId: {
- type: Number,
- required: false,
- default: 0,
- },
- saveButtonTitle: {
- type: String,
- required: false,
- default: 'Save comment',
- },
- note: {
- type: Object,
- required: false,
- default: () => ({}),
- },
- isEditing: {
- type: Boolean,
- required: true,
- },
+ noteId: {
+ type: Number,
+ required: false,
+ default: 0,
},
- data() {
- return {
- updatedNoteBody: this.noteBody,
- conflictWhileEditing: false,
- isSubmitting: false,
- isResolving: false,
- resolveAsThread: true,
- };
+ saveButtonTitle: {
+ type: String,
+ required: false,
+ default: 'Save comment',
},
- computed: {
- ...mapGetters([
- 'getDiscussionLastNote',
- 'getNoteableData',
- 'getNoteableDataByProp',
- 'getNotesDataByProp',
- 'getUserDataByProp',
- ]),
- noteHash() {
- return `#note_${this.noteId}`;
- },
- markdownPreviewPath() {
- return this.getNoteableDataByProp('preview_note_path');
- },
- markdownDocsPath() {
- return this.getNotesDataByProp('markdownDocsPath');
- },
- quickActionsDocsPath() {
- return !this.isEditing ? this.getNotesDataByProp('quickActionsDocsPath') : undefined;
- },
- currentUserId() {
- return this.getUserDataByProp('id');
- },
- isDisabled() {
- return !this.updatedNoteBody.length || this.isSubmitting;
- },
+ note: {
+ type: Object,
+ required: false,
+ default: () => ({}),
},
- watch: {
- noteBody() {
- if (this.updatedNoteBody === this.noteBody) {
- this.updatedNoteBody = this.noteBody;
- } else {
- this.conflictWhileEditing = true;
- }
- },
+ isEditing: {
+ type: Boolean,
+ required: true,
+ },
+ },
+ data() {
+ return {
+ updatedNoteBody: this.noteBody,
+ conflictWhileEditing: false,
+ isSubmitting: false,
+ isResolving: false,
+ resolveAsThread: true,
+ };
+ },
+ computed: {
+ ...mapGetters([
+ 'getDiscussionLastNote',
+ 'getNoteableData',
+ 'getNoteableDataByProp',
+ 'getNotesDataByProp',
+ 'getUserDataByProp',
+ ]),
+ noteHash() {
+ return `#note_${this.noteId}`;
+ },
+ markdownPreviewPath() {
+ return this.getNoteableDataByProp('preview_note_path');
+ },
+ markdownDocsPath() {
+ return this.getNotesDataByProp('markdownDocsPath');
+ },
+ quickActionsDocsPath() {
+ return !this.isEditing
+ ? this.getNotesDataByProp('quickActionsDocsPath')
+ : undefined;
},
- mounted() {
- this.$refs.textarea.focus();
+ currentUserId() {
+ return this.getUserDataByProp('id');
},
- methods: {
- ...mapActions([
- 'toggleResolveNote',
- ]),
- handleUpdate(shouldResolve) {
- const beforeSubmitDiscussionState = this.discussionResolved;
- this.isSubmitting = true;
+ isDisabled() {
+ return !this.updatedNoteBody.length || this.isSubmitting;
+ },
+ },
+ watch: {
+ noteBody() {
+ if (this.updatedNoteBody === this.noteBody) {
+ this.updatedNoteBody = this.noteBody;
+ } else {
+ this.conflictWhileEditing = true;
+ }
+ },
+ },
+ mounted() {
+ this.$refs.textarea.focus();
+ },
+ methods: {
+ ...mapActions(['toggleResolveNote']),
+ handleUpdate(shouldResolve) {
+ const beforeSubmitDiscussionState = this.discussionResolved;
+ this.isSubmitting = true;
- this.$emit('handleFormUpdate', this.updatedNoteBody, this.$refs.editNoteForm, () => {
+ this.$emit(
+ 'handleFormUpdate',
+ this.updatedNoteBody,
+ this.$refs.editNoteForm,
+ () => {
this.isSubmitting = false;
if (shouldResolve) {
this.resolveHandler(beforeSubmitDiscussionState);
}
- });
- },
- editMyLastNote() {
- if (this.updatedNoteBody === '') {
- const lastNoteInDiscussion = this.getDiscussionLastNote(this.updatedNoteBody);
+ },
+ );
+ },
+ editMyLastNote() {
+ if (this.updatedNoteBody === '') {
+ const lastNoteInDiscussion = this.getDiscussionLastNote(
+ this.updatedNoteBody,
+ );
- if (lastNoteInDiscussion) {
- eventHub.$emit('enterEditMode', {
- noteId: lastNoteInDiscussion.id,
- });
- }
+ if (lastNoteInDiscussion) {
+ eventHub.$emit('enterEditMode', {
+ noteId: lastNoteInDiscussion.id,
+ });
}
- },
- cancelHandler(shouldConfirm = false) {
- // Sends information about confirm message and if the textarea has changed
- this.$emit('cancelFormEdition', shouldConfirm, this.noteBody !== this.updatedNoteBody);
- },
+ }
+ },
+ cancelHandler(shouldConfirm = false) {
+ // Sends information about confirm message and if the textarea has changed
+ this.$emit(
+ 'cancelFormEdition',
+ shouldConfirm,
+ this.noteBody !== this.updatedNoteBody,
+ );
},
- };
+ },
+};
</script>
<template>