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

127 lines
3.4 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2020-11-24 15:15:51 +05:30
/* eslint-disable vue/no-v-html */
2020-06-23 00:09:42 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2020-10-24 23:57:45 +05:30
import { GlButton } from '@gitlab/ui';
2020-06-23 00:09:42 +05:30
import NoteableNote from '~/notes/components/noteable_note.vue';
import PublishButton from './publish_button.vue';
2020-10-24 23:57:45 +05:30
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2020-06-23 00:09:42 +05:30
export default {
components: {
NoteableNote,
PublishButton,
2020-10-24 23:57:45 +05:30
GlButton,
2020-06-23 00:09:42 +05:30
},
2020-10-24 23:57:45 +05:30
mixins: [glFeatureFlagsMixin()],
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) {
if (this.glFeatures.multilineComments && draft.position) {
this.setSelectedCommentPositionHover(draft.position.line_range);
}
},
handleMouseLeave(draft) {
// Even though position isn't used here we still don't want to unecessarily call a mutation
// The lack of position tells us that highlighting is irrelevant in this context
if (this.glFeatures.multilineComments && draft.position) {
this.setSelectedCommentPositionHover();
}
},
2020-06-23 00:09:42 +05:30
},
};
</script>
<template>
2020-07-28 23:09:34 +05:30
<article
2020-10-24 23:57:45 +05:30
role="article"
2020-07-28 23:09:34 +05:30
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)"
>
2020-07-28 23:09:34 +05:30
<strong slot="note-header-info" class="badge draft-pending-label gl-mr-2">
2020-06-23 00:09:42 +05:30
{{ __('Pending') }}
</strong>
</noteable-note>
</ul>
<template v-if="!isEditingDraft">
<div
v-if="draftCommands"
class="referenced-commands draft-note-commands"
v-html="draftCommands"
></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>