inline_diff_table_row.vue 2.4 KB
Newer Older
1
<script>
2
import { mapGetters, mapActions } from 'vuex';
3 4 5 6 7 8 9 10 11 12 13 14 15 16
import DiffTableCell from './diff_table_cell.vue';
import {
  NEW_LINE_TYPE,
  OLD_LINE_TYPE,
  PARALLEL_DIFF_VIEW_TYPE,
  LINE_POSITION_LEFT,
  LINE_POSITION_RIGHT,
} from '../constants';

export default {
  components: {
    DiffTableCell,
  },
  props: {
17 18 19 20 21 22
    fileHash: {
      type: String,
      required: true,
    },
    contextLinesPath: {
      type: String,
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
      required: true,
    },
    line: {
      type: Object,
      required: true,
    },
    isBottom: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      isHover: false,
    };
  },
  computed: {
41
    ...mapGetters('diffs', ['isInlineView']),
42 43 44 45 46 47 48 49 50
    classNameMap() {
      return {
        [this.line.type]: this.line.type,
        [PARALLEL_DIFF_VIEW_TYPE]: this.isParallelView,
      };
    },
    inlineRowId() {
      const { lineCode, oldLine, newLine } = this.line;

51
      return lineCode || `${this.fileHash}_${oldLine}_${newLine}`;
52 53 54 55 56 57 58 59
    },
  },
  created() {
    this.newLineType = NEW_LINE_TYPE;
    this.oldLineType = OLD_LINE_TYPE;
    this.linePositionLeft = LINE_POSITION_LEFT;
    this.linePositionRight = LINE_POSITION_RIGHT;
  },
60 61 62
  mounted() {
    this.scrollToLineIfNeededInline(this.line);
  },
63
  methods: {
64
    ...mapActions('diffs', ['scrollToLineIfNeededInline']),
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    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
    :id="inlineRowId"
    :class="classNameMap"
    class="line_holder"
    @mouseover="handleMouseMove"
    @mouseout="handleMouseMove"
  >
    <diff-table-cell
83 84
      :file-hash="fileHash"
      :context-lines-path="contextLinesPath"
85 86 87 88 89 90 91 92
      :line="line"
      :line-type="oldLineType"
      :is-bottom="isBottom"
      :is-hover="isHover"
      :show-comment-button="true"
      class="diff-line-num old_line"
    />
    <diff-table-cell
93 94
      :file-hash="fileHash"
      :context-lines-path="contextLinesPath"
95 96 97 98
      :line="line"
      :line-type="newLineType"
      :is-bottom="isBottom"
      :is-hover="isHover"
A
at.ramya 已提交
99
      class="diff-line-num new_line qa-new-diff-line"
100
    />
101
    <td
102
      :class="line.type"
103 104 105 106
      class="line_content"
      v-html="line.richText"
    >
    </td>
107 108
  </tr>
</template>