summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/mixins/diff_content.js
blob: ebb511d3a7e658d1b2edff78c96f2103505441e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { mapGetters } from 'vuex';
import diffDiscussions from '../components/diff_discussions.vue';
import diffLineGutterContent from '../components/diff_line_gutter_content.vue';
import diffLineNoteForm from '../components/diff_line_note_form.vue';
import diffTableRow from '../components/diff_table_row.vue';
import { trimFirstCharOfLineContent } from '../store/utils';

export default {
  props: {
    diffFile: {
      type: Object,
      required: true,
    },
    diffLines: {
      type: Array,
      required: true,
    },
  },
  components: {
    diffDiscussions,
    diffTableRow,
    diffLineNoteForm,
    diffLineGutterContent,
  },
  computed: {
    ...mapGetters(['commit']),
    commitId() {
      return this.commit && this.commit.id;
    },
    userColorScheme() {
      return window.gon.user_color_scheme;
    },
    normalizedDiffLines() {
      return this.diffLines.map(line => {
        if (line.richText) {
          return trimFirstCharOfLineContent(line);
        }

        if (line.left) {
          Object.assign(line, { left: trimFirstCharOfLineContent(line.left) });
        }

        if (line.right) {
          Object.assign(line, { right: trimFirstCharOfLineContent(line.right) });
        }

        return line;
      });
    },
    diffLinesLength() {
      return this.normalizedDiffLines.length;
    },
    fileHash() {
      return this.diffFile.fileHash;
    },
  },
};