2020-11-10 07:08:57 -05:00
|
|
|
<script>
|
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
|
|
|
import { GlTooltipDirective, GlIcon, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
|
2021-02-01 10:08:56 -05:00
|
|
|
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2021-02-04 04:09:30 -05:00
|
|
|
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
|
2020-12-17 04:10:19 -05:00
|
|
|
import {
|
|
|
|
CONTEXT_LINE_CLASS_NAME,
|
|
|
|
PARALLEL_DIFF_VIEW_TYPE,
|
|
|
|
CONFLICT_MARKER_OUR,
|
|
|
|
CONFLICT_MARKER_THEIR,
|
|
|
|
CONFLICT_OUR,
|
|
|
|
CONFLICT_THEIR,
|
|
|
|
CONFLICT_MARKER,
|
|
|
|
} from '../constants';
|
2020-11-10 07:08:57 -05:00
|
|
|
import DiffGutterAvatars from './diff_gutter_avatars.vue';
|
|
|
|
import * as utils from './diff_row_utils';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlIcon,
|
|
|
|
DiffGutterAvatars,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
SafeHtml,
|
|
|
|
},
|
2021-01-14 13:10:59 -05:00
|
|
|
mixins: [glFeatureFlagsMixin()],
|
2020-11-10 07:08:57 -05:00
|
|
|
props: {
|
|
|
|
fileHash: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
filePath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
line: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isCommented: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
inline: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-01-14 13:10:59 -05:00
|
|
|
index: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dragging: false,
|
|
|
|
};
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters('diffs', ['fileLineCoverage']),
|
|
|
|
...mapGetters(['isLoggedIn']),
|
|
|
|
...mapState({
|
|
|
|
isHighlighted(state) {
|
|
|
|
const line = this.line.left?.line_code ? this.line.left : this.line.right;
|
2021-01-14 13:10:59 -05:00
|
|
|
return utils.isHighlighted(state, line, false);
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
classNameMap() {
|
|
|
|
return {
|
|
|
|
[CONTEXT_LINE_CLASS_NAME]: this.line.isContextLineLeft,
|
2021-01-12 04:10:49 -05:00
|
|
|
[PARALLEL_DIFF_VIEW_TYPE]: !this.inline,
|
2021-01-14 13:10:59 -05:00
|
|
|
commented: this.isCommented,
|
2020-11-10 07:08:57 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
parallelViewLeftLineType() {
|
2021-01-14 13:10:59 -05:00
|
|
|
return utils.parallelViewLeftLineType(this.line, this.isHighlighted || this.isCommented);
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
2021-01-18 16:11:05 -05:00
|
|
|
coverageStateLeft() {
|
|
|
|
if (!this.inline || !this.line.left) return {};
|
|
|
|
return this.fileLineCoverage(this.filePath, this.line.left.new_line);
|
|
|
|
},
|
|
|
|
coverageStateRight() {
|
|
|
|
if (!this.line.right) return {};
|
2020-11-10 07:08:57 -05:00
|
|
|
return this.fileLineCoverage(this.filePath, this.line.right.new_line);
|
|
|
|
},
|
|
|
|
classNameMapCellLeft() {
|
2021-01-14 13:10:59 -05:00
|
|
|
return utils.classNameMapCell({
|
|
|
|
line: this.line.left,
|
|
|
|
hll: this.isHighlighted || this.isCommented,
|
|
|
|
isLoggedIn: this.isLoggedIn,
|
|
|
|
});
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
|
|
|
classNameMapCellRight() {
|
2021-01-14 13:10:59 -05:00
|
|
|
return utils.classNameMapCell({
|
|
|
|
line: this.line.right,
|
|
|
|
hll: this.isHighlighted || this.isCommented,
|
|
|
|
isLoggedIn: this.isLoggedIn,
|
|
|
|
});
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
|
|
|
addCommentTooltipLeft() {
|
2021-01-27 07:09:01 -05:00
|
|
|
return utils.addCommentTooltip(this.line.left, this.glFeatures.dragCommentSelection);
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
|
|
|
addCommentTooltipRight() {
|
2021-01-27 07:09:01 -05:00
|
|
|
return utils.addCommentTooltip(this.line.right, this.glFeatures.dragCommentSelection);
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
2020-12-17 04:10:19 -05:00
|
|
|
emptyCellRightClassMap() {
|
|
|
|
return { conflict_their: this.line.left?.type === CONFLICT_OUR };
|
|
|
|
},
|
|
|
|
emptyCellLeftClassMap() {
|
|
|
|
return { conflict_our: this.line.right?.type === CONFLICT_THEIR };
|
|
|
|
},
|
2020-11-10 07:08:57 -05:00
|
|
|
shouldRenderCommentButton() {
|
2021-01-27 01:08:58 -05:00
|
|
|
return this.isLoggedIn && !this.line.isContextLineLeft && !this.line.isMetaLineLeft;
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
2020-12-17 04:10:19 -05:00
|
|
|
isLeftConflictMarker() {
|
|
|
|
return [CONFLICT_MARKER_OUR, CONFLICT_MARKER_THEIR].includes(this.line.left?.type);
|
|
|
|
},
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.scrollToLineIfNeededParallel(this.line);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', [
|
|
|
|
'scrollToLineIfNeededParallel',
|
|
|
|
'showCommentForm',
|
|
|
|
'setHighlightedRow',
|
|
|
|
'toggleLineDiscussions',
|
|
|
|
]),
|
|
|
|
// 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('.diff-table');
|
|
|
|
|
|
|
|
table.classList.remove('left-side-selected', 'right-side-selected');
|
2020-12-23 13:10:19 -05:00
|
|
|
const [lineClass] = ['left-side', 'right-side'].filter((name) =>
|
|
|
|
line.classList.contains(name),
|
|
|
|
);
|
2020-11-10 07:08:57 -05:00
|
|
|
|
|
|
|
if (lineClass) {
|
|
|
|
table.classList.add(`${lineClass}-selected`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleCommentButton(line) {
|
|
|
|
this.showCommentForm({ lineCode: line.line_code, fileHash: this.fileHash });
|
|
|
|
},
|
2020-12-17 04:10:19 -05:00
|
|
|
conflictText(line) {
|
|
|
|
return line.type === CONFLICT_MARKER_THEIR
|
|
|
|
? this.$options.THEIR_CHANGES
|
|
|
|
: this.$options.OUR_CHANGES;
|
|
|
|
},
|
2021-01-14 13:10:59 -05:00
|
|
|
onDragEnd() {
|
|
|
|
this.dragging = false;
|
|
|
|
if (!this.glFeatures.dragCommentSelection) return;
|
|
|
|
|
|
|
|
this.$emit('stopdragging');
|
|
|
|
},
|
|
|
|
onDragEnter(line, index) {
|
|
|
|
if (!this.glFeatures.dragCommentSelection) return;
|
|
|
|
|
|
|
|
this.$emit('enterdragging', { ...line, index });
|
|
|
|
},
|
|
|
|
onDragStart(line) {
|
2021-02-02 19:09:41 -05:00
|
|
|
this.$root.$emit(BV_HIDE_TOOLTIP);
|
2021-01-14 13:10:59 -05:00
|
|
|
this.dragging = true;
|
|
|
|
this.$emit('startdragging', line);
|
|
|
|
},
|
2020-11-10 07:08:57 -05:00
|
|
|
},
|
2020-12-17 04:10:19 -05:00
|
|
|
OUR_CHANGES: 'HEAD//our changes',
|
|
|
|
THEIR_CHANGES: 'origin//their changes',
|
|
|
|
CONFLICT_MARKER,
|
|
|
|
CONFLICT_MARKER_THEIR,
|
|
|
|
CONFLICT_OUR,
|
|
|
|
CONFLICT_THEIR,
|
2020-11-10 07:08:57 -05:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div :class="classNameMap" class="diff-grid-row diff-tr line_holder">
|
2021-01-14 13:10:59 -05:00
|
|
|
<div
|
|
|
|
data-testid="left-side"
|
|
|
|
class="diff-grid-left left-side"
|
|
|
|
@dragover.prevent
|
|
|
|
@dragenter="onDragEnter(line.left, index)"
|
|
|
|
@dragend="onDragEnd"
|
|
|
|
>
|
2020-12-17 04:10:19 -05:00
|
|
|
<template v-if="line.left && line.left.type !== $options.CONFLICT_MARKER">
|
2020-11-10 07:08:57 -05:00
|
|
|
<div
|
|
|
|
:class="classNameMapCellLeft"
|
|
|
|
data-testid="leftLineNumber"
|
2021-01-12 04:10:49 -05:00
|
|
|
class="diff-td diff-line-num"
|
2020-11-10 07:08:57 -05:00
|
|
|
>
|
2020-12-17 04:10:19 -05:00
|
|
|
<template v-if="!isLeftConflictMarker">
|
|
|
|
<span
|
2021-01-27 01:08:58 -05:00
|
|
|
v-if="shouldRenderCommentButton && !line.hasDiscussionsLeft"
|
2020-12-17 04:10:19 -05:00
|
|
|
v-gl-tooltip
|
|
|
|
data-testid="leftCommentButton"
|
|
|
|
class="add-diff-note tooltip-wrapper"
|
|
|
|
:title="addCommentTooltipLeft"
|
2020-11-10 07:08:57 -05:00
|
|
|
>
|
2020-12-17 04:10:19 -05:00
|
|
|
<button
|
2021-01-14 13:10:59 -05:00
|
|
|
:draggable="glFeatures.dragCommentSelection"
|
2020-12-17 04:10:19 -05:00
|
|
|
type="button"
|
|
|
|
class="add-diff-note note-button js-add-diff-note-button qa-diff-comment"
|
2021-01-14 13:10:59 -05:00
|
|
|
:class="{ 'gl-cursor-grab': dragging }"
|
2020-12-17 04:10:19 -05:00
|
|
|
:disabled="line.left.commentsDisabled"
|
|
|
|
@click="handleCommentButton(line.left)"
|
2021-01-14 13:10:59 -05:00
|
|
|
@dragstart="onDragStart({ ...line.left, index })"
|
2020-12-17 04:10:19 -05:00
|
|
|
>
|
|
|
|
<gl-icon :size="12" name="comment" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</template>
|
2020-11-10 07:08:57 -05:00
|
|
|
<a
|
2020-12-17 04:10:19 -05:00
|
|
|
v-if="line.left.old_line && line.left.type !== $options.CONFLICT_THEIR"
|
2020-11-10 07:08:57 -05:00
|
|
|
:data-linenumber="line.left.old_line"
|
|
|
|
:href="line.lineHrefOld"
|
|
|
|
@click="setHighlightedRow(line.lineCode)"
|
|
|
|
>
|
|
|
|
</a>
|
|
|
|
<diff-gutter-avatars
|
|
|
|
v-if="line.hasDiscussionsLeft"
|
|
|
|
:discussions="line.left.discussions"
|
|
|
|
:discussions-expanded="line.left.discussionsExpanded"
|
|
|
|
data-testid="leftDiscussions"
|
|
|
|
@toggleLineDiscussions="
|
|
|
|
toggleLineDiscussions({
|
|
|
|
lineCode: line.left.line_code,
|
|
|
|
fileHash,
|
|
|
|
expanded: !line.left.discussionsExpanded,
|
|
|
|
})
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-01-12 04:10:49 -05:00
|
|
|
<div v-if="inline" :class="classNameMapCellLeft" class="diff-td diff-line-num">
|
2020-11-10 07:08:57 -05:00
|
|
|
<a
|
2020-12-17 04:10:19 -05:00
|
|
|
v-if="line.left.new_line && line.left.type !== $options.CONFLICT_OUR"
|
2020-11-26 10:09:30 -05:00
|
|
|
:data-linenumber="line.left.new_line"
|
2020-11-10 07:08:57 -05:00
|
|
|
:href="line.lineHrefOld"
|
|
|
|
@click="setHighlightedRow(line.lineCode)"
|
|
|
|
>
|
|
|
|
</a>
|
|
|
|
</div>
|
2021-01-18 16:11:05 -05:00
|
|
|
<div
|
|
|
|
v-gl-tooltip.hover
|
|
|
|
:title="coverageStateLeft.text"
|
|
|
|
:class="[...parallelViewLeftLineType, coverageStateLeft.class]"
|
|
|
|
class="diff-td line-coverage left-side"
|
|
|
|
></div>
|
2020-11-10 07:08:57 -05:00
|
|
|
<div
|
|
|
|
:id="line.left.line_code"
|
|
|
|
:key="line.left.line_code"
|
2021-01-12 04:10:49 -05:00
|
|
|
:class="[parallelViewLeftLineType, { parallel: !inline }]"
|
|
|
|
class="diff-td line_content with-coverage left-side"
|
2020-11-10 07:08:57 -05:00
|
|
|
data-testid="leftContent"
|
|
|
|
@mousedown="handleParallelLineMouseDown"
|
2020-12-17 04:10:19 -05:00
|
|
|
>
|
|
|
|
<strong v-if="isLeftConflictMarker">{{ conflictText(line.left) }}</strong>
|
|
|
|
<span v-else v-safe-html="line.left.rich_text"></span>
|
|
|
|
</div>
|
2020-11-10 07:08:57 -05:00
|
|
|
</template>
|
2020-12-17 04:10:19 -05:00
|
|
|
<template v-else-if="!inline || (line.left && line.left.type === $options.CONFLICT_MARKER)">
|
|
|
|
<div
|
|
|
|
data-testid="leftEmptyCell"
|
|
|
|
class="diff-td diff-line-num old_line empty-cell"
|
|
|
|
:class="emptyCellLeftClassMap"
|
|
|
|
>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-if="inline"
|
|
|
|
class="diff-td diff-line-num old_line empty-cell"
|
|
|
|
:class="emptyCellLeftClassMap"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
class="diff-td line-coverage left-side empty-cell"
|
|
|
|
:class="emptyCellLeftClassMap"
|
|
|
|
></div>
|
|
|
|
<div
|
2021-01-12 04:10:49 -05:00
|
|
|
class="diff-td line_content with-coverage left-side empty-cell"
|
|
|
|
:class="[emptyCellLeftClassMap, { parallel: !inline }]"
|
2020-12-17 04:10:19 -05:00
|
|
|
></div>
|
2020-11-10 07:08:57 -05:00
|
|
|
</template>
|
|
|
|
</div>
|
2021-01-14 13:10:59 -05:00
|
|
|
<div
|
|
|
|
v-if="!inline"
|
|
|
|
data-testid="right-side"
|
|
|
|
class="diff-grid-right right-side"
|
|
|
|
@dragover.prevent
|
|
|
|
@dragenter="onDragEnter(line.right, index)"
|
|
|
|
@dragend="onDragEnd"
|
|
|
|
>
|
2020-11-10 07:08:57 -05:00
|
|
|
<template v-if="line.right">
|
2020-11-26 10:09:30 -05:00
|
|
|
<div :class="classNameMapCellRight" class="diff-td diff-line-num new_line">
|
2020-12-17 04:10:19 -05:00
|
|
|
<template v-if="line.right.type !== $options.CONFLICT_MARKER_THEIR">
|
|
|
|
<span
|
2021-01-27 01:08:58 -05:00
|
|
|
v-if="shouldRenderCommentButton && !line.hasDiscussionsRight"
|
2020-12-17 04:10:19 -05:00
|
|
|
v-gl-tooltip
|
|
|
|
data-testid="rightCommentButton"
|
|
|
|
class="add-diff-note tooltip-wrapper"
|
|
|
|
:title="addCommentTooltipRight"
|
2020-11-10 07:08:57 -05:00
|
|
|
>
|
2020-12-17 04:10:19 -05:00
|
|
|
<button
|
2021-01-14 13:10:59 -05:00
|
|
|
:draggable="glFeatures.dragCommentSelection"
|
2020-12-17 04:10:19 -05:00
|
|
|
type="button"
|
|
|
|
class="add-diff-note note-button js-add-diff-note-button qa-diff-comment"
|
2021-01-14 13:10:59 -05:00
|
|
|
:class="{ 'gl-cursor-grab': dragging }"
|
2020-12-17 04:10:19 -05:00
|
|
|
:disabled="line.right.commentsDisabled"
|
|
|
|
@click="handleCommentButton(line.right)"
|
2021-01-14 13:10:59 -05:00
|
|
|
@dragstart="onDragStart({ ...line.right, index })"
|
2020-12-17 04:10:19 -05:00
|
|
|
>
|
|
|
|
<gl-icon :size="12" name="comment" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</template>
|
2020-11-10 07:08:57 -05:00
|
|
|
<a
|
|
|
|
v-if="line.right.new_line"
|
|
|
|
:data-linenumber="line.right.new_line"
|
|
|
|
:href="line.lineHrefNew"
|
|
|
|
@click="setHighlightedRow(line.lineCode)"
|
|
|
|
>
|
|
|
|
</a>
|
|
|
|
<diff-gutter-avatars
|
|
|
|
v-if="line.hasDiscussionsRight"
|
|
|
|
:discussions="line.right.discussions"
|
|
|
|
:discussions-expanded="line.right.discussionsExpanded"
|
|
|
|
data-testid="rightDiscussions"
|
|
|
|
@toggleLineDiscussions="
|
|
|
|
toggleLineDiscussions({
|
|
|
|
lineCode: line.right.line_code,
|
|
|
|
fileHash,
|
|
|
|
expanded: !line.right.discussionsExpanded,
|
|
|
|
})
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-gl-tooltip.hover
|
2021-01-18 16:11:05 -05:00
|
|
|
:title="coverageStateRight.text"
|
|
|
|
:class="[
|
|
|
|
line.right.type,
|
|
|
|
coverageStateRight.class,
|
|
|
|
{ hll: isHighlighted, hll: isCommented },
|
|
|
|
]"
|
2020-11-10 07:08:57 -05:00
|
|
|
class="diff-td line-coverage right-side"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
:id="line.right.line_code"
|
|
|
|
:key="line.right.rich_text"
|
2021-01-14 13:10:59 -05:00
|
|
|
v-safe-html="line.right.rich_text"
|
|
|
|
:class="[
|
|
|
|
line.right.type,
|
|
|
|
{
|
|
|
|
hll: isHighlighted,
|
|
|
|
hll: isCommented,
|
|
|
|
parallel: !inline,
|
|
|
|
},
|
|
|
|
]"
|
2021-01-12 04:10:49 -05:00
|
|
|
class="diff-td line_content with-coverage right-side"
|
2020-11-10 07:08:57 -05:00
|
|
|
@mousedown="handleParallelLineMouseDown"
|
2020-12-17 04:10:19 -05:00
|
|
|
>
|
|
|
|
<strong v-if="line.right.type === $options.CONFLICT_MARKER_THEIR">{{
|
|
|
|
conflictText(line.right)
|
|
|
|
}}</strong>
|
|
|
|
<span v-else v-safe-html="line.right.rich_text"></span>
|
|
|
|
</div>
|
2020-11-10 07:08:57 -05:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2020-12-17 04:10:19 -05:00
|
|
|
<div
|
|
|
|
data-testid="rightEmptyCell"
|
|
|
|
class="diff-td diff-line-num old_line empty-cell"
|
|
|
|
:class="emptyCellRightClassMap"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
v-if="inline"
|
|
|
|
class="diff-td diff-line-num old_line empty-cell"
|
|
|
|
:class="emptyCellRightClassMap"
|
|
|
|
></div>
|
|
|
|
<div
|
|
|
|
class="diff-td line-coverage right-side empty-cell"
|
|
|
|
:class="emptyCellRightClassMap"
|
|
|
|
></div>
|
|
|
|
<div
|
2021-01-12 04:10:49 -05:00
|
|
|
class="diff-td line_content with-coverage right-side empty-cell"
|
|
|
|
:class="[emptyCellRightClassMap, { parallel: !inline }]"
|
2020-12-17 04:10:19 -05:00
|
|
|
></div>
|
2020-11-10 07:08:57 -05:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|