Commit 0ffdf51d authored by Thomas Randolph's avatar Thomas Randolph

Add current file and total files to the file-by-file nav

parent 6aea0191
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { GlLoadingIcon, GlButton, GlAlert, GlPagination } from '@gitlab/ui'; import { GlLoadingIcon, GlButton, GlAlert, GlPagination, GlSprintf } from '@gitlab/ui';
import Mousetrap from 'mousetrap'; import Mousetrap from 'mousetrap';
import { __ } from '~/locale'; import { __ } from '~/locale';
import { getParameterByName, parseBoolean } from '~/lib/utils/common_utils'; import { getParameterByName, parseBoolean } from '~/lib/utils/common_utils';
...@@ -40,6 +40,7 @@ export default { ...@@ -40,6 +40,7 @@ export default {
GlPagination, GlPagination,
GlButton, GlButton,
GlAlert, GlAlert,
GlSprintf,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
props: { props: {
...@@ -169,15 +170,21 @@ export default { ...@@ -169,15 +170,21 @@ export default {
isDiffHead() { isDiffHead() {
return parseBoolean(getParameterByName('diff_head')); return parseBoolean(getParameterByName('diff_head'));
}, },
previousFile() { showFileByFileNavigation() {
const currentFile = this.currentDiffIndex + 1; return this.diffFiles.length > 1 && this.viewDiffsFileByFile;
},
currentFileNumber() {
return this.currentDiffIndex + 1;
},
previousFileNumber() {
const { currentDiffIndex } = this;
return currentFile >= 2 ? currentFile - 1 : null; return currentDiffIndex >= 1 ? currentDiffIndex : null;
}, },
nextFile() { nextFileNumber() {
const currentFile = this.currentDiffIndex + 1; const { currentFileNumber, diffFiles } = this;
return currentFile < this.diffFiles.length ? currentFile + 1 : null; return currentFileNumber < diffFiles.length ? currentFileNumber + 1 : null;
}, },
}, },
watch: { watch: {
...@@ -284,6 +291,9 @@ export default { ...@@ -284,6 +291,9 @@ export default {
'toggleShowTreeList', 'toggleShowTreeList',
'navigateToDiffFileIndex', 'navigateToDiffFileIndex',
]), ]),
navigateToDiffFileNumber(number) {
this.navigateToDiffFileIndex(number - 1);
},
refetchDiffData() { refetchDiffData() {
this.fetchData(false); this.fetchData(false);
}, },
...@@ -519,13 +529,22 @@ export default { ...@@ -519,13 +529,22 @@ export default {
:can-current-user-fork="canCurrentUserFork" :can-current-user-fork="canCurrentUserFork"
:view-diffs-file-by-file="viewDiffsFileByFile" :view-diffs-file-by-file="viewDiffsFileByFile"
/> />
<div v-if="viewDiffsFileByFile" class="file-by-file-navigation"> <div
v-if="showFileByFileNavigation"
data-testid="file-by-file-navigation"
class="gl-display-grid gl-text-center"
>
<gl-pagination <gl-pagination
:value="currentDiffIndex + 1" class="gl-mx-auto"
:prev-page="previousFile" :value="currentFileNumber"
:next-page="nextFile" :prev-page="previousFileNumber"
@input="val => navigateToDiffFileIndex(val - 1)" :next-page="nextFileNumber"
@input="navigateToDiffFileNumber"
/> />
<gl-sprintf :message="__('File %{current} of %{total}')">
<template #current>{{ currentFileNumber }}</template>
<template #total>{{ diffFiles.length }}</template>
</gl-sprintf>
</div> </div>
</template> </template>
<no-changes v-else :changes-empty-state-illustration="changesEmptyStateIllustration" /> <no-changes v-else :changes-empty-state-illustration="changesEmptyStateIllustration" />
......
...@@ -1035,8 +1035,3 @@ $mr-widget-min-height: 69px; ...@@ -1035,8 +1035,3 @@ $mr-widget-min-height: 69px;
.diff-file-row.is-active { .diff-file-row.is-active {
background-color: $gray-50; background-color: $gray-50;
} }
.file-by-file-navigation {
display: grid;
place-items: center;
}
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