Read about our upcoming Code of Conduct on this issue

diff_stats.vue 1.4 KB
Newer Older
1
<script>
2
import Icon from '~/vue_shared/components/icon.vue';
3
import { n__ } from '~/locale';
4
import { isNumber } from 'underscore';
5
6

export default {
7
  components: { Icon },
8
9
10
11
12
13
14
15
16
17
18
19
  props: {
    addedLines: {
      type: Number,
      required: true,
    },
    removedLines: {
      type: Number,
      required: true,
    },
    diffFilesLength: {
      type: Number,
      required: false,
20
      default: null,
21
22
23
24
    },
  },
  computed: {
    filesText() {
25
      return n__('File', 'Files', this.diffFilesLength);
26
27
28
29
    },
    isCompareVersionsHeader() {
      return Boolean(this.diffFilesLength);
    },
30
31
32
    hasDiffFiles() {
      return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0;
    },
33
34
35
36
37
38
39
40
41
42
43
44
  },
};
</script>

<template>
  <div
    class="diff-stats"
    :class="{
      'is-compare-versions-header d-none d-lg-inline-flex': isCompareVersionsHeader,
      'd-inline-flex': !isCompareVersionsHeader,
    }"
  >
45
    <div v-if="hasDiffFiles" class="diff-stats-group">
46
47
      <icon name="doc-code" class="diff-stats-icon text-secondary" />
      <strong>{{ diffFilesLength }} {{ filesText }}</strong>
48
    </div>
49
50
    <div class="diff-stats-group cgreen">
      <icon name="file-addition" class="diff-stats-icon" /> <strong>{{ addedLines }}</strong>
51
    </div>
52
53
    <div class="diff-stats-group cred">
      <icon name="file-deletion" class="diff-stats-icon" /> <strong>{{ removedLines }}</strong>
54
55
56
    </div>
  </div>
</template>