2018-11-08 19:23:39 +05:30
|
|
|
<script>
|
2019-02-15 15:39:39 +05:30
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { GlIcon } from '@gitlab/ui';
|
|
|
|
import { getParameterByName, parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
import DiffGutterAvatars from './diff_gutter_avatars.vue';
|
2018-11-08 19:23:39 +05:30
|
|
|
import {
|
|
|
|
MATCH_LINE_TYPE,
|
|
|
|
CONTEXT_LINE_TYPE,
|
2020-03-13 15:44:24 +05:30
|
|
|
LINE_POSITION_RIGHT,
|
2018-11-08 19:23:39 +05:30
|
|
|
EMPTY_CELL_TYPE,
|
|
|
|
OLD_LINE_TYPE,
|
|
|
|
OLD_NO_NEW_LINE_TYPE,
|
|
|
|
NEW_NO_NEW_LINE_TYPE,
|
|
|
|
LINE_HOVER_CLASS_NAME,
|
|
|
|
LINE_UNFOLD_CLASS_NAME,
|
|
|
|
} from '../constants';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-03-13 15:44:24 +05:30
|
|
|
DiffGutterAvatars,
|
|
|
|
GlIcon,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
line: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
fileHash: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
contextLinesPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-02-15 15:39:39 +05:30
|
|
|
isHighlighted: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
showCommentButton: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
linePosition: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
lineType: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
isContentLine: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isBottom: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isHover: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['isLoggedIn']),
|
2020-03-13 15:44:24 +05:30
|
|
|
lineCode() {
|
|
|
|
return (
|
|
|
|
this.line.line_code ||
|
|
|
|
(this.line.left && this.line.left.line_code) ||
|
|
|
|
(this.line.right && this.line.right.line_code)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
lineHref() {
|
|
|
|
return `#${this.line.line_code || ''}`;
|
|
|
|
},
|
|
|
|
shouldShowCommentButton() {
|
|
|
|
return (
|
|
|
|
this.isHover &&
|
|
|
|
!this.isMatchLine &&
|
|
|
|
!this.isContextLine &&
|
|
|
|
!this.isMetaLine &&
|
|
|
|
!this.hasDiscussions
|
|
|
|
);
|
|
|
|
},
|
|
|
|
hasDiscussions() {
|
|
|
|
return this.line.discussions && this.line.discussions.length > 0;
|
|
|
|
},
|
|
|
|
shouldShowAvatarsOnGutter() {
|
|
|
|
if (!this.line.type && this.linePosition === LINE_POSITION_RIGHT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.showCommentButton && this.hasDiscussions;
|
|
|
|
},
|
|
|
|
shouldRenderCommentButton() {
|
|
|
|
const isDiffHead = parseBoolean(getParameterByName('diff_head'));
|
|
|
|
return !isDiffHead && this.isLoggedIn && this.showCommentButton;
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
isMatchLine() {
|
2018-11-20 20:47:30 +05:30
|
|
|
return this.line.type === MATCH_LINE_TYPE;
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
isContextLine() {
|
2018-11-20 20:47:30 +05:30
|
|
|
return this.line.type === CONTEXT_LINE_TYPE;
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
isMetaLine() {
|
2018-11-20 20:47:30 +05:30
|
|
|
const { type } = this.line;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
return (
|
|
|
|
type === OLD_NO_NEW_LINE_TYPE || type === NEW_NO_NEW_LINE_TYPE || type === EMPTY_CELL_TYPE
|
|
|
|
);
|
|
|
|
},
|
|
|
|
classNameMap() {
|
2018-11-20 20:47:30 +05:30
|
|
|
const { type } = this.line;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
return [
|
|
|
|
type,
|
|
|
|
{
|
|
|
|
hll: this.isHighlighted,
|
|
|
|
[LINE_UNFOLD_CLASS_NAME]: this.isMatchLine,
|
|
|
|
[LINE_HOVER_CLASS_NAME]:
|
|
|
|
this.isLoggedIn &&
|
|
|
|
this.isHover &&
|
|
|
|
!this.isMatchLine &&
|
|
|
|
!this.isContextLine &&
|
|
|
|
!this.isMetaLine,
|
|
|
|
},
|
|
|
|
];
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
lineNumber() {
|
2019-02-15 15:39:39 +05:30
|
|
|
return this.lineType === OLD_LINE_TYPE ? this.line.old_line : this.line.new_line;
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['showCommentForm', 'setHighlightedRow', 'toggleLineDiscussions']),
|
|
|
|
handleCommentButton() {
|
|
|
|
this.showCommentForm({ lineCode: this.line.line_code, fileHash: this.fileHash });
|
|
|
|
},
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2020-03-13 15:44:24 +05:30
|
|
|
<td ref="td" :class="classNameMap">
|
|
|
|
<div>
|
|
|
|
<button
|
|
|
|
v-if="shouldRenderCommentButton"
|
|
|
|
v-show="shouldShowCommentButton"
|
|
|
|
ref="addDiffNoteButton"
|
|
|
|
type="button"
|
|
|
|
class="add-diff-note js-add-diff-note-button qa-diff-comment"
|
|
|
|
title="Add a comment to this line"
|
|
|
|
@click="handleCommentButton"
|
|
|
|
>
|
|
|
|
<gl-icon :size="12" name="comment" />
|
|
|
|
</button>
|
|
|
|
<a
|
|
|
|
v-if="lineNumber"
|
|
|
|
ref="lineNumberRef"
|
|
|
|
:data-linenumber="lineNumber"
|
|
|
|
:href="lineHref"
|
|
|
|
@click="setHighlightedRow(lineCode)"
|
|
|
|
>
|
|
|
|
</a>
|
|
|
|
<diff-gutter-avatars
|
|
|
|
v-if="shouldShowAvatarsOnGutter"
|
|
|
|
:discussions="line.discussions"
|
|
|
|
:discussions-expanded="line.discussionsExpanded"
|
|
|
|
@toggleLineDiscussions="
|
|
|
|
toggleLineDiscussions({ lineCode, fileHash, expanded: !line.discussionsExpanded })
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</div>
|
2018-11-08 19:23:39 +05:30
|
|
|
</td>
|
|
|
|
</template>
|