debian-mirror-gitlab/app/assets/javascripts/batch_comments/components/draft_note.vue

131 lines
3.3 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2021-12-11 22:18:48 +05:30
import { GlButton, GlSafeHtmlDirective } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2020-06-23 00:09:42 +05:30
import NoteableNote from '~/notes/components/noteable_note.vue';
import PublishButton from './publish_button.vue';
export default {
components: {
NoteableNote,
PublishButton,
2020-10-24 23:57:45 +05:30
GlButton,
2020-06-23 00:09:42 +05:30
},
2021-12-11 22:18:48 +05:30
directives: {
SafeHtml: GlSafeHtmlDirective,
},
2020-06-23 00:09:42 +05:30
props: {
draft: {
type: Object,
required: true,
},
line: {
type: Object,
required: false,
default: null,
},
},
data() {
return {
isEditingDraft: false,
};
},
computed: {
...mapState('batchComments', ['isPublishing']),
...mapGetters('batchComments', ['isPublishingDraft']),
draftCommands() {
return this.draft.references.commands;
},
},
mounted() {
if (window.location.hash && window.location.hash === `#note_${this.draft.id}`) {
this.scrollToDraft(this.draft);
}
},
methods: {
...mapActions('batchComments', [
'deleteDraft',
'updateDraft',
'publishSingleDraft',
'scrollToDraft',
'toggleResolveDiscussion',
]),
2020-07-28 23:09:34 +05:30
...mapActions(['setSelectedCommentPositionHover']),
2020-06-23 00:09:42 +05:30
update(data) {
this.updateDraft(data);
},
publishNow() {
this.publishSingleDraft(this.draft.id);
},
handleEditing() {
this.isEditingDraft = true;
},
handleNotEditing() {
this.isEditingDraft = false;
},
2020-10-24 23:57:45 +05:30
handleMouseEnter(draft) {
2021-03-11 19:13:27 +05:30
if (draft.position) {
2020-10-24 23:57:45 +05:30
this.setSelectedCommentPositionHover(draft.position.line_range);
}
},
handleMouseLeave(draft) {
2021-03-11 19:13:27 +05:30
// Even though position isn't used here we still don't want to unnecessarily call a mutation
2020-10-24 23:57:45 +05:30
// The lack of position tells us that highlighting is irrelevant in this context
2021-03-11 19:13:27 +05:30
if (draft.position) {
2020-10-24 23:57:45 +05:30
this.setSelectedCommentPositionHover();
}
},
2020-06-23 00:09:42 +05:30
},
2021-12-11 22:18:48 +05:30
safeHtmlConfig: {
2022-01-26 12:08:38 +05:30
ADD_TAGS: ['use', 'gl-emoji', 'copy-code'],
2021-12-11 22:18:48 +05:30
},
2020-06-23 00:09:42 +05:30
};
</script>
<template>
2020-07-28 23:09:34 +05:30
<article
class="draft-note-component note-wrapper"
2020-10-24 23:57:45 +05:30
@mouseenter="handleMouseEnter(draft)"
@mouseleave="handleMouseLeave(draft)"
2020-07-28 23:09:34 +05:30
>
2020-06-23 00:09:42 +05:30
<ul class="notes draft-notes">
<noteable-note
:note="draft"
:line="line"
2020-07-28 23:09:34 +05:30
:discussion-root="true"
2020-06-23 00:09:42 +05:30
class="draft-note"
@handleEdit="handleEditing"
@cancelForm="handleNotEditing"
@updateSuccess="handleNotEditing"
@handleDeleteNote="deleteDraft"
@handleUpdateNote="update"
@toggleResolveStatus="toggleResolveDiscussion(draft.id)"
>
2021-09-30 23:02:18 +05:30
<template #note-header-info>
<strong class="badge draft-pending-label gl-mr-2">
{{ __('Pending') }}
</strong>
</template>
2020-06-23 00:09:42 +05:30
</noteable-note>
</ul>
<template v-if="!isEditingDraft">
<div
v-if="draftCommands"
2021-12-11 22:18:48 +05:30
v-safe-html:[$options.safeHtmlConfig]="draftCommands"
2020-06-23 00:09:42 +05:30
class="referenced-commands draft-note-commands"
></div>
<p class="draft-note-actions d-flex">
2020-10-24 23:57:45 +05:30
<publish-button :show-count="true" :should-publish="false" category="secondary" />
<gl-button
2020-06-23 00:09:42 +05:30
ref="publishNowButton"
:loading="isPublishingDraft(draft.id) || isPublishing"
2020-10-24 23:57:45 +05:30
class="gl-ml-3"
2020-06-23 00:09:42 +05:30
@click="publishNow"
2020-10-24 23:57:45 +05:30
>
{{ __('Add comment now') }}
</gl-button>
2020-06-23 00:09:42 +05:30
</p>
</template>
</article>
</template>