debian-mirror-gitlab/app/assets/javascripts/diffs/components/inline_diff_table_row.vue

203 lines
5.1 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
2020-04-08 14:13:33 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2020-11-24 15:15:51 +05:30
import { GlTooltipDirective, GlIcon, GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui';
2021-01-03 14:25:43 +05:30
import { CONTEXT_LINE_CLASS_NAME } from '../constants';
2020-11-24 15:15:51 +05:30
import DiffGutterAvatars from './diff_gutter_avatars.vue';
2021-01-03 14:25:43 +05:30
import * as utils from './diff_row_utils';
2018-11-08 19:23:39 +05:30
export default {
components: {
2020-11-24 15:15:51 +05:30
DiffGutterAvatars,
GlIcon,
2018-11-08 19:23:39 +05:30
},
2020-04-08 14:13:33 +05:30
directives: {
GlTooltip: GlTooltipDirective,
2020-11-24 15:15:51 +05:30
SafeHtml,
2020-04-08 14:13:33 +05:30
},
2018-11-08 19:23:39 +05:30
props: {
fileHash: {
type: String,
required: true,
},
2020-04-08 14:13:33 +05:30
filePath: {
type: String,
required: true,
},
2018-11-08 19:23:39 +05:30
line: {
type: Object,
required: true,
},
isBottom: {
type: Boolean,
required: false,
default: false,
},
2020-07-28 23:09:34 +05:30
isCommented: {
type: Boolean,
required: false,
default: false,
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
isHover: false,
};
},
computed: {
2020-11-24 15:15:51 +05:30
...mapGetters(['isLoggedIn']),
2020-04-08 14:13:33 +05:30
...mapGetters('diffs', ['fileLineCoverage']),
2019-02-15 15:39:39 +05:30
...mapState({
isHighlighted(state) {
2021-01-03 14:25:43 +05:30
return utils.isHighlighted(state, this.line, this.isCommented);
2019-02-15 15:39:39 +05:30
},
}),
2018-11-08 19:23:39 +05:30
isContextLine() {
2021-01-03 14:25:43 +05:30
return utils.isContextLine(this.line.type);
2018-11-08 19:23:39 +05:30
},
classNameMap() {
2019-07-31 22:56:46 +05:30
return [
this.line.type,
{
[CONTEXT_LINE_CLASS_NAME]: this.isContextLine,
},
];
2018-11-08 19:23:39 +05:30
},
inlineRowId() {
2019-02-15 15:39:39 +05:30
return this.line.line_code || `${this.fileHash}_${this.line.old_line}_${this.line.new_line}`;
2018-11-08 19:23:39 +05:30
},
2019-10-12 21:52:04 +05:30
isMatchLine() {
2021-01-03 14:25:43 +05:30
return utils.isMatchLine(this.line.type);
2019-10-12 21:52:04 +05:30
},
2020-04-08 14:13:33 +05:30
coverageState() {
return this.fileLineCoverage(this.filePath, this.line.new_line);
},
2020-11-24 15:15:51 +05:30
isMetaLine() {
2021-01-03 14:25:43 +05:30
return utils.isMetaLine(this.line.type);
2020-11-24 15:15:51 +05:30
},
classNameMapCell() {
2021-01-03 14:25:43 +05:30
return utils.classNameMapCell(this.line, this.isHighlighted, this.isLoggedIn, this.isHover);
2020-11-24 15:15:51 +05:30
},
addCommentTooltip() {
2021-01-03 14:25:43 +05:30
return utils.addCommentTooltip(this.line);
2020-11-24 15:15:51 +05:30
},
shouldRenderCommentButton() {
2021-01-03 14:25:43 +05:30
return utils.shouldRenderCommentButton(this.isLoggedIn, true);
2020-11-24 15:15:51 +05:30
},
shouldShowCommentButton() {
2021-01-03 14:25:43 +05:30
return utils.shouldShowCommentButton(
this.isHover,
this.isContextLine,
this.isMetaLine,
this.hasDiscussions,
);
2020-11-24 15:15:51 +05:30
},
hasDiscussions() {
2021-01-03 14:25:43 +05:30
return utils.hasDiscussions(this.line);
2020-11-24 15:15:51 +05:30
},
lineHref() {
2021-01-03 14:25:43 +05:30
return utils.lineHref(this.line);
2020-11-24 15:15:51 +05:30
},
lineCode() {
2021-01-03 14:25:43 +05:30
return utils.lineCode(this.line);
2020-11-24 15:15:51 +05:30
},
shouldShowAvatarsOnGutter() {
return this.hasDiscussions;
},
2018-11-08 19:23:39 +05:30
},
2018-11-20 20:47:30 +05:30
mounted() {
this.scrollToLineIfNeededInline(this.line);
},
2018-11-08 19:23:39 +05:30
methods: {
2020-11-24 15:15:51 +05:30
...mapActions('diffs', [
'scrollToLineIfNeededInline',
'showCommentForm',
'setHighlightedRow',
'toggleLineDiscussions',
]),
2018-11-08 19:23:39 +05:30
handleMouseMove(e) {
// To show the comment icon on the gutter we need to know if we hover the line.
// Current table structure doesn't allow us to do this with CSS in both of the diff view types
this.isHover = e.type === 'mouseover';
},
2020-11-24 15:15:51 +05:30
handleCommentButton() {
this.showCommentForm({ lineCode: this.line.line_code, fileHash: this.fileHash });
},
2018-11-08 19:23:39 +05:30
},
};
</script>
<template>
<tr
2019-10-12 21:52:04 +05:30
v-if="!isMatchLine"
2018-11-08 19:23:39 +05:30
:id="inlineRowId"
:class="classNameMap"
class="line_holder"
@mouseover="handleMouseMove"
@mouseout="handleMouseMove"
>
2020-11-24 15:15:51 +05:30
<td ref="oldTd" class="diff-line-num old_line" :class="classNameMapCell">
<span
v-if="shouldRenderCommentButton"
ref="addNoteTooltip"
v-gl-tooltip
class="add-diff-note tooltip-wrapper"
:title="addCommentTooltip"
>
<button
v-show="shouldShowCommentButton"
ref="addDiffNoteButton"
type="button"
class="add-diff-note note-button js-add-diff-note-button qa-diff-comment"
:disabled="line.commentsDisabled"
@click="handleCommentButton"
>
<gl-icon :size="12" name="comment" />
</button>
</span>
<a
v-if="line.old_line"
ref="lineNumberRefOld"
:data-linenumber="line.old_line"
: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 })
"
/>
</td>
<td ref="newTd" class="diff-line-num new_line qa-new-diff-line" :class="classNameMapCell">
<a
v-if="line.new_line"
ref="lineNumberRefNew"
:data-linenumber="line.new_line"
:href="lineHref"
@click="setHighlightedRow(lineCode)"
>
</a>
</td>
2020-04-08 14:13:33 +05:30
<td
v-gl-tooltip.hover
:title="coverageState.text"
:class="[line.type, coverageState.class, { hll: isHighlighted }]"
class="line-coverage"
></td>
2018-11-08 19:23:39 +05:30
<td
2021-01-03 14:25:43 +05:30
:key="line.line_code"
2020-11-24 15:15:51 +05:30
v-safe-html="line.rich_text"
2019-02-15 15:39:39 +05:30
:class="[
line.type,
{
hll: isHighlighted,
},
]"
2020-04-08 14:13:33 +05:30
class="line_content with-coverage"
2019-02-15 15:39:39 +05:30
></td>
2018-11-08 19:23:39 +05:30
</tr>
</template>