2018-06-27 21:20:41 +00:00
|
|
|
<script>
|
2020-03-17 18:09:44 +00:00
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
2018-06-27 21:20:41 +00:00
|
|
|
import $ from 'jquery';
|
2020-09-15 12:09:30 +00:00
|
|
|
import { GlTooltipDirective, GlIcon, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
|
2020-09-23 12:09:58 +00:00
|
|
|
import { CONTEXT_LINE_CLASS_NAME, PARALLEL_DIFF_VIEW_TYPE } from '../constants';
|
2020-09-15 12:09:30 +00:00
|
|
|
import DiffGutterAvatars from './diff_gutter_avatars.vue';
|
2020-09-23 12:09:58 +00:00
|
|
|
import * as utils from './diff_row_utils';
|
2018-06-27 21:20:41 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-09-15 12:09:30 +00:00
|
|
|
GlIcon,
|
|
|
|
DiffGutterAvatars,
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
2020-03-17 18:09:44 +00:00
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
2020-09-04 18:08:48 +00:00
|
|
|
SafeHtml,
|
2020-03-17 18:09:44 +00:00
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
props: {
|
2018-07-17 15:47:02 +00:00
|
|
|
fileHash: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-03-17 18:09:44 +00:00
|
|
|
filePath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
line: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isBottom: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-07-16 06:09:33 +00:00
|
|
|
isCommented: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLeftHover: false,
|
|
|
|
isRightHover: false,
|
2020-09-15 12:09:30 +00:00
|
|
|
isCommentButtonRendered: false,
|
2018-06-27 21:20:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2020-03-17 18:09:44 +00:00
|
|
|
...mapGetters('diffs', ['fileLineCoverage']),
|
2020-09-15 12:09:30 +00:00
|
|
|
...mapGetters(['isLoggedIn']),
|
2018-11-30 08:48:47 +00:00
|
|
|
...mapState({
|
|
|
|
isHighlighted(state) {
|
2020-09-23 12:09:58 +00:00
|
|
|
const line = this.line.left?.line_code ? this.line.left : this.line.right;
|
|
|
|
return utils.isHighlighted(state, line, this.isCommented);
|
2018-11-30 08:48:47 +00:00
|
|
|
},
|
|
|
|
}),
|
2018-06-27 21:20:41 +00:00
|
|
|
classNameMap() {
|
|
|
|
return {
|
2020-11-10 12:08:57 +00:00
|
|
|
[CONTEXT_LINE_CLASS_NAME]: this.line.isContextLineLeft,
|
2018-08-06 21:13:34 +00:00
|
|
|
[PARALLEL_DIFF_VIEW_TYPE]: true,
|
2018-06-27 21:20:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
parallelViewLeftLineType() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.parallelViewLeftLineType(this.line, this.isHighlighted);
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
2020-03-17 18:09:44 +00:00
|
|
|
coverageState() {
|
|
|
|
return this.fileLineCoverage(this.filePath, this.line.right.new_line);
|
|
|
|
},
|
2020-09-15 12:09:30 +00:00
|
|
|
classNameMapCellLeft() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.classNameMapCell(
|
|
|
|
this.line.left,
|
|
|
|
this.isHighlighted,
|
|
|
|
this.isLoggedIn,
|
|
|
|
this.isLeftHover,
|
|
|
|
);
|
2020-09-15 12:09:30 +00:00
|
|
|
},
|
|
|
|
classNameMapCellRight() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.classNameMapCell(
|
|
|
|
this.line.right,
|
|
|
|
this.isHighlighted,
|
|
|
|
this.isLoggedIn,
|
|
|
|
this.isRightHover,
|
|
|
|
);
|
2020-09-15 12:09:30 +00:00
|
|
|
},
|
|
|
|
addCommentTooltipLeft() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.addCommentTooltip(this.line.left);
|
2020-09-15 12:09:30 +00:00
|
|
|
},
|
|
|
|
addCommentTooltipRight() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.addCommentTooltip(this.line.right);
|
2020-09-15 12:09:30 +00:00
|
|
|
},
|
|
|
|
shouldRenderCommentButton() {
|
2020-10-12 15:08:32 +00:00
|
|
|
return utils.shouldRenderCommentButton(this.isLoggedIn, this.isCommentButtonRendered);
|
2020-09-15 12:09:30 +00:00
|
|
|
},
|
|
|
|
shouldShowCommentButtonLeft() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.shouldShowCommentButton(
|
|
|
|
this.isLeftHover,
|
2020-11-10 12:08:57 +00:00
|
|
|
this.line.isContextLineLeft,
|
|
|
|
this.line.isMetaLineLeft,
|
|
|
|
this.line.hasDiscussionsLeft,
|
2020-09-15 12:09:30 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
shouldShowCommentButtonRight() {
|
2020-09-23 12:09:58 +00:00
|
|
|
return utils.shouldShowCommentButton(
|
|
|
|
this.isRightHover,
|
2020-11-10 12:08:57 +00:00
|
|
|
this.line.isContextLineRight,
|
|
|
|
this.line.isMetaLineRight,
|
|
|
|
this.line.hasDiscussionsRight,
|
2020-09-15 12:09:30 +00:00
|
|
|
);
|
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
2018-09-20 08:21:17 +00:00
|
|
|
mounted() {
|
|
|
|
this.scrollToLineIfNeededParallel(this.line);
|
2020-09-15 12:09:30 +00:00
|
|
|
this.unwatchShouldShowCommentButton = this.$watch(
|
2020-12-23 21:10:24 +00:00
|
|
|
(vm) => [vm.shouldShowCommentButtonLeft, vm.shouldShowCommentButtonRight].join(),
|
|
|
|
(newVal) => {
|
2020-09-15 12:09:30 +00:00
|
|
|
if (newVal) {
|
|
|
|
this.isCommentButtonRendered = true;
|
|
|
|
this.unwatchShouldShowCommentButton();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.unwatchShouldShowCommentButton();
|
2018-09-20 08:21:17 +00:00
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
methods: {
|
2020-09-15 12:09:30 +00:00
|
|
|
...mapActions('diffs', [
|
|
|
|
'scrollToLineIfNeededParallel',
|
|
|
|
'showCommentForm',
|
|
|
|
'setHighlightedRow',
|
|
|
|
'toggleLineDiscussions',
|
|
|
|
]),
|
2018-06-27 21:20:41 +00:00
|
|
|
handleMouseMove(e) {
|
|
|
|
const isHover = e.type === 'mouseover';
|
2018-07-03 23:18:27 +00:00
|
|
|
const hoveringCell = e.target.closest('td');
|
|
|
|
const allCellsInHoveringRow = Array.from(e.currentTarget.children);
|
|
|
|
const hoverIndex = allCellsInHoveringRow.indexOf(hoveringCell);
|
2018-06-27 21:20:41 +00:00
|
|
|
|
2020-03-17 18:09:44 +00:00
|
|
|
if (hoverIndex >= 3) {
|
2018-07-03 23:18:27 +00:00
|
|
|
this.isRightHover = isHover;
|
2018-06-27 21:20:41 +00:00
|
|
|
} else {
|
2018-07-03 23:18:27 +00:00
|
|
|
this.isLeftHover = isHover;
|
2018-06-27 21:20:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Prevent text selecting on both sides of parallel diff view
|
|
|
|
// Backport of the same code from legacy diff notes.
|
|
|
|
handleParallelLineMouseDown(e) {
|
|
|
|
const line = $(e.currentTarget);
|
|
|
|
const table = line.closest('table');
|
|
|
|
|
|
|
|
table.removeClass('left-side-selected right-side-selected');
|
2020-12-23 21:10:24 +00:00
|
|
|
const [lineClass] = ['left-side', 'right-side'].filter((name) => line.hasClass(name));
|
2018-06-27 21:20:41 +00:00
|
|
|
|
|
|
|
if (lineClass) {
|
|
|
|
table.addClass(`${lineClass}-selected`);
|
|
|
|
}
|
|
|
|
},
|
2020-09-15 12:09:30 +00:00
|
|
|
handleCommentButton(line) {
|
|
|
|
this.showCommentForm({ lineCode: line.line_code, fileHash: this.fileHash });
|
|
|
|
},
|
2018-06-27 21:20:41 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<tr
|
|
|
|
:class="classNameMap"
|
|
|
|
class="line_holder"
|
|
|
|
@mouseover="handleMouseMove"
|
|
|
|
@mouseout="handleMouseMove"
|
|
|
|
>
|
2020-11-10 12:08:57 +00:00
|
|
|
<template v-if="line.left && !line.isMatchLineLeft">
|
2020-09-15 12:09:30 +00:00
|
|
|
<td ref="oldTd" :class="classNameMapCellLeft" class="diff-line-num old_line">
|
|
|
|
<span
|
|
|
|
v-if="shouldRenderCommentButton"
|
|
|
|
ref="addNoteTooltipLeft"
|
|
|
|
v-gl-tooltip
|
|
|
|
class="add-diff-note tooltip-wrapper"
|
|
|
|
:title="addCommentTooltipLeft"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
v-show="shouldShowCommentButtonLeft"
|
|
|
|
ref="addDiffNoteButtonLeft"
|
|
|
|
type="button"
|
|
|
|
class="add-diff-note note-button js-add-diff-note-button qa-diff-comment"
|
|
|
|
:disabled="line.left.commentsDisabled"
|
|
|
|
@click="handleCommentButton(line.left)"
|
|
|
|
>
|
|
|
|
<gl-icon :size="12" name="comment" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<a
|
|
|
|
v-if="line.left.old_line"
|
|
|
|
ref="lineNumberRefOld"
|
|
|
|
:data-linenumber="line.left.old_line"
|
2020-11-10 12:08:57 +00:00
|
|
|
:href="line.lineHrefOld"
|
|
|
|
@click="setHighlightedRow(line.lineCode)"
|
2020-09-15 12:09:30 +00:00
|
|
|
>
|
|
|
|
</a>
|
|
|
|
<diff-gutter-avatars
|
2020-11-10 12:08:57 +00:00
|
|
|
v-if="line.hasDiscussionsLeft"
|
2020-09-15 12:09:30 +00:00
|
|
|
:discussions="line.left.discussions"
|
|
|
|
:discussions-expanded="line.left.discussionsExpanded"
|
|
|
|
@toggleLineDiscussions="
|
|
|
|
toggleLineDiscussions({
|
|
|
|
lineCode: line.left.line_code,
|
|
|
|
fileHash,
|
|
|
|
expanded: !line.left.discussionsExpanded,
|
|
|
|
})
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</td>
|
2020-03-17 18:09:44 +00:00
|
|
|
<td :class="parallelViewLeftLineType" class="line-coverage left-side"></td>
|
2018-08-06 21:13:34 +00:00
|
|
|
<td
|
2018-11-09 19:48:41 +00:00
|
|
|
:id="line.left.line_code"
|
2020-09-23 12:09:58 +00:00
|
|
|
:key="line.left.line_code"
|
2020-09-04 18:08:48 +00:00
|
|
|
v-safe-html="line.left.rich_text"
|
2018-08-06 21:13:34 +00:00
|
|
|
:class="parallelViewLeftLineType"
|
2020-03-17 18:09:44 +00:00
|
|
|
class="line_content with-coverage parallel left-side"
|
2019-03-25 08:51:29 +00:00
|
|
|
@mousedown="handleParallelLineMouseDown"
|
2018-11-16 20:07:38 +00:00
|
|
|
></td>
|
2018-08-06 21:13:34 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<td class="diff-line-num old_line empty-cell"></td>
|
2020-03-17 18:09:44 +00:00
|
|
|
<td class="line-coverage left-side empty-cell"></td>
|
|
|
|
<td class="line_content with-coverage parallel left-side empty-cell"></td>
|
2018-08-06 21:13:34 +00:00
|
|
|
</template>
|
2020-11-10 12:08:57 +00:00
|
|
|
<template v-if="line.right && !line.isMatchLineRight">
|
2020-09-15 12:09:30 +00:00
|
|
|
<td ref="newTd" :class="classNameMapCellRight" class="diff-line-num new_line">
|
|
|
|
<span
|
|
|
|
v-if="shouldRenderCommentButton"
|
|
|
|
ref="addNoteTooltipRight"
|
|
|
|
v-gl-tooltip
|
|
|
|
class="add-diff-note tooltip-wrapper"
|
|
|
|
:title="addCommentTooltipRight"
|
|
|
|
>
|
|
|
|
<button
|
|
|
|
v-show="shouldShowCommentButtonRight"
|
|
|
|
ref="addDiffNoteButtonRight"
|
|
|
|
type="button"
|
|
|
|
class="add-diff-note note-button js-add-diff-note-button qa-diff-comment"
|
|
|
|
:disabled="line.right.commentsDisabled"
|
|
|
|
@click="handleCommentButton(line.right)"
|
|
|
|
>
|
|
|
|
<gl-icon :size="12" name="comment" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<a
|
|
|
|
v-if="line.right.new_line"
|
|
|
|
ref="lineNumberRefNew"
|
|
|
|
:data-linenumber="line.right.new_line"
|
2020-11-10 12:08:57 +00:00
|
|
|
:href="line.lineHrefNew"
|
|
|
|
@click="setHighlightedRow(line.lineCode)"
|
2020-09-15 12:09:30 +00:00
|
|
|
>
|
|
|
|
</a>
|
|
|
|
<diff-gutter-avatars
|
2020-11-10 12:08:57 +00:00
|
|
|
v-if="line.hasDiscussionsRight"
|
2020-09-15 12:09:30 +00:00
|
|
|
:discussions="line.right.discussions"
|
|
|
|
:discussions-expanded="line.right.discussionsExpanded"
|
|
|
|
@toggleLineDiscussions="
|
|
|
|
toggleLineDiscussions({
|
|
|
|
lineCode: line.right.line_code,
|
|
|
|
fileHash,
|
|
|
|
expanded: !line.right.discussionsExpanded,
|
|
|
|
})
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</td>
|
2020-03-17 18:09:44 +00:00
|
|
|
<td
|
|
|
|
v-gl-tooltip.hover
|
|
|
|
:title="coverageState.text"
|
|
|
|
:class="[line.right.type, coverageState.class, { hll: isHighlighted }]"
|
|
|
|
class="line-coverage right-side"
|
|
|
|
></td>
|
2018-08-06 21:13:34 +00:00
|
|
|
<td
|
2018-11-09 19:48:41 +00:00
|
|
|
:id="line.right.line_code"
|
2020-09-23 12:09:58 +00:00
|
|
|
:key="line.right.rich_text"
|
2020-09-04 18:08:48 +00:00
|
|
|
v-safe-html="line.right.rich_text"
|
2018-11-30 08:48:47 +00:00
|
|
|
:class="[
|
|
|
|
line.right.type,
|
|
|
|
{
|
|
|
|
hll: isHighlighted,
|
|
|
|
},
|
|
|
|
]"
|
2020-03-17 18:09:44 +00:00
|
|
|
class="line_content with-coverage parallel right-side"
|
2019-03-25 08:51:29 +00:00
|
|
|
@mousedown="handleParallelLineMouseDown"
|
2018-11-16 20:07:38 +00:00
|
|
|
></td>
|
2018-08-06 21:13:34 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<td class="diff-line-num old_line empty-cell"></td>
|
2020-03-17 18:09:44 +00:00
|
|
|
<td class="line-coverage right-side empty-cell"></td>
|
|
|
|
<td class="line_content with-coverage parallel right-side empty-cell"></td>
|
2018-08-06 21:13:34 +00:00
|
|
|
</template>
|
2018-06-27 21:20:41 +00:00
|
|
|
</tr>
|
|
|
|
</template>
|