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

138 lines
3.9 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlSprintf, GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapGetters } from 'vuex';
2020-06-23 00:09:42 +05:30
import { IMAGE_DIFF_POSITION_TYPE } from '~/diffs/constants';
import { sprintf, __ } from '~/locale';
import {
getStartLineNumber,
getEndLineNumber,
getLineClasses,
} from '~/notes/components/multiline_comment_utils';
2021-03-11 19:13:27 +05:30
import resolvedStatusMixin from '../mixins/resolved_status';
2020-06-23 00:09:42 +05:30
export default {
components: {
2020-11-24 15:15:51 +05:30
GlIcon,
2020-06-23 00:09:42 +05:30
GlSprintf,
},
2021-03-11 19:13:27 +05:30
mixins: [resolvedStatusMixin],
2020-06-23 00:09:42 +05:30
props: {
draft: {
type: Object,
required: true,
},
isLast: {
type: Boolean,
required: true,
},
},
computed: {
...mapGetters('diffs', ['getDiffFileByHash']),
...mapGetters(['getDiscussion']),
iconName() {
return this.isDiffDiscussion || this.draft.line_code ? 'doc-text' : 'comment';
},
discussion() {
return this.getDiscussion(this.draft.discussion_id);
},
isDiffDiscussion() {
return this.discussion && this.discussion.diff_discussion;
},
titleText() {
const file = this.discussion ? this.discussion.diff_file : this.draft;
2021-04-29 21:17:54 +05:30
if (file?.file_path) {
2020-06-23 00:09:42 +05:30
return file.file_path;
}
2021-04-29 21:17:54 +05:30
if (this.discussion) {
2021-09-04 01:27:46 +05:30
return sprintf(
__("%{authorsName}'s thread"),
{
authorsName: this.discussion.notes.find((note) => !note.system).author.name,
},
false,
);
2021-04-29 21:17:54 +05:30
}
return __('Your new comment');
2020-06-23 00:09:42 +05:30
},
linePosition() {
2020-07-28 23:09:34 +05:30
if (this.position?.position_type === IMAGE_DIFF_POSITION_TYPE) {
2020-06-23 00:09:42 +05:30
// eslint-disable-next-line @gitlab/require-i18n-strings
2020-07-28 23:09:34 +05:30
return `${this.position.x}x ${this.position.y}y`;
2020-06-23 00:09:42 +05:30
}
2020-07-28 23:09:34 +05:30
return this.position?.new_line || this.position?.old_line;
2020-06-23 00:09:42 +05:30
},
content() {
const el = document.createElement('div');
el.innerHTML = this.draft.note_html;
return el.textContent;
},
showLinePosition() {
return this.draft.file_hash || this.isDiffDiscussion;
},
2020-07-28 23:09:34 +05:30
position() {
return this.draft.position || this.discussion.position;
},
2020-06-23 00:09:42 +05:30
startLineNumber() {
2021-03-11 19:13:27 +05:30
if (this.position?.position_type === IMAGE_DIFF_POSITION_TYPE) {
// eslint-disable-next-line @gitlab/require-i18n-strings
return `${this.position.x}x ${this.position.y}y`;
}
2020-07-28 23:09:34 +05:30
return getStartLineNumber(this.position?.line_range);
2020-06-23 00:09:42 +05:30
},
endLineNumber() {
2020-07-28 23:09:34 +05:30
return getEndLineNumber(this.position?.line_range);
2020-06-23 00:09:42 +05:30
},
},
methods: {
getLineClasses(lineNumber) {
return getLineClasses(lineNumber);
},
},
showStaysResolved: false,
};
</script>
<template>
2021-01-03 14:25:43 +05:30
<span>
2020-06-23 00:09:42 +05:30
<span class="review-preview-item-header">
2020-11-24 15:15:51 +05:30
<gl-icon class="flex-shrink-0" :name="iconName" />
2021-03-11 19:13:27 +05:30
<span class="bold text-nowrap gl-align-items-center">
2021-04-29 21:17:54 +05:30
<span class="review-preview-item-header-text block-truncated gl-ml-2">
2020-06-23 00:09:42 +05:30
{{ titleText }}
</span>
<template v-if="showLinePosition">
2021-03-11 19:13:27 +05:30
<template v-if="startLineNumber === endLineNumber">
2020-06-23 00:09:42 +05:30
:<span :class="getLineClasses(startLineNumber)">{{ startLineNumber }}</span>
</template>
<gl-sprintf v-else :message="__(':%{startLine} to %{endLine}')">
<template #startLine>
<span class="gl-mr-2" :class="getLineClasses(startLineNumber)">{{
startLineNumber
}}</span>
</template>
<template #endLine>
<span class="gl-ml-2" :class="getLineClasses(endLineNumber)">{{
endLineNumber
}}</span>
</template>
</gl-sprintf>
</template>
</span>
</span>
<span class="review-preview-item-content">
<p>{{ content }}</p>
</span>
<span
v-if="draft.discussion_id && resolvedStatusMessage"
class="review-preview-item-footer draft-note-resolution p-0"
>
2020-11-24 15:15:51 +05:30
<gl-icon class="gl-mr-3" name="status_success" /> {{ resolvedStatusMessage }}
2020-06-23 00:09:42 +05:30
</span>
2021-01-03 14:25:43 +05:30
</span>
2020-06-23 00:09:42 +05:30
</template>