parallel_diff_view.vue 2.67 KB
Newer Older
Felipe Artur's avatar
Felipe Artur committed
1
<script>
2
import { mapGetters } from 'vuex';
3
import draftCommentsMixin from 'ee_else_ce/diffs/mixins/draft_comments';
4
import parallelDiffTableRow from './parallel_diff_table_row.vue';
5
import parallelDiffCommentRow from './parallel_diff_comment_row.vue';
6
import parallelDiffExpansionRow from './parallel_diff_expansion_row.vue';
Felipe Artur's avatar
Felipe Artur committed
7 8

export default {
9
  components: {
10
    parallelDiffExpansionRow,
11
    parallelDiffTableRow,
12
    parallelDiffCommentRow,
13 14
    ParallelDraftCommentRow: () =>
      import('ee_component/batch_comments/components/parallel_draft_comment_row.vue'),
15
  },
16
  mixins: [draftCommentsMixin],
17 18 19 20 21 22 23 24 25
  props: {
    diffFile: {
      type: Object,
      required: true,
    },
    diffLines: {
      type: Array,
      required: true,
    },
26 27 28 29 30
    helpPagePath: {
      type: String,
      required: false,
      default: '',
    },
31
  },
Felipe Artur's avatar
Felipe Artur committed
32
  computed: {
33
    ...mapGetters('diffs', ['commitId']),
34
    diffLinesLength() {
Tim Zallmann's avatar
Tim Zallmann committed
35
      return this.diffLines.length;
36
    },
Felipe Artur's avatar
Felipe Artur committed
37
  },
38
  userColorScheme: window.gon.user_color_scheme,
Felipe Artur's avatar
Felipe Artur committed
39 40 41 42
};
</script>

<template>
43
  <table
44
    :class="$options.userColorScheme"
Felipe Artur's avatar
Felipe Artur committed
45
    :data-commit-id="commitId"
46 47
    class="code diff-wrap-lines js-syntax-highlight text-file"
  >
48 49 50 51 52 53 54
    <!-- Need to insert an empty row to solve "table-layout:fixed" equal width when expansion row is the first line -->
    <tr>
      <td style="width: 50px;"></td>
      <td></td>
      <td style="width: 50px;"></td>
      <td></td>
    </tr>
55 56
    <tbody>
      <template v-for="(line, index) in diffLines">
57 58 59 60 61 62 63 64
        <parallel-diff-expansion-row
          :key="`expand-${index}`"
          :file-hash="diffFile.file_hash"
          :context-lines-path="diffFile.context_lines_path"
          :line="line"
          :is-top="index === 0"
          :is-bottom="index + 1 === diffLinesLength"
        />
65 66 67 68 69 70 71 72 73 74 75 76 77
        <parallel-diff-table-row
          :key="line.line_code"
          :file-hash="diffFile.file_hash"
          :context-lines-path="diffFile.context_lines_path"
          :line="line"
          :is-bottom="index + 1 === diffLinesLength"
        />
        <parallel-diff-comment-row
          :key="`dcr-${line.line_code || index}`"
          :line="line"
          :diff-file-hash="diffFile.file_hash"
          :line-index="index"
          :help-page-path="helpPagePath"
78 79
          :has-draft-left="hasParallelDraftLeft(diffFile.file_hash, line) || false"
          :has-draft-right="hasParallelDraftRight(diffFile.file_hash, line) || false"
80 81 82 83 84 85 86 87 88 89
        />
        <parallel-draft-comment-row
          v-if="shouldRenderParallelDraftRow(diffFile.file_hash, line)"
          :key="`drafts-${index}`"
          :line="line"
          :diff-file-content-sha="diffFile.file_hash"
        />
      </template>
    </tbody>
  </table>
Felipe Artur's avatar
Felipe Artur committed
90
</template>