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

148 lines
3.4 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';
import { GlTooltipDirective } from '@gitlab/ui';
2018-11-08 19:23:39 +05:30
import DiffTableCell from './diff_table_cell.vue';
import {
2019-10-12 21:52:04 +05:30
MATCH_LINE_TYPE,
2018-11-08 19:23:39 +05:30
NEW_LINE_TYPE,
OLD_LINE_TYPE,
CONTEXT_LINE_TYPE,
CONTEXT_LINE_CLASS_NAME,
LINE_POSITION_LEFT,
LINE_POSITION_RIGHT,
} from '../constants';
export default {
components: {
DiffTableCell,
},
2020-04-08 14:13:33 +05:30
directives: {
GlTooltip: GlTooltipDirective,
},
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-04-08 14:13:33 +05:30
...mapGetters('diffs', ['fileLineCoverage']),
2019-02-15 15:39:39 +05:30
...mapState({
isHighlighted(state) {
2020-07-28 23:09:34 +05:30
if (this.isCommented) return true;
const lineCode = this.line.line_code;
return lineCode ? lineCode === state.diffs.highlightedRow : false;
2019-02-15 15:39:39 +05:30
},
}),
2018-11-08 19:23:39 +05:30
isContextLine() {
return this.line.type === CONTEXT_LINE_TYPE;
},
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() {
return this.line.type === MATCH_LINE_TYPE;
},
2020-04-08 14:13:33 +05:30
coverageState() {
return this.fileLineCoverage(this.filePath, this.line.new_line);
},
2018-11-08 19:23:39 +05:30
},
created() {
this.newLineType = NEW_LINE_TYPE;
this.oldLineType = OLD_LINE_TYPE;
this.linePositionLeft = LINE_POSITION_LEFT;
this.linePositionRight = LINE_POSITION_RIGHT;
},
2018-11-20 20:47:30 +05:30
mounted() {
this.scrollToLineIfNeededInline(this.line);
},
2018-11-08 19:23:39 +05:30
methods: {
2018-11-20 20:47:30 +05:30
...mapActions('diffs', ['scrollToLineIfNeededInline']),
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';
},
},
};
</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"
>
<diff-table-cell
:file-hash="fileHash"
:line="line"
:line-type="oldLineType"
:is-bottom="isBottom"
:is-hover="isHover"
:show-comment-button="true"
2019-02-15 15:39:39 +05:30
:is-highlighted="isHighlighted"
2018-11-08 19:23:39 +05:30
class="diff-line-num old_line"
/>
<diff-table-cell
:file-hash="fileHash"
:line="line"
:line-type="newLineType"
:is-bottom="isBottom"
:is-hover="isHover"
2019-02-15 15:39:39 +05:30
:is-highlighted="isHighlighted"
2018-12-13 13:39:08 +05:30
class="diff-line-num new_line qa-new-diff-line"
2018-11-08 19:23:39 +05:30
/>
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
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
v-html="line.rich_text"
></td>
2018-11-08 19:23:39 +05:30
</tr>
</template>