2018-11-08 19:23:39 +05:30
|
|
|
import Vue from 'vue';
|
2023-05-27 22:25:52 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
2019-03-02 22:35:43 +05:30
|
|
|
import { mapActions, mapState, mapGetters } from 'vuex';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { apolloProvider } from '~/graphql_shared/issuable_client';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { getCookie, parseBoolean, removeCookie } from '~/lib/utils/common_utils';
|
2023-03-04 22:38:38 +05:30
|
|
|
import notesStore from '~/mr_notes/stores';
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
import eventHub from '../notes/event_hub';
|
2022-10-11 01:57:18 +05:30
|
|
|
import DiffsApp from './components/app.vue';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
import { TREE_LIST_STORAGE_KEY, DIFF_WHITESPACE_COOKIE_NAME } from './constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { getReviewsForMergeRequest } from './utils/file_reviews';
|
|
|
|
import { getDerivedMergeRequestInformation } from './utils/merge_request';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
export default function initDiffsApp(store = notesStore) {
|
2023-05-27 22:25:52 +05:30
|
|
|
const el = document.getElementById('js-diffs-app');
|
|
|
|
const { dataset } = el;
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
const vm = new Vue({
|
2023-05-27 22:25:52 +05:30
|
|
|
el,
|
2018-11-08 19:23:39 +05:30
|
|
|
name: 'MergeRequestDiffs',
|
|
|
|
components: {
|
2022-10-11 01:57:18 +05:30
|
|
|
DiffsApp,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
store,
|
2023-05-27 22:25:52 +05:30
|
|
|
apolloProvider,
|
|
|
|
provide: {
|
|
|
|
newSavedRepliesPath: dataset.savedRepliesNewPath,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
endpoint: dataset.endpoint,
|
2020-01-01 13:55:28 +05:30
|
|
|
endpointMetadata: dataset.endpointMetadata || '',
|
|
|
|
endpointBatch: dataset.endpointBatch || '',
|
2023-05-27 22:25:52 +05:30
|
|
|
endpointDiffForPath: dataset.endpointDiffForPath || '',
|
2020-04-08 14:13:33 +05:30
|
|
|
endpointCoverage: dataset.endpointCoverage || '',
|
2021-04-29 21:17:54 +05:30
|
|
|
endpointCodequality: dataset.endpointCodequality || '',
|
|
|
|
endpointUpdateUser: dataset.updateCurrentUserPath,
|
2018-11-08 19:23:39 +05:30
|
|
|
projectPath: dataset.projectPath,
|
2019-02-15 15:39:39 +05:30
|
|
|
helpPagePath: dataset.helpPagePath,
|
|
|
|
currentUser: JSON.parse(dataset.currentUserData) || {},
|
|
|
|
changesEmptyStateIllustration: dataset.changesEmptyStateIllustration,
|
2019-07-07 11:18:12 +05:30
|
|
|
isFluidLayout: parseBoolean(dataset.isFluidLayout),
|
2019-09-04 21:01:54 +05:30
|
|
|
dismissEndpoint: dataset.dismissEndpoint,
|
|
|
|
showSuggestPopover: parseBoolean(dataset.showSuggestPopover),
|
2019-12-04 20:38:33 +05:30
|
|
|
showWhitespaceDefault: parseBoolean(dataset.showWhitespaceDefault),
|
2020-07-28 23:09:34 +05:30
|
|
|
viewDiffsFileByFile: parseBoolean(dataset.fileByFileDefault),
|
2021-03-08 18:12:59 +05:30
|
|
|
defaultSuggestionCommitMessage: dataset.defaultSuggestionCommitMessage,
|
2021-10-27 15:23:28 +05:30
|
|
|
sourceProjectDefaultUrl: dataset.sourceProjectDefaultUrl,
|
|
|
|
sourceProjectFullPath: dataset.sourceProjectFullPath,
|
|
|
|
isForked: parseBoolean(dataset.isForked),
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2021-03-08 18:12:59 +05:30
|
|
|
activeTab: (state) => state.page.activeTab,
|
2018-11-08 19:23:39 +05:30
|
|
|
}),
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
created() {
|
|
|
|
const treeListStored = localStorage.getItem(TREE_LIST_STORAGE_KEY);
|
|
|
|
const renderTreeList = treeListStored !== null ? parseBoolean(treeListStored) : true;
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
this.setRenderTreeList({ renderTreeList, trackClick: false });
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
// NOTE: A "true" or "checked" value for `showWhitespace` is '0' not '1'.
|
|
|
|
// Check for cookie and save that setting for future use.
|
|
|
|
// Then delete the cookie as we are phasing it out and using the database as SSOT.
|
|
|
|
// NOTE: This can/should be removed later
|
2022-04-04 11:22:00 +05:30
|
|
|
if (getCookie(DIFF_WHITESPACE_COOKIE_NAME)) {
|
|
|
|
const hideWhitespace = getCookie(DIFF_WHITESPACE_COOKIE_NAME);
|
2021-09-04 01:27:46 +05:30
|
|
|
this.setShowWhitespace({
|
|
|
|
url: this.endpointUpdateUser,
|
|
|
|
showWhitespace: hideWhitespace !== '1',
|
2021-10-27 15:23:28 +05:30
|
|
|
trackClick: false,
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
2022-04-04 11:22:00 +05:30
|
|
|
removeCookie(DIFF_WHITESPACE_COOKIE_NAME);
|
2021-09-04 01:27:46 +05:30
|
|
|
} else {
|
|
|
|
// This is only to set the the user preference in Vuex for use later
|
|
|
|
this.setShowWhitespace({
|
|
|
|
showWhitespace: this.showWhitespaceDefault,
|
|
|
|
updateDatabase: false,
|
2021-10-27 15:23:28 +05:30
|
|
|
trackClick: false,
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
}
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['setRenderTreeList', 'setShowWhitespace']),
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
render(createElement) {
|
2021-03-08 18:12:59 +05:30
|
|
|
const { mrPath } = getDerivedMergeRequestInformation({ endpoint: this.endpoint });
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
return createElement('diffs-app', {
|
|
|
|
props: {
|
|
|
|
endpoint: this.endpoint,
|
2020-01-01 13:55:28 +05:30
|
|
|
endpointMetadata: this.endpointMetadata,
|
|
|
|
endpointBatch: this.endpointBatch,
|
2023-05-27 22:25:52 +05:30
|
|
|
endpointDiffForPath: this.endpointDiffForPath,
|
2020-04-08 14:13:33 +05:30
|
|
|
endpointCoverage: this.endpointCoverage,
|
2021-04-29 21:17:54 +05:30
|
|
|
endpointCodequality: this.endpointCodequality,
|
|
|
|
endpointUpdateUser: this.endpointUpdateUser,
|
2018-11-08 19:23:39 +05:30
|
|
|
currentUser: this.currentUser,
|
|
|
|
projectPath: this.projectPath,
|
2019-02-15 15:39:39 +05:30
|
|
|
helpPagePath: this.helpPagePath,
|
2018-11-08 19:23:39 +05:30
|
|
|
shouldShow: this.activeTab === 'diffs',
|
2019-02-15 15:39:39 +05:30
|
|
|
changesEmptyStateIllustration: this.changesEmptyStateIllustration,
|
2019-07-07 11:18:12 +05:30
|
|
|
isFluidLayout: this.isFluidLayout,
|
2019-09-04 21:01:54 +05:30
|
|
|
dismissEndpoint: this.dismissEndpoint,
|
|
|
|
showSuggestPopover: this.showSuggestPopover,
|
2021-02-22 17:27:13 +05:30
|
|
|
fileByFileUserPreference: this.viewDiffsFileByFile,
|
2021-03-08 18:12:59 +05:30
|
|
|
defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage,
|
2021-04-17 20:07:23 +05:30
|
|
|
rehydratedMrReviews: getReviewsForMergeRequest(mrPath),
|
2021-10-27 15:23:28 +05:30
|
|
|
sourceProjectDefaultUrl: this.sourceProjectDefaultUrl,
|
|
|
|
sourceProjectFullPath: this.sourceProjectFullPath,
|
|
|
|
isForked: this.isForked,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
const fileFinderEl = document.getElementById('js-diff-file-finder');
|
|
|
|
|
|
|
|
if (fileFinderEl) {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: fileFinderEl,
|
|
|
|
store,
|
|
|
|
components: {
|
|
|
|
FindFile: () => import('~/vue_shared/components/file_finder/index.vue'),
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState('diffs', ['fileFinderVisible', 'isLoading']),
|
|
|
|
...mapGetters('diffs', ['flatBlobsList']),
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
fileFinderVisible(newVal, oldVal) {
|
|
|
|
if (newVal && !oldVal && !this.flatBlobsList.length) {
|
|
|
|
eventHub.$emit('fetchDiffData');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['toggleFileFinder', 'scrollToFile']),
|
|
|
|
openFile(file) {
|
|
|
|
window.mrTabs.tabShown('diffs');
|
2021-12-11 22:18:48 +05:30
|
|
|
this.scrollToFile({ path: file.path });
|
2021-11-11 11:23:49 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('find-file', {
|
|
|
|
props: {
|
|
|
|
files: this.flatBlobsList,
|
|
|
|
visible: this.fileFinderVisible,
|
|
|
|
loading: this.isLoading,
|
|
|
|
showDiffStats: true,
|
|
|
|
clearSearchOnClose: false,
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
toggle: this.toggleFileFinder,
|
|
|
|
click: this.openFile,
|
|
|
|
},
|
|
|
|
class: ['diff-file-finder'],
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm;
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|