summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/diff_stats.vue
blob: 0303700f42a6a510071aa1dd9f2646c3946f4d74 (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
<script>
import { GlIcon } from '@gitlab/ui';
import { isNumber } from 'lodash';
import { n__ } from '~/locale';

export default {
  components: { GlIcon },
  props: {
    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;
    },
  },
};
</script>

<template>
  <div
    class="diff-stats"
    :class="{
      'is-compare-versions-header d-none d-lg-inline-flex': isCompareVersionsHeader,
      'd-none d-sm-inline-flex': !isCompareVersionsHeader,
    }"
  >
    <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 cgreen d-flex align-items-center"
      :class="{ bold: isCompareVersionsHeader }"
    >
      <span>+</span>
      <span class="js-file-addition-line">{{ addedLines }}</span>
    </div>
    <div
      class="diff-stats-group cred d-flex align-items-center"
      :class="{ bold: isCompareVersionsHeader }"
    >
      <span>-</span>
      <span class="js-file-deletion-line">{{ removedLines }}</span>
    </div>
  </div>
</template>