debian-mirror-gitlab/app/assets/javascripts/diffs/components/diff_stats.vue

85 lines
2.2 KiB
Vue
Raw Normal View History

2019-03-02 22:35:43 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { isNumber } from 'lodash';
2019-03-02 22:35:43 +05:30
import { n__ } from '~/locale';
2021-09-04 01:27:46 +05:30
import { isNotDiffable, stats } from '../utils/diff_file';
2019-03-02 22:35:43 +05:30
export default {
2020-11-24 15:15:51 +05:30
components: { GlIcon },
2019-03-02 22:35:43 +05:30
props: {
2021-09-04 01:27:46 +05:30
diffFile: {
type: Object,
required: false,
default: () => null,
},
2019-03-02 22:35:43 +05:30
addedLines: {
type: Number,
required: true,
},
removedLines: {
type: Number,
required: true,
},
2020-10-24 23:57:45 +05:30
diffFilesCountText: {
type: String,
2019-03-02 22:35:43 +05:30
required: false,
default: null,
},
},
computed: {
2020-10-24 23:57:45 +05:30
diffFilesLength() {
return parseInt(this.diffFilesCountText, 10);
},
2019-03-02 22:35:43 +05:30
filesText() {
2020-03-13 15:44:24 +05:30
return n__('file', 'files', this.diffFilesLength);
2019-03-02 22:35:43 +05:30
},
isCompareVersionsHeader() {
2020-10-24 23:57:45 +05:30
return Boolean(this.diffFilesCountText);
2019-03-02 22:35:43 +05:30
},
2020-03-13 15:44:24 +05:30
hasDiffFiles() {
return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0;
},
2021-09-04 01:27:46 +05:30
notDiffable() {
return isNotDiffable(this.diffFile);
},
fileStats() {
return stats(this.diffFile);
},
2019-03-02 22:35:43 +05:30
},
};
</script>
<template>
<div
class="diff-stats"
:class="{
2021-09-04 01:27:46 +05:30
'is-compare-versions-header gl-display-none gl-lg-display-inline-flex': isCompareVersionsHeader,
'gl-display-none gl-sm-display-inline-flex': !isCompareVersionsHeader,
2019-03-02 22:35:43 +05:30
}"
>
2021-09-04 01:27:46 +05:30
<div v-if="notDiffable" :class="fileStats.classes">
{{ fileStats.text }}
2019-03-02 22:35:43 +05:30
</div>
2021-09-04 01:27:46 +05:30
<div v-else class="diff-stats-contents">
<div v-if="hasDiffFiles" class="diff-stats-group">
2021-10-27 15:23:28 +05:30
<gl-icon name="doc-code" class="diff-stats-icon gl-text-gray-500" />
<span class="gl-text-gray-500 bold">{{ diffFilesCountText }} {{ filesText }}</span>
2021-09-04 01:27:46 +05:30
</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>
2019-03-02 22:35:43 +05:30
</div>
</div>
</template>