2018-07-03 23:18:27 +00:00
|
|
|
<script>
|
2020-03-17 18:09:44 +00:00
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
|
|
|
import { GlTooltipDirective } from '@gitlab/ui';
|
2018-07-03 23:18:27 +00:00
|
|
|
import DiffTableCell from './diff_table_cell.vue';
|
|
|
|
import {
|
2019-08-10 02:36:32 +00:00
|
|
|
MATCH_LINE_TYPE,
|
2018-07-03 23:18:27 +00:00
|
|
|
NEW_LINE_TYPE,
|
|
|
|
OLD_LINE_TYPE,
|
2018-11-07 21:57:26 +00:00
|
|
|
CONTEXT_LINE_TYPE,
|
|
|
|
CONTEXT_LINE_CLASS_NAME,
|
2018-07-03 23:18:27 +00:00
|
|
|
LINE_POSITION_LEFT,
|
|
|
|
LINE_POSITION_RIGHT,
|
|
|
|
} from '../constants';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
DiffTableCell,
|
|
|
|
},
|
2020-03-17 18:09:44 +00:00
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
2018-07-03 23:18:27 +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-07-17 15:47:02 +00:00
|
|
|
contextLinesPath: {
|
|
|
|
type: String,
|
2018-07-03 23:18:27 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
line: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
isBottom: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isHover: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2020-03-17 18:09:44 +00:00
|
|
|
...mapGetters('diffs', ['fileLineCoverage']),
|
2018-11-30 08:48:47 +00:00
|
|
|
...mapState({
|
|
|
|
isHighlighted(state) {
|
|
|
|
return this.line.line_code !== null && this.line.line_code === state.diffs.highlightedRow;
|
|
|
|
},
|
|
|
|
}),
|
2018-11-07 21:57:26 +00:00
|
|
|
isContextLine() {
|
|
|
|
return this.line.type === CONTEXT_LINE_TYPE;
|
|
|
|
},
|
2018-07-03 23:18:27 +00:00
|
|
|
classNameMap() {
|
2019-05-03 07:33:15 +00:00
|
|
|
return [
|
|
|
|
this.line.type,
|
|
|
|
{
|
|
|
|
[CONTEXT_LINE_CLASS_NAME]: this.isContextLine,
|
|
|
|
},
|
|
|
|
];
|
2018-07-03 23:18:27 +00:00
|
|
|
},
|
|
|
|
inlineRowId() {
|
2018-11-09 19:48:41 +00:00
|
|
|
return this.line.line_code || `${this.fileHash}_${this.line.old_line}_${this.line.new_line}`;
|
2018-07-03 23:18:27 +00:00
|
|
|
},
|
2019-08-10 02:36:32 +00:00
|
|
|
isMatchLine() {
|
|
|
|
return this.line.type === MATCH_LINE_TYPE;
|
|
|
|
},
|
2020-03-17 18:09:44 +00:00
|
|
|
coverageState() {
|
|
|
|
return this.fileLineCoverage(this.filePath, this.line.new_line);
|
|
|
|
},
|
2018-07-03 23:18:27 +00:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.newLineType = NEW_LINE_TYPE;
|
|
|
|
this.oldLineType = OLD_LINE_TYPE;
|
|
|
|
this.linePositionLeft = LINE_POSITION_LEFT;
|
|
|
|
this.linePositionRight = LINE_POSITION_RIGHT;
|
|
|
|
},
|
2018-09-20 08:21:17 +00:00
|
|
|
mounted() {
|
|
|
|
this.scrollToLineIfNeededInline(this.line);
|
|
|
|
},
|
2018-07-03 23:18:27 +00:00
|
|
|
methods: {
|
2018-09-20 08:21:17 +00:00
|
|
|
...mapActions('diffs', ['scrollToLineIfNeededInline']),
|
2018-07-03 23:18:27 +00:00
|
|
|
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';
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<tr
|
2019-08-10 02:36:32 +00:00
|
|
|
v-if="!isMatchLine"
|
2018-07-03 23:18:27 +00:00
|
|
|
:id="inlineRowId"
|
|
|
|
:class="classNameMap"
|
|
|
|
class="line_holder"
|
|
|
|
@mouseover="handleMouseMove"
|
|
|
|
@mouseout="handleMouseMove"
|
|
|
|
>
|
|
|
|
<diff-table-cell
|
2018-07-17 15:47:02 +00:00
|
|
|
:file-hash="fileHash"
|
|
|
|
:context-lines-path="contextLinesPath"
|
2018-07-03 23:18:27 +00:00
|
|
|
:line="line"
|
|
|
|
:line-type="oldLineType"
|
|
|
|
:is-bottom="isBottom"
|
|
|
|
:is-hover="isHover"
|
|
|
|
:show-comment-button="true"
|
2018-11-30 08:48:47 +00:00
|
|
|
:is-highlighted="isHighlighted"
|
2018-07-03 23:18:27 +00:00
|
|
|
class="diff-line-num old_line"
|
|
|
|
/>
|
|
|
|
<diff-table-cell
|
2018-07-17 15:47:02 +00:00
|
|
|
:file-hash="fileHash"
|
|
|
|
:context-lines-path="contextLinesPath"
|
2018-07-03 23:18:27 +00:00
|
|
|
:line="line"
|
|
|
|
:line-type="newLineType"
|
|
|
|
:is-bottom="isBottom"
|
|
|
|
:is-hover="isHover"
|
2018-11-30 08:48:47 +00:00
|
|
|
:is-highlighted="isHighlighted"
|
2018-10-30 06:43:43 +00:00
|
|
|
class="diff-line-num new_line qa-new-diff-line"
|
2018-07-03 23:18:27 +00:00
|
|
|
/>
|
2020-03-17 18:09:44 +00:00
|
|
|
<td
|
|
|
|
v-gl-tooltip.hover
|
|
|
|
:title="coverageState.text"
|
|
|
|
:class="[line.type, coverageState.class, { hll: isHighlighted }]"
|
|
|
|
class="line-coverage"
|
|
|
|
></td>
|
2018-11-30 08:48:47 +00:00
|
|
|
<td
|
|
|
|
:class="[
|
|
|
|
line.type,
|
|
|
|
{
|
|
|
|
hll: isHighlighted,
|
|
|
|
},
|
|
|
|
]"
|
2020-03-17 18:09:44 +00:00
|
|
|
class="line_content with-coverage"
|
2018-11-30 08:48:47 +00:00
|
|
|
v-html="line.rich_text"
|
|
|
|
></td>
|
2018-07-03 23:18:27 +00:00
|
|
|
</tr>
|
|
|
|
</template>
|