2018-11-08 19:23:39 +05:30
|
|
|
<script>
|
|
|
|
import { mapState, mapGetters, mapActions } from 'vuex';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlLoadingIcon, GlPagination, GlSprintf } from '@gitlab/ui';
|
2021-02-22 17:27:13 +05:30
|
|
|
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import Mousetrap from 'mousetrap';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { __ } from '~/locale';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { getParameterByName, parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2019-07-07 11:18:12 +05:30
|
|
|
import PanelResizer from '~/vue_shared/components/panel_resizer.vue';
|
2020-01-01 13:55:28 +05:30
|
|
|
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { isSingleViewStyle } from '~/helpers/diffs_helper';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { updateHistory } from '~/lib/utils/url_utility';
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
import notesEventHub from '../../notes/event_hub';
|
|
|
|
import eventHub from '../event_hub';
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
import CompareVersions from './compare_versions.vue';
|
|
|
|
import DiffFile from './diff_file.vue';
|
|
|
|
import NoChanges from './no_changes.vue';
|
2018-12-05 23:21:45 +05:30
|
|
|
import CommitWidget from './commit_widget.vue';
|
|
|
|
import TreeList from './tree_list.vue';
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
import HiddenFilesWarning from './hidden_files_warning.vue';
|
|
|
|
import MergeConflictWarning from './merge_conflict_warning.vue';
|
|
|
|
import CollapsedFilesWarning from './collapsed_files_warning.vue';
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
import { diffsApp } from '../utils/performance';
|
2021-02-22 17:27:13 +05:30
|
|
|
import { fileByFile } from '../utils/preferences';
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
import {
|
|
|
|
TREE_LIST_WIDTH_STORAGE_KEY,
|
|
|
|
INITIAL_TREE_WIDTH,
|
|
|
|
MIN_TREE_WIDTH,
|
|
|
|
MAX_TREE_WIDTH,
|
|
|
|
TREE_HIDE_STATS_WIDTH,
|
|
|
|
MR_TREE_SHOW_KEY,
|
|
|
|
CENTERED_LIMITED_CONTAINER_CLASSES,
|
2020-11-24 15:15:51 +05:30
|
|
|
ALERT_OVERFLOW_HIDDEN,
|
|
|
|
ALERT_MERGE_CONFLICT,
|
|
|
|
ALERT_COLLAPSED_FILES,
|
2021-02-22 17:27:13 +05:30
|
|
|
EVT_VIEW_FILE_BY_FILE,
|
2019-07-07 11:18:12 +05:30
|
|
|
} from '../constants';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DiffsApp',
|
|
|
|
components: {
|
|
|
|
CompareVersions,
|
|
|
|
DiffFile,
|
|
|
|
NoChanges,
|
|
|
|
HiddenFilesWarning,
|
2020-11-24 15:15:51 +05:30
|
|
|
MergeConflictWarning,
|
|
|
|
CollapsedFilesWarning,
|
2018-12-05 23:21:45 +05:30
|
|
|
CommitWidget,
|
|
|
|
TreeList,
|
2018-12-13 13:39:08 +05:30
|
|
|
GlLoadingIcon,
|
2019-07-07 11:18:12 +05:30
|
|
|
PanelResizer,
|
2020-11-24 15:15:51 +05:30
|
|
|
GlPagination,
|
|
|
|
GlSprintf,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
mixins: [glFeatureFlagsMixin()],
|
2020-11-24 15:15:51 +05:30
|
|
|
alerts: {
|
|
|
|
ALERT_OVERFLOW_HIDDEN,
|
|
|
|
ALERT_MERGE_CONFLICT,
|
|
|
|
ALERT_COLLAPSED_FILES,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
endpointMetadata: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
endpointBatch: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-08 14:13:33 +05:30
|
|
|
endpointCoverage: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
shouldShow: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
currentUser: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-02-15 15:39:39 +05:30
|
|
|
helpPagePath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
changesEmptyStateIllustration: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
isFluidLayout: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
dismissEndpoint: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
showSuggestPopover: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
fileByFileUserPreference: {
|
2020-07-28 23:09:34 +05:30
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
data() {
|
2019-07-07 11:18:12 +05:30
|
|
|
const treeWidth =
|
|
|
|
parseInt(localStorage.getItem(TREE_LIST_WIDTH_STORAGE_KEY), 10) || INITIAL_TREE_WIDTH;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
return {
|
2019-07-07 11:18:12 +05:30
|
|
|
treeWidth,
|
2020-03-13 15:44:24 +05:30
|
|
|
diffFilesLength: 0,
|
2018-12-13 13:39:08 +05:30
|
|
|
};
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
isLoading: state => state.diffs.isLoading,
|
2020-01-01 13:55:28 +05:30
|
|
|
isBatchLoading: state => state.diffs.isBatchLoading,
|
2018-11-08 19:23:39 +05:30
|
|
|
diffFiles: state => state.diffs.diffFiles,
|
|
|
|
diffViewType: state => state.diffs.diffViewType,
|
|
|
|
mergeRequestDiffs: state => state.diffs.mergeRequestDiffs,
|
|
|
|
mergeRequestDiff: state => state.diffs.mergeRequestDiff,
|
|
|
|
commit: state => state.diffs.commit,
|
|
|
|
renderOverflowWarning: state => state.diffs.renderOverflowWarning,
|
|
|
|
numTotalFiles: state => state.diffs.realSize,
|
|
|
|
numVisibleFiles: state => state.diffs.size,
|
|
|
|
plainDiffPath: state => state.diffs.plainDiffPath,
|
|
|
|
emailPatchPath: state => state.diffs.emailPatchPath,
|
2020-03-13 15:44:24 +05:30
|
|
|
retrievingBatches: state => state.diffs.retrievingBatches,
|
2018-11-08 19:23:39 +05:30
|
|
|
}),
|
2020-10-24 23:57:45 +05:30
|
|
|
...mapState('diffs', [
|
|
|
|
'showTreeList',
|
|
|
|
'isLoading',
|
|
|
|
'startVersion',
|
|
|
|
'currentDiffFileId',
|
|
|
|
'isTreeLoaded',
|
|
|
|
'conflictResolutionPath',
|
|
|
|
'canMerge',
|
|
|
|
'hasConflicts',
|
2021-02-22 17:27:13 +05:30
|
|
|
'viewDiffsFileByFile',
|
2020-10-24 23:57:45 +05:30
|
|
|
]),
|
2021-01-29 00:20:46 +05:30
|
|
|
...mapGetters('diffs', ['whichCollapsedTypes', 'isParallelView', 'currentDiffIndex']),
|
2018-12-13 13:39:08 +05:30
|
|
|
...mapGetters(['isNotesFetched', 'getNoteableData']),
|
2020-07-28 23:09:34 +05:30
|
|
|
diffs() {
|
|
|
|
if (!this.viewDiffsFileByFile) {
|
|
|
|
return this.diffFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.diffFiles.filter((file, i) => {
|
|
|
|
return file.file_hash === this.currentDiffFileId || (i === 0 && !this.currentDiffFileId);
|
|
|
|
});
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
canCurrentUserFork() {
|
2019-02-15 15:39:39 +05:30
|
|
|
return this.currentUser.can_fork === true && this.currentUser.can_create_merge_request;
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2019-02-15 15:39:39 +05:30
|
|
|
renderDiffFiles() {
|
|
|
|
return (
|
|
|
|
this.diffFiles.length > 0 ||
|
|
|
|
(this.startVersion &&
|
|
|
|
this.startVersion.version_index === this.mergeRequestDiff.version_index)
|
|
|
|
);
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
hideFileStats() {
|
|
|
|
return this.treeWidth <= TREE_HIDE_STATS_WIDTH;
|
|
|
|
},
|
|
|
|
isLimitedContainer() {
|
|
|
|
return !this.showTreeList && !this.isParallelView && !this.isFluidLayout;
|
|
|
|
},
|
2020-10-24 23:57:45 +05:30
|
|
|
isDiffHead() {
|
|
|
|
return parseBoolean(getParameterByName('diff_head'));
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
showFileByFileNavigation() {
|
|
|
|
return this.diffFiles.length > 1 && this.viewDiffsFileByFile;
|
|
|
|
},
|
|
|
|
currentFileNumber() {
|
|
|
|
return this.currentDiffIndex + 1;
|
|
|
|
},
|
|
|
|
previousFileNumber() {
|
|
|
|
const { currentDiffIndex } = this;
|
|
|
|
|
|
|
|
return currentDiffIndex >= 1 ? currentDiffIndex : null;
|
|
|
|
},
|
|
|
|
nextFileNumber() {
|
|
|
|
const { currentFileNumber, diffFiles } = this;
|
|
|
|
|
|
|
|
return currentFileNumber < diffFiles.length ? currentFileNumber + 1 : null;
|
|
|
|
},
|
|
|
|
visibleWarning() {
|
|
|
|
let visible = false;
|
|
|
|
|
|
|
|
if (this.renderOverflowWarning) {
|
|
|
|
visible = this.$options.alerts.ALERT_OVERFLOW_HIDDEN;
|
|
|
|
} else if (this.isDiffHead && this.hasConflicts) {
|
|
|
|
visible = this.$options.alerts.ALERT_MERGE_CONFLICT;
|
2021-01-29 00:20:46 +05:30
|
|
|
} else if (this.whichCollapsedTypes.automatic && !this.viewDiffsFileByFile) {
|
2020-11-24 15:15:51 +05:30
|
|
|
visible = this.$options.alerts.ALERT_COLLAPSED_FILES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
watch: {
|
2020-05-24 23:13:21 +05:30
|
|
|
commit(newCommit, oldCommit) {
|
|
|
|
const commitChangedAfterRender = newCommit && !this.isLoading;
|
|
|
|
const commitIsDifferent = oldCommit && newCommit.id !== oldCommit.id;
|
|
|
|
const url = window?.location ? String(window.location) : '';
|
|
|
|
|
|
|
|
if (commitChangedAfterRender && commitIsDifferent) {
|
|
|
|
updateHistory({
|
|
|
|
title: document.title,
|
|
|
|
url: url.replace(oldCommit.id, newCommit.id),
|
|
|
|
});
|
|
|
|
this.refetchDiffData();
|
|
|
|
this.adjustView();
|
|
|
|
}
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
diffViewType() {
|
|
|
|
this.adjustView();
|
|
|
|
},
|
|
|
|
shouldShow() {
|
|
|
|
// When the shouldShow property changed to true, the route is rendered for the first time
|
|
|
|
// and if we have the isLoading as true this means we didn't fetch the data
|
|
|
|
if (this.isLoading) {
|
|
|
|
this.fetchData();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.adjustView();
|
|
|
|
},
|
2018-12-05 23:21:45 +05:30
|
|
|
isLoading: 'adjustView',
|
|
|
|
showTreeList: 'adjustView',
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
mounted() {
|
2019-09-04 21:01:54 +05:30
|
|
|
this.setBaseConfig({
|
|
|
|
endpoint: this.endpoint,
|
2020-01-01 13:55:28 +05:30
|
|
|
endpointMetadata: this.endpointMetadata,
|
|
|
|
endpointBatch: this.endpointBatch,
|
2020-04-08 14:13:33 +05:30
|
|
|
endpointCoverage: this.endpointCoverage,
|
2019-09-04 21:01:54 +05:30
|
|
|
projectPath: this.projectPath,
|
|
|
|
dismissEndpoint: this.dismissEndpoint,
|
|
|
|
showSuggestPopover: this.showSuggestPopover,
|
2021-02-22 17:27:13 +05:30
|
|
|
viewDiffsFileByFile: fileByFile(this.fileByFileUserPreference),
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
if (this.shouldShow) {
|
|
|
|
this.fetchData();
|
|
|
|
}
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
const id = window?.location?.hash;
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
if (id && id.indexOf('#note') !== 0) {
|
|
|
|
this.setHighlightedRow(
|
|
|
|
id
|
|
|
|
.split('diff-content')
|
|
|
|
.pop()
|
|
|
|
.slice(1),
|
|
|
|
);
|
2019-02-15 15:39:39 +05:30
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
beforeCreate() {
|
|
|
|
diffsApp.instrument();
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
created() {
|
|
|
|
this.adjustView();
|
2021-02-22 17:27:13 +05:30
|
|
|
this.subscribeToEvents();
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
this.unwatchDiscussions = this.$watch(
|
|
|
|
() => `${this.diffFiles.length}:${this.$store.state.notes.discussions.length}`,
|
|
|
|
() => this.setDiscussions(),
|
|
|
|
);
|
|
|
|
|
|
|
|
this.unwatchRetrievingBatches = this.$watch(
|
|
|
|
() => `${this.retrievingBatches}:${this.$store.state.notes.discussions.length}`,
|
|
|
|
() => {
|
|
|
|
if (!this.retrievingBatches && this.$store.state.notes.discussions.length) {
|
|
|
|
this.unwatchDiscussions();
|
|
|
|
this.unwatchRetrievingBatches();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2021-01-29 00:20:46 +05:30
|
|
|
diffsApp.deinstrument();
|
2021-02-22 17:27:13 +05:30
|
|
|
this.unsubscribeFromEvents();
|
2019-07-07 11:18:12 +05:30
|
|
|
this.removeEventListeners();
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2019-02-15 15:39:39 +05:30
|
|
|
...mapActions(['startTaskList']),
|
2018-11-20 20:47:30 +05:30
|
|
|
...mapActions('diffs', [
|
2020-05-24 23:13:21 +05:30
|
|
|
'moveToNeighboringCommit',
|
2018-11-20 20:47:30 +05:30
|
|
|
'setBaseConfig',
|
2020-01-01 13:55:28 +05:30
|
|
|
'fetchDiffFilesMeta',
|
|
|
|
'fetchDiffFilesBatch',
|
2020-04-08 14:13:33 +05:30
|
|
|
'fetchCoverageFiles',
|
2018-11-20 20:47:30 +05:30
|
|
|
'startRenderDiffsQueue',
|
|
|
|
'assignDiscussionsToDiff',
|
2019-02-15 15:39:39 +05:30
|
|
|
'setHighlightedRow',
|
2019-07-07 11:18:12 +05:30
|
|
|
'cacheTreeListWidth',
|
|
|
|
'scrollToFile',
|
2021-02-22 17:27:13 +05:30
|
|
|
'setShowTreeList',
|
2020-07-28 23:09:34 +05:30
|
|
|
'navigateToDiffFileIndex',
|
2021-02-22 17:27:13 +05:30
|
|
|
'setFileByFile',
|
2018-11-20 20:47:30 +05:30
|
|
|
]),
|
2021-02-22 17:27:13 +05:30
|
|
|
subscribeToEvents() {
|
|
|
|
notesEventHub.$once('fetchDiffData', this.fetchData);
|
|
|
|
notesEventHub.$on('refetchDiffData', this.refetchDiffData);
|
|
|
|
eventHub.$on(EVT_VIEW_FILE_BY_FILE, this.fileByFileListener);
|
|
|
|
},
|
|
|
|
unsubscribeFromEvents() {
|
|
|
|
eventHub.$off(EVT_VIEW_FILE_BY_FILE, this.fileByFileListener);
|
|
|
|
notesEventHub.$off('refetchDiffData', this.refetchDiffData);
|
|
|
|
notesEventHub.$off('fetchDiffData', this.fetchData);
|
|
|
|
},
|
|
|
|
fileByFileListener({ setting } = {}) {
|
|
|
|
this.setFileByFile({ fileByFile: setting });
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
navigateToDiffFileNumber(number) {
|
|
|
|
this.navigateToDiffFileIndex(number - 1);
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
refetchDiffData() {
|
|
|
|
this.fetchData(false);
|
|
|
|
},
|
2020-01-01 13:55:28 +05:30
|
|
|
startDiffRendering() {
|
|
|
|
requestIdleCallback(
|
|
|
|
() => {
|
|
|
|
this.startRenderDiffsQueue();
|
|
|
|
},
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
needsReload() {
|
2020-11-24 15:15:51 +05:30
|
|
|
return this.diffFiles.length && isSingleViewStyle(this.diffFiles[0]);
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
needsFirstLoad() {
|
2020-11-24 15:15:51 +05:30
|
|
|
return !this.diffFiles.length;
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
fetchData(toggleTree = true) {
|
2020-11-24 15:15:51 +05:30
|
|
|
this.fetchDiffFilesMeta()
|
|
|
|
.then(({ real_size }) => {
|
|
|
|
this.diffFilesLength = parseInt(real_size, 10);
|
2021-02-22 17:27:13 +05:30
|
|
|
if (toggleTree) this.setTreeDisplay();
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
this.startDiffRendering();
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
this.fetchDiffFilesBatch()
|
|
|
|
.then(() => {
|
2021-02-22 17:27:13 +05:30
|
|
|
if (toggleTree) this.setTreeDisplay();
|
2020-11-24 15:15:51 +05:30
|
|
|
// Guarantee the discussions are assigned after the batch finishes.
|
|
|
|
// Just watching the length of the discussions or the diff files
|
|
|
|
// isn't enough, because with split diff loading, neither will
|
|
|
|
// change when loading the other half of the diff files.
|
|
|
|
this.setDiscussions();
|
|
|
|
})
|
|
|
|
.then(() => this.startDiffRendering())
|
|
|
|
.catch(() => {
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
if (this.endpointCoverage) {
|
|
|
|
this.fetchCoverageFiles();
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if (!this.isNotesFetched) {
|
2021-02-22 17:27:13 +05:30
|
|
|
notesEventHub.$emit('fetchNotesData');
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
|
|
|
},
|
2018-11-20 20:47:30 +05:30
|
|
|
setDiscussions() {
|
2020-03-13 15:44:24 +05:30
|
|
|
requestIdleCallback(
|
|
|
|
() =>
|
|
|
|
this.assignDiscussionsToDiff()
|
|
|
|
.then(this.$nextTick)
|
|
|
|
.then(this.startTaskList),
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
adjustView() {
|
2018-12-05 23:21:45 +05:30
|
|
|
if (this.shouldShow) {
|
|
|
|
this.$nextTick(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
this.setEventListeners();
|
2018-12-05 23:21:45 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
} else {
|
|
|
|
this.removeEventListeners();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setEventListeners() {
|
|
|
|
Mousetrap.bind(['[', 'k', ']', 'j'], (e, combo) => {
|
|
|
|
switch (combo) {
|
|
|
|
case '[':
|
|
|
|
case 'k':
|
|
|
|
this.jumpToFile(-1);
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
case 'j':
|
|
|
|
this.jumpToFile(+1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
if (this.commit && this.glFeatures.mrCommitNeighborNav) {
|
|
|
|
Mousetrap.bind('c', () => this.moveToNeighboringCommit({ direction: 'next' }));
|
|
|
|
Mousetrap.bind('x', () => this.moveToNeighboringCommit({ direction: 'previous' }));
|
|
|
|
}
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
removeEventListeners() {
|
|
|
|
Mousetrap.unbind(['[', 'k', ']', 'j']);
|
2020-05-24 23:13:21 +05:30
|
|
|
Mousetrap.unbind('c');
|
|
|
|
Mousetrap.unbind('x');
|
2019-07-07 11:18:12 +05:30
|
|
|
},
|
|
|
|
jumpToFile(step) {
|
|
|
|
const targetIndex = this.currentDiffIndex + step;
|
|
|
|
if (targetIndex >= 0 && targetIndex < this.diffFiles.length) {
|
|
|
|
this.scrollToFile(this.diffFiles[targetIndex].file_path);
|
|
|
|
}
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
setTreeDisplay() {
|
2019-07-07 11:18:12 +05:30
|
|
|
const storedTreeShow = localStorage.getItem(MR_TREE_SHOW_KEY);
|
2021-02-22 17:27:13 +05:30
|
|
|
let showTreeList = true;
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
if (storedTreeShow !== null) {
|
|
|
|
showTreeList = parseBoolean(storedTreeShow);
|
|
|
|
} else if (!bp.isDesktop() || (!this.isBatchLoading && this.diffFiles.length <= 1)) {
|
|
|
|
showTreeList = false;
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
return this.setShowTreeList({ showTreeList, saving: false });
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
minTreeWidth: MIN_TREE_WIDTH,
|
|
|
|
maxTreeWidth: MAX_TREE_WIDTH,
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div v-show="shouldShow">
|
2020-10-24 23:57:45 +05:30
|
|
|
<div v-if="isLoading || !isTreeLoaded" class="loading"><gl-loading-icon size="lg" /></div>
|
2019-02-15 15:39:39 +05:30
|
|
|
<div v-else id="diffs" :class="{ active: shouldShow }" class="diffs tab-pane">
|
2018-11-08 19:23:39 +05:30
|
|
|
<compare-versions
|
|
|
|
:merge-request-diffs="mergeRequestDiffs"
|
2019-07-07 11:18:12 +05:30
|
|
|
:is-limited-container="isLimitedContainer"
|
2020-10-24 23:57:45 +05:30
|
|
|
:diff-files-count-text="numTotalFiles"
|
2018-11-08 19:23:39 +05:30
|
|
|
/>
|
|
|
|
|
|
|
|
<hidden-files-warning
|
2020-11-24 15:15:51 +05:30
|
|
|
v-if="visibleWarning == $options.alerts.ALERT_OVERFLOW_HIDDEN"
|
2018-11-08 19:23:39 +05:30
|
|
|
:visible="numVisibleFiles"
|
|
|
|
:total="numTotalFiles"
|
|
|
|
:plain-diff-path="plainDiffPath"
|
|
|
|
:email-patch-path="emailPatchPath"
|
|
|
|
/>
|
2020-11-24 15:15:51 +05:30
|
|
|
<merge-conflict-warning
|
|
|
|
v-if="visibleWarning == $options.alerts.ALERT_MERGE_CONFLICT"
|
|
|
|
:limited="isLimitedContainer"
|
|
|
|
:resolution-path="conflictResolutionPath"
|
|
|
|
:mergeable="canMerge"
|
|
|
|
/>
|
|
|
|
<collapsed-files-warning
|
|
|
|
v-if="visibleWarning == $options.alerts.ALERT_COLLAPSED_FILES"
|
|
|
|
:limited="isLimitedContainer"
|
|
|
|
/>
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
<div
|
|
|
|
:data-can-create-note="getNoteableData.current_user.can_create_note"
|
2020-11-24 15:15:51 +05:30
|
|
|
class="files d-flex gl-mt-2"
|
2018-12-13 13:39:08 +05:30
|
|
|
>
|
2019-07-07 11:18:12 +05:30
|
|
|
<div
|
2020-07-28 23:09:34 +05:30
|
|
|
v-if="showTreeList"
|
2019-07-07 11:18:12 +05:30
|
|
|
:style="{ width: `${treeWidth}px` }"
|
2021-01-03 14:25:43 +05:30
|
|
|
class="diff-tree-list js-diff-tree-list px-3 pr-md-0"
|
2019-07-07 11:18:12 +05:30
|
|
|
>
|
|
|
|
<panel-resizer
|
|
|
|
:size.sync="treeWidth"
|
|
|
|
:start-size="treeWidth"
|
|
|
|
:min-size="$options.minTreeWidth"
|
|
|
|
:max-size="$options.maxTreeWidth"
|
|
|
|
side="right"
|
|
|
|
@resize-end="cacheTreeListWidth"
|
|
|
|
/>
|
|
|
|
<tree-list :hide-file-stats="hideFileStats" />
|
|
|
|
</div>
|
|
|
|
<div
|
2021-01-03 14:25:43 +05:30
|
|
|
class="col-12 col-md-auto diff-files-holder"
|
2019-07-07 11:18:12 +05:30
|
|
|
:class="{
|
|
|
|
[CENTERED_LIMITED_CONTAINER_CLASSES]: isLimitedContainer,
|
|
|
|
}"
|
|
|
|
>
|
2020-10-24 23:57:45 +05:30
|
|
|
<commit-widget v-if="commit" :commit="commit" :collapsible="false" />
|
2020-04-08 14:13:33 +05:30
|
|
|
<div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div>
|
2020-01-01 13:55:28 +05:30
|
|
|
<template v-else-if="renderDiffFiles">
|
2019-02-15 15:39:39 +05:30
|
|
|
<diff-file
|
2021-01-29 00:20:46 +05:30
|
|
|
v-for="(file, index) in diffs"
|
2019-02-15 15:39:39 +05:30
|
|
|
:key="file.newPath"
|
|
|
|
:file="file"
|
2021-01-29 00:20:46 +05:30
|
|
|
:is-first-file="index === 0"
|
|
|
|
:is-last-file="index === diffs.length - 1"
|
2019-02-15 15:39:39 +05:30
|
|
|
:help-page-path="helpPagePath"
|
|
|
|
:can-current-user-fork="canCurrentUserFork"
|
2020-07-28 23:09:34 +05:30
|
|
|
:view-diffs-file-by-file="viewDiffsFileByFile"
|
2019-02-15 15:39:39 +05:30
|
|
|
/>
|
2020-11-24 15:15:51 +05:30
|
|
|
<div
|
|
|
|
v-if="showFileByFileNavigation"
|
|
|
|
data-testid="file-by-file-navigation"
|
|
|
|
class="gl-display-grid gl-text-center"
|
|
|
|
>
|
|
|
|
<gl-pagination
|
|
|
|
class="gl-mx-auto"
|
|
|
|
:value="currentFileNumber"
|
|
|
|
:prev-page="previousFileNumber"
|
|
|
|
:next-page="nextFileNumber"
|
|
|
|
@input="navigateToDiffFileNumber"
|
|
|
|
/>
|
|
|
|
<gl-sprintf :message="__('File %{current} of %{total}')">
|
|
|
|
<template #current>{{ currentFileNumber }}</template>
|
|
|
|
<template #total>{{ diffFiles.length }}</template>
|
|
|
|
</gl-sprintf>
|
2020-07-28 23:09:34 +05:30
|
|
|
</div>
|
2021-02-22 17:27:13 +05:30
|
|
|
<gl-loading-icon v-else-if="retrievingBatches" size="lg" />
|
2019-02-15 15:39:39 +05:30
|
|
|
</template>
|
|
|
|
<no-changes v-else :changes-empty-state-illustration="changesEmptyStateIllustration" />
|
2018-12-05 23:21:45 +05:30
|
|
|
</div>
|
2018-11-08 19:23:39 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|