Commit df766246 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'fix-nan-no-diff' into 'master'

Do not show 'NaN files' in diff stats when a MR diff does not have any changes.

See merge request gitlab-org/gitlab!24087
parents 3d9d3567 664187f6
<script> <script>
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { n__ } from '~/locale'; import { n__ } from '~/locale';
import { isNumber } from 'underscore';
export default { export default {
components: { Icon }, components: { Icon },
...@@ -16,7 +17,7 @@ export default { ...@@ -16,7 +17,7 @@ export default {
diffFilesLength: { diffFilesLength: {
type: Number, type: Number,
required: false, required: false,
default: null, default: 0,
}, },
}, },
computed: { computed: {
...@@ -26,6 +27,9 @@ export default { ...@@ -26,6 +27,9 @@ export default {
isCompareVersionsHeader() { isCompareVersionsHeader() {
return Boolean(this.diffFilesLength); return Boolean(this.diffFilesLength);
}, },
hasDiffFiles() {
return isNumber(this.diffFilesLength) && this.diffFilesLength >= 0;
},
}, },
}; };
</script> </script>
...@@ -38,7 +42,7 @@ export default { ...@@ -38,7 +42,7 @@ export default {
'd-inline-flex': !isCompareVersionsHeader, 'd-inline-flex': !isCompareVersionsHeader,
}" }"
> >
<div v-if="diffFilesLength !== null" class="diff-stats-group"> <div v-if="hasDiffFiles" class="diff-stats-group">
<icon name="doc-code" class="diff-stats-icon text-secondary" /> <icon name="doc-code" class="diff-stats-icon text-secondary" />
<strong>{{ diffFilesLength }} {{ filesText }}</strong> <strong>{{ diffFilesLength }} {{ filesText }}</strong>
</div> </div>
......
---
title: Fix showing 'NaN files' when a MR diff does not have any changes
merge_request: 24002
author:
type: fixed
...@@ -3,11 +3,12 @@ import Icon from '~/vue_shared/components/icon.vue'; ...@@ -3,11 +3,12 @@ import Icon from '~/vue_shared/components/icon.vue';
import DiffStats from '~/diffs/components/diff_stats.vue'; import DiffStats from '~/diffs/components/diff_stats.vue';
describe('diff_stats', () => { describe('diff_stats', () => {
it('does not render a group if diffFileLengths is not passed in', () => { it('does not render a group if diffFileLengths is not a number', () => {
const wrapper = shallowMount(DiffStats, { const wrapper = shallowMount(DiffStats, {
propsData: { propsData: {
addedLines: 1, addedLines: 1,
removedLines: 2, removedLines: 2,
diffFilesLength: Number.NaN,
}, },
}); });
const groups = wrapper.findAll('.diff-stats-group'); const groups = wrapper.findAll('.diff-stats-group');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment