summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/diff_stats.vue
blob: 05d4fbe7c20493e8c2d3cd01df699a6b67427002 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<script>
import { GlIcon } from '@gitlab/ui';
import { isNumber } from 'lodash';
import { n__ } from '~/locale';
import { isNotDiffable, stats } from '../utils/diff_file';

export default {
  components: { GlIcon },
  props: {
    diffFile: {
      type: Object,
      required: false,
      default: () => null,
    },
    addedLines: {
      type: Number,
      required: true,
    },
    removedLines: {
      type: Number,
      required: true,
    },
    diffFilesCountText: {
      type: String,
      required: false,
      default: null,
    },
  },
  computed: {
    diffFilesLength() {
      return parseInt(this.diffFilesCountText, 10);
    },
    filesText() {
      return n__('file', 'files', this.diffFilesLength);
    },
    isCompareVersionsHeader() {
      return Boolean(this.diffFilesCountText);
    },
    hasDiffFiles() {
      return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0;
    },
    notDiffable() {
      return isNotDiffable(this.diffFile);
    },
    fileStats() {
      return stats(this.diffFile);
    },
  },
};
</script>

<template>
  <div
    class="diff-stats"
    :class="{
      'is-compare-versions-header gl-display-none gl-lg-display-inline-flex': isCompareVersionsHeader,
      'gl-display-none gl-sm-display-inline-flex': !isCompareVersionsHeader,
    }"
  >
    <div v-if="notDiffable" :class="fileStats.classes">
      {{ fileStats.text }}
    </div>
    <div v-else class="diff-stats-contents">
      <div v-if="hasDiffFiles" class="diff-stats-group">
        <gl-icon name="doc-code" class="diff-stats-icon text-secondary" />
        <span class="text-secondary bold">{{ diffFilesCountText }} {{ filesText }}</span>
      </div>
      <div
        class="diff-stats-group gl-text-green-600 gl-display-flex gl-align-items-center"
        :class="{ bold: isCompareVersionsHeader }"
      >
        <span>+</span>
        <span data-testid="js-file-addition-line">{{ addedLines }}</span>
      </div>
      <div
        class="diff-stats-group gl-text-red-500 gl-display-flex gl-align-items-center"
        :class="{ bold: isCompareVersionsHeader }"
      >
        <span>-</span>
        <span data-testid="js-file-deletion-line">{{ removedLines }}</span>
      </div>
    </div>
  </div>
</template>