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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

132 lines
3.5 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlButton, GlBadge } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2023-03-04 22:38:38 +05:30
import SafeHtml from '~/vue_shared/directives/safe_html';
2022-08-13 15:12:31 +05:30
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
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,
2022-04-04 11:22:00 +05:30
GlBadge,
2020-06-23 00:09:42 +05:30
},
2021-12-11 22:18:48 +05:30
directives: {
2023-03-04 22:38:38 +05:30
SafeHtml,
2021-12-11 22:18:48 +05:30
},
2022-08-13 15:12:31 +05:30
mixins: [glFeatureFlagMixin()],
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>
2023-03-04 22:38:38 +05:30
<noteable-note
:note="draft"
:line="line"
:discussion-root="true"
:class="{ 'gl-mb-0!': glFeatures.mrReviewSubmitComment }"
class="draft-note-component draft-note"
@handleEdit="handleEditing"
@cancelForm="handleNotEditing"
@updateSuccess="handleNotEditing"
@handleDeleteNote="deleteDraft"
@handleUpdateNote="update"
@toggleResolveStatus="toggleResolveDiscussion(draft.id)"
@mouseenter.native="handleMouseEnter(draft)"
@mouseleave.native="handleMouseLeave(draft)"
2020-07-28 23:09:34 +05:30
>
2023-03-04 22:38:38 +05:30
<template #note-header-info>
<gl-badge variant="warning" class="gl-mr-2">{{ __('Pending') }}</gl-badge>
</template>
<template v-if="!isEditingDraft" #after-note-body>
2020-06-23 00:09:42 +05:30
<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>
2022-08-27 11:52:29 +05:30
<p v-if="!glFeatures.mrReviewSubmitComment" class="draft-note-actions d-flex">
2022-04-04 11:22:00 +05:30
<publish-button
:show-count="true"
:should-publish="false"
category="secondary"
:disabled="isPublishingDraft(draft.id)"
/>
2020-10-24 23:57:45 +05:30
<gl-button
2022-04-04 11:22:00 +05:30
:disabled="isPublishing"
:loading="isPublishingDraft(draft.id)"
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>
2023-03-04 22:38:38 +05:30
</noteable-note>
2020-06-23 00:09:42 +05:30
</template>