2018-06-21 08:22:40 -04:00
|
|
|
<script>
|
|
|
|
import { mapState, mapGetters, mapActions } from 'vuex';
|
2019-12-09 07:07:58 -05:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import Mousetrap from 'mousetrap';
|
2018-06-21 08:22:40 -04:00
|
|
|
import { __ } from '~/locale';
|
|
|
|
import createFlash from '~/flash';
|
2019-02-15 05:25:33 -05:00
|
|
|
import PanelResizer from '~/vue_shared/components/panel_resizer.vue';
|
2019-12-09 07:07:58 -05:00
|
|
|
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2020-01-14 07:07:41 -05:00
|
|
|
import { isSingleViewStyle } from '~/helpers/diffs_helper';
|
2018-06-29 03:22:07 -04:00
|
|
|
import eventHub from '../../notes/event_hub';
|
2018-06-21 08:22:40 -04:00
|
|
|
import CompareVersions from './compare_versions.vue';
|
|
|
|
import DiffFile from './diff_file.vue';
|
|
|
|
import NoChanges from './no_changes.vue';
|
|
|
|
import HiddenFilesWarning from './hidden_files_warning.vue';
|
2018-09-26 04:28:50 -04:00
|
|
|
import CommitWidget from './commit_widget.vue';
|
2018-10-03 05:05:43 -04:00
|
|
|
import TreeList from './tree_list.vue';
|
2019-02-15 05:25:33 -05:00
|
|
|
import {
|
|
|
|
TREE_LIST_WIDTH_STORAGE_KEY,
|
|
|
|
INITIAL_TREE_WIDTH,
|
|
|
|
MIN_TREE_WIDTH,
|
|
|
|
MAX_TREE_WIDTH,
|
|
|
|
TREE_HIDE_STATS_WIDTH,
|
2019-03-19 07:34:21 -04:00
|
|
|
MR_TREE_SHOW_KEY,
|
2019-03-28 17:37:06 -04:00
|
|
|
CENTERED_LIMITED_CONTAINER_CLASSES,
|
2019-02-15 05:25:33 -05:00
|
|
|
} from '../constants';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DiffsApp',
|
|
|
|
components: {
|
|
|
|
CompareVersions,
|
|
|
|
DiffFile,
|
|
|
|
NoChanges,
|
|
|
|
HiddenFilesWarning,
|
2018-09-26 04:28:50 -04:00
|
|
|
CommitWidget,
|
2018-10-03 05:05:43 -04:00
|
|
|
TreeList,
|
2018-11-07 05:06:15 -05:00
|
|
|
GlLoadingIcon,
|
2019-02-15 05:25:33 -05:00
|
|
|
PanelResizer,
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
2019-11-26 04:08:36 -05:00
|
|
|
mixins: [glFeatureFlagsMixin()],
|
2018-06-21 08:22:40 -04:00
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-11-26 04:08:36 -05:00
|
|
|
endpointMetadata: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
endpointBatch: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-06-26 14:49:22 -04:00
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
shouldShow: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
currentUser: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-12-13 14:17:19 -05:00
|
|
|
helpPagePath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-12-13 05:57:45 -05:00
|
|
|
changesEmptyStateIllustration: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2019-04-12 04:32:05 -04:00
|
|
|
isFluidLayout: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2019-06-14 09:01:24 -04:00
|
|
|
dismissEndpoint: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
showSuggestPopover: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
2018-10-19 09:09:16 -04:00
|
|
|
data() {
|
2019-02-15 05:25:33 -05:00
|
|
|
const treeWidth =
|
|
|
|
parseInt(localStorage.getItem(TREE_LIST_WIDTH_STORAGE_KEY), 10) || INITIAL_TREE_WIDTH;
|
|
|
|
|
2018-10-19 09:09:16 -04:00
|
|
|
return {
|
2019-02-15 05:25:33 -05:00
|
|
|
treeWidth,
|
2018-10-19 09:09:16 -04:00
|
|
|
};
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
isLoading: state => state.diffs.isLoading,
|
2019-11-26 04:08:36 -05:00
|
|
|
isBatchLoading: state => state.diffs.isBatchLoading,
|
2018-06-21 08:22:40 -04:00
|
|
|
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,
|
|
|
|
targetBranchName: state => state.diffs.targetBranchName,
|
|
|
|
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,
|
2019-12-19 07:07:35 -05:00
|
|
|
retrievingBatches: state => state.diffs.retrievingBatches,
|
2018-06-21 08:22:40 -04:00
|
|
|
}),
|
2018-12-13 05:57:45 -05:00
|
|
|
...mapState('diffs', ['showTreeList', 'isLoading', 'startVersion']),
|
2019-02-27 04:12:13 -05:00
|
|
|
...mapGetters('diffs', ['isParallelView', 'currentDiffIndex']),
|
2018-10-19 09:09:16 -04:00
|
|
|
...mapGetters(['isNotesFetched', 'getNoteableData']),
|
2018-06-21 08:22:40 -04:00
|
|
|
targetBranch() {
|
|
|
|
return {
|
|
|
|
branchName: this.targetBranchName,
|
|
|
|
versionIndex: -1,
|
|
|
|
path: '',
|
|
|
|
};
|
|
|
|
},
|
2018-07-17 11:47:02 -04:00
|
|
|
canCurrentUserFork() {
|
2018-11-09 14:48:41 -05:00
|
|
|
return this.currentUser.can_fork === true && this.currentUser.can_create_merge_request;
|
2018-07-17 11:47:02 -04:00
|
|
|
},
|
2018-10-03 05:05:43 -04:00
|
|
|
showCompareVersions() {
|
|
|
|
return this.mergeRequestDiffs && this.mergeRequestDiff;
|
|
|
|
},
|
2018-12-13 05:57:45 -05:00
|
|
|
renderDiffFiles() {
|
|
|
|
return (
|
|
|
|
this.diffFiles.length > 0 ||
|
|
|
|
(this.startVersion &&
|
|
|
|
this.startVersion.version_index === this.mergeRequestDiff.version_index)
|
|
|
|
);
|
|
|
|
},
|
2019-02-15 05:25:33 -05:00
|
|
|
hideFileStats() {
|
|
|
|
return this.treeWidth <= TREE_HIDE_STATS_WIDTH;
|
|
|
|
},
|
2019-03-28 17:37:06 -04:00
|
|
|
isLimitedContainer() {
|
2019-04-12 04:32:05 -04:00
|
|
|
return !this.showTreeList && !this.isParallelView && !this.isFluidLayout;
|
2019-03-28 17:37:06 -04:00
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
diffViewType() {
|
2020-01-14 07:07:41 -05:00
|
|
|
if (this.needsReload() || this.needsFirstLoad()) {
|
|
|
|
this.refetchDiffData();
|
|
|
|
}
|
2018-06-21 08:22:40 -04:00
|
|
|
this.adjustView();
|
|
|
|
},
|
|
|
|
shouldShow() {
|
2018-06-29 03:22:07 -04:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.adjustView();
|
|
|
|
},
|
2018-10-03 05:05:43 -04:00
|
|
|
isLoading: 'adjustView',
|
|
|
|
showTreeList: 'adjustView',
|
2019-12-19 07:07:35 -05:00
|
|
|
retrievingBatches(newVal) {
|
|
|
|
if (!newVal) this.unwatchDiscussions();
|
2019-12-04 13:08:46 -05:00
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
mounted() {
|
2019-06-14 09:01:24 -04:00
|
|
|
this.setBaseConfig({
|
|
|
|
endpoint: this.endpoint,
|
2019-11-26 04:08:36 -05:00
|
|
|
endpointMetadata: this.endpointMetadata,
|
|
|
|
endpointBatch: this.endpointBatch,
|
2019-06-14 09:01:24 -04:00
|
|
|
projectPath: this.projectPath,
|
|
|
|
dismissEndpoint: this.dismissEndpoint,
|
|
|
|
showSuggestPopover: this.showSuggestPopover,
|
2019-12-12 04:07:48 -05:00
|
|
|
useSingleDiffStyle: this.glFeatures.singleMrDiffView,
|
2019-06-14 09:01:24 -04:00
|
|
|
});
|
2018-06-29 03:22:07 -04:00
|
|
|
|
|
|
|
if (this.shouldShow) {
|
|
|
|
this.fetchData();
|
|
|
|
}
|
2018-11-30 03:48:47 -05:00
|
|
|
|
|
|
|
const id = window && window.location && window.location.hash;
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
this.setHighlightedRow(id.slice(1));
|
|
|
|
}
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.adjustView();
|
2019-01-16 10:17:10 -05:00
|
|
|
eventHub.$once('fetchDiffData', this.fetchData);
|
2019-05-10 14:06:37 -04:00
|
|
|
eventHub.$on('refetchDiffData', this.refetchDiffData);
|
2019-03-28 17:37:06 -04:00
|
|
|
this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES;
|
2019-12-19 07:07:35 -05:00
|
|
|
|
|
|
|
this.unwatchDiscussions = this.$watch(
|
|
|
|
() => `${this.diffFiles.length}:${this.$store.state.notes.discussions.length}`,
|
|
|
|
() => this.setDiscussions(),
|
|
|
|
);
|
2019-01-16 10:17:10 -05:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('fetchDiffData', this.fetchData);
|
2019-05-10 14:06:37 -04:00
|
|
|
eventHub.$off('refetchDiffData', this.refetchDiffData);
|
2019-02-27 04:12:13 -05:00
|
|
|
this.removeEventListeners();
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
methods: {
|
2018-10-25 11:51:00 -04:00
|
|
|
...mapActions(['startTaskList']),
|
2018-08-13 04:47:54 -04:00
|
|
|
...mapActions('diffs', [
|
|
|
|
'setBaseConfig',
|
|
|
|
'fetchDiffFiles',
|
2019-11-26 04:08:36 -05:00
|
|
|
'fetchDiffFilesMeta',
|
|
|
|
'fetchDiffFilesBatch',
|
2018-08-13 04:47:54 -04:00
|
|
|
'startRenderDiffsQueue',
|
|
|
|
'assignDiscussionsToDiff',
|
2018-11-30 03:48:47 -05:00
|
|
|
'setHighlightedRow',
|
2019-02-15 05:25:33 -05:00
|
|
|
'cacheTreeListWidth',
|
2019-02-27 04:12:13 -05:00
|
|
|
'scrollToFile',
|
2019-03-19 07:34:21 -04:00
|
|
|
'toggleShowTreeList',
|
2018-08-13 04:47:54 -04:00
|
|
|
]),
|
2019-05-10 14:06:37 -04:00
|
|
|
refetchDiffData() {
|
|
|
|
this.fetchData(false);
|
|
|
|
},
|
2019-12-04 13:08:46 -05:00
|
|
|
startDiffRendering() {
|
|
|
|
requestIdleCallback(
|
|
|
|
() => {
|
|
|
|
this.startRenderDiffsQueue();
|
|
|
|
},
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
|
|
|
},
|
2020-01-14 07:07:41 -05:00
|
|
|
needsReload() {
|
|
|
|
return (
|
|
|
|
this.glFeatures.singleMrDiffView &&
|
|
|
|
this.diffFiles.length &&
|
|
|
|
isSingleViewStyle(this.diffFiles[0])
|
|
|
|
);
|
|
|
|
},
|
|
|
|
needsFirstLoad() {
|
|
|
|
return this.glFeatures.singleMrDiffView && !this.diffFiles.length;
|
|
|
|
},
|
2019-05-10 14:06:37 -04:00
|
|
|
fetchData(toggleTree = true) {
|
2019-12-17 13:07:48 -05:00
|
|
|
if (this.glFeatures.diffsBatchLoad) {
|
2019-11-26 04:08:36 -05:00
|
|
|
this.fetchDiffFilesMeta()
|
|
|
|
.then(() => {
|
|
|
|
if (toggleTree) this.hideTreeListIfJustOneFile();
|
2019-12-04 13:08:46 -05:00
|
|
|
|
|
|
|
this.startDiffRendering();
|
2019-11-26 04:08:36 -05:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
2019-03-19 07:34:21 -04:00
|
|
|
|
2019-11-26 04:08:36 -05:00
|
|
|
this.fetchDiffFilesBatch()
|
2020-01-14 07:07:41 -05:00
|
|
|
.then(() => {
|
|
|
|
// 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();
|
|
|
|
})
|
2019-12-04 13:08:46 -05:00
|
|
|
.then(() => this.startDiffRendering())
|
2019-11-26 04:08:36 -05:00
|
|
|
.catch(() => {
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.fetchDiffFiles()
|
|
|
|
.then(() => {
|
|
|
|
if (toggleTree) {
|
|
|
|
this.hideTreeListIfJustOneFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
requestIdleCallback(
|
|
|
|
() => {
|
2020-01-14 07:07:41 -05:00
|
|
|
this.setDiscussions();
|
2019-11-26 04:08:36 -05:00
|
|
|
this.startRenderDiffsQueue();
|
|
|
|
},
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
|
|
|
}
|
2018-06-29 03:22:07 -04:00
|
|
|
|
|
|
|
if (!this.isNotesFetched) {
|
|
|
|
eventHub.$emit('fetchNotesData');
|
|
|
|
}
|
|
|
|
},
|
2018-09-05 04:28:49 -04:00
|
|
|
setDiscussions() {
|
2019-12-19 07:07:35 -05:00
|
|
|
requestIdleCallback(
|
|
|
|
() =>
|
|
|
|
this.assignDiscussionsToDiff()
|
|
|
|
.then(this.$nextTick)
|
|
|
|
.then(this.startTaskList),
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
2018-09-05 04:28:49 -04:00
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
adjustView() {
|
2018-10-03 05:05:43 -04:00
|
|
|
if (this.shouldShow) {
|
|
|
|
this.$nextTick(() => {
|
2019-02-27 04:12:13 -05:00
|
|
|
this.setEventListeners();
|
2018-10-03 05:05:43 -04:00
|
|
|
});
|
2019-02-27 04:12:13 -05:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
removeEventListeners() {
|
|
|
|
Mousetrap.unbind(['[', 'k', ']', 'j']);
|
|
|
|
},
|
|
|
|
jumpToFile(step) {
|
|
|
|
const targetIndex = this.currentDiffIndex + step;
|
|
|
|
if (targetIndex >= 0 && targetIndex < this.diffFiles.length) {
|
|
|
|
this.scrollToFile(this.diffFiles[targetIndex].file_path);
|
2018-06-21 08:22:40 -04:00
|
|
|
}
|
|
|
|
},
|
2019-03-19 07:34:21 -04:00
|
|
|
hideTreeListIfJustOneFile() {
|
|
|
|
const storedTreeShow = localStorage.getItem(MR_TREE_SHOW_KEY);
|
|
|
|
|
|
|
|
if ((storedTreeShow === null && this.diffFiles.length <= 1) || storedTreeShow === 'false') {
|
|
|
|
this.toggleShowTreeList(false);
|
|
|
|
}
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
2019-02-15 05:25:33 -05:00
|
|
|
minTreeWidth: MIN_TREE_WIDTH,
|
|
|
|
maxTreeWidth: MAX_TREE_WIDTH,
|
2018-06-21 08:22:40 -04:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2018-06-30 09:17:46 -04:00
|
|
|
<div v-show="shouldShow">
|
2018-11-16 15:07:38 -05:00
|
|
|
<div v-if="isLoading" class="loading"><gl-loading-icon /></div>
|
|
|
|
<div v-else id="diffs" :class="{ active: shouldShow }" class="diffs tab-pane">
|
2018-06-21 08:22:40 -04:00
|
|
|
<compare-versions
|
|
|
|
:merge-request-diffs="mergeRequestDiffs"
|
|
|
|
:merge-request-diff="mergeRequestDiff"
|
|
|
|
:target-branch="targetBranch"
|
2019-03-28 17:37:06 -04:00
|
|
|
:is-limited-container="isLimitedContainer"
|
2018-06-21 08:22:40 -04:00
|
|
|
/>
|
|
|
|
|
|
|
|
<hidden-files-warning
|
|
|
|
v-if="renderOverflowWarning"
|
|
|
|
:visible="numVisibleFiles"
|
|
|
|
:total="numTotalFiles"
|
|
|
|
:plain-diff-path="plainDiffPath"
|
|
|
|
:email-patch-path="emailPatchPath"
|
|
|
|
/>
|
|
|
|
|
2018-10-18 03:50:38 -04:00
|
|
|
<div
|
|
|
|
:data-can-create-note="getNoteableData.current_user.can_create_note"
|
|
|
|
class="files d-flex prepend-top-default"
|
|
|
|
>
|
2019-02-15 05:25:33 -05:00
|
|
|
<div
|
|
|
|
v-show="showTreeList"
|
|
|
|
:style="{ width: `${treeWidth}px` }"
|
2019-08-12 21:20:15 -04:00
|
|
|
class="diff-tree-list js-diff-tree-list mr-3"
|
2019-02-15 05:25:33 -05:00
|
|
|
>
|
|
|
|
<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>
|
2019-03-28 17:37:06 -04:00
|
|
|
<div
|
|
|
|
class="diff-files-holder"
|
|
|
|
:class="{
|
|
|
|
[CENTERED_LIMITED_CONTAINER_CLASSES]: isLimitedContainer,
|
|
|
|
}"
|
|
|
|
>
|
2018-11-20 07:37:57 -05:00
|
|
|
<commit-widget v-if="commit" :commit="commit" />
|
2019-11-26 04:08:36 -05:00
|
|
|
<div v-if="isBatchLoading" class="loading"><gl-loading-icon /></div>
|
|
|
|
<template v-else-if="renderDiffFiles">
|
2018-11-20 07:37:57 -05:00
|
|
|
<diff-file
|
|
|
|
v-for="file in diffFiles"
|
|
|
|
:key="file.newPath"
|
|
|
|
:file="file"
|
2018-12-13 14:17:19 -05:00
|
|
|
:help-page-path="helpPagePath"
|
2018-11-20 07:37:57 -05:00
|
|
|
:can-current-user-fork="canCurrentUserFork"
|
|
|
|
/>
|
|
|
|
</template>
|
2018-12-13 05:57:45 -05:00
|
|
|
<no-changes v-else :changes-empty-state-illustration="changesEmptyStateIllustration" />
|
2018-10-03 05:05:43 -04:00
|
|
|
</div>
|
2018-06-21 08:22:40 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|