2018-06-21 08:22:40 -04:00
|
|
|
import Vue from 'vue';
|
2019-01-16 10:17:10 -05:00
|
|
|
import { mapActions, mapState, mapGetters } from 'vuex';
|
2022-02-15 10:15:04 -05:00
|
|
|
import { getCookie, parseBoolean, removeCookie } from '~/lib/utils/common_utils';
|
2022-02-01 16:12:02 -05:00
|
|
|
|
2019-01-16 10:17:10 -05:00
|
|
|
import eventHub from '../notes/event_hub';
|
2018-06-21 08:22:40 -04:00
|
|
|
import diffsApp from './components/app.vue';
|
2020-12-17 19:10:04 -05:00
|
|
|
|
2020-07-08 11:09:24 -04:00
|
|
|
import { TREE_LIST_STORAGE_KEY, DIFF_WHITESPACE_COOKIE_NAME } from './constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { getReviewsForMergeRequest } from './utils/file_reviews';
|
|
|
|
import { getDerivedMergeRequestInformation } from './utils/merge_request';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
export default function initDiffsApp(store) {
|
2021-09-09 11:09:24 -04:00
|
|
|
const vm = new Vue({
|
2018-06-21 08:22:40 -04:00
|
|
|
el: '#js-diffs-app',
|
|
|
|
name: 'MergeRequestDiffs',
|
|
|
|
components: {
|
|
|
|
diffsApp,
|
|
|
|
},
|
|
|
|
store,
|
|
|
|
data() {
|
|
|
|
const { dataset } = document.querySelector(this.$options.el);
|
|
|
|
|
|
|
|
return {
|
|
|
|
endpoint: dataset.endpoint,
|
2019-11-26 04:08:36 -05:00
|
|
|
endpointMetadata: dataset.endpointMetadata || '',
|
|
|
|
endpointBatch: dataset.endpointBatch || '',
|
2020-03-17 14:09:44 -04:00
|
|
|
endpointCoverage: dataset.endpointCoverage || '',
|
2021-04-02 20:09:02 -04:00
|
|
|
endpointCodequality: dataset.endpointCodequality || '',
|
2021-04-05 17:09:19 -04:00
|
|
|
endpointUpdateUser: dataset.updateCurrentUserPath,
|
2018-06-26 14:49:22 -04:00
|
|
|
projectPath: dataset.projectPath,
|
2018-12-13 14:17:19 -05:00
|
|
|
helpPagePath: dataset.helpPagePath,
|
2018-11-09 14:48:41 -05:00
|
|
|
currentUser: JSON.parse(dataset.currentUserData) || {},
|
2018-12-13 05:57:45 -05:00
|
|
|
changesEmptyStateIllustration: dataset.changesEmptyStateIllustration,
|
2019-04-12 04:32:05 -04:00
|
|
|
isFluidLayout: parseBoolean(dataset.isFluidLayout),
|
2019-06-14 09:01:24 -04:00
|
|
|
dismissEndpoint: dataset.dismissEndpoint,
|
|
|
|
showSuggestPopover: parseBoolean(dataset.showSuggestPopover),
|
2019-09-16 05:06:25 -04:00
|
|
|
showWhitespaceDefault: parseBoolean(dataset.showWhitespaceDefault),
|
2020-07-15 02:09:35 -04:00
|
|
|
viewDiffsFileByFile: parseBoolean(dataset.fileByFileDefault),
|
2021-01-19 07:10:46 -05:00
|
|
|
defaultSuggestionCommitMessage: dataset.defaultSuggestionCommitMessage,
|
2021-08-10 08:11:00 -04:00
|
|
|
sourceProjectDefaultUrl: dataset.sourceProjectDefaultUrl,
|
|
|
|
sourceProjectFullPath: dataset.sourceProjectFullPath,
|
|
|
|
isForked: parseBoolean(dataset.isForked),
|
2018-06-21 08:22:40 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
2020-12-23 16:10:24 -05:00
|
|
|
activeTab: (state) => state.page.activeTab,
|
2018-06-21 08:22:40 -04:00
|
|
|
}),
|
|
|
|
},
|
2019-01-24 09:48:03 -05:00
|
|
|
created() {
|
|
|
|
const treeListStored = localStorage.getItem(TREE_LIST_STORAGE_KEY);
|
|
|
|
const renderTreeList = treeListStored !== null ? parseBoolean(treeListStored) : true;
|
|
|
|
|
2021-07-22 08:10:04 -04:00
|
|
|
this.setRenderTreeList({ renderTreeList, trackClick: false });
|
2020-07-08 11:09:24 -04:00
|
|
|
|
2021-06-16 08:10:18 -04:00
|
|
|
// 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-02-01 16:12:02 -05:00
|
|
|
if (getCookie(DIFF_WHITESPACE_COOKIE_NAME)) {
|
|
|
|
const hideWhitespace = getCookie(DIFF_WHITESPACE_COOKIE_NAME);
|
2021-06-16 08:10:18 -04:00
|
|
|
this.setShowWhitespace({
|
|
|
|
url: this.endpointUpdateUser,
|
|
|
|
showWhitespace: hideWhitespace !== '1',
|
2021-07-22 08:10:04 -04:00
|
|
|
trackClick: false,
|
2021-06-16 08:10:18 -04:00
|
|
|
});
|
2022-02-01 16:12:02 -05:00
|
|
|
removeCookie(DIFF_WHITESPACE_COOKIE_NAME);
|
2021-06-16 08:10:18 -04:00
|
|
|
} else {
|
|
|
|
// This is only to set the the user preference in Vuex for use later
|
|
|
|
this.setShowWhitespace({
|
|
|
|
showWhitespace: this.showWhitespaceDefault,
|
|
|
|
updateDatabase: false,
|
2021-07-22 08:10:04 -04:00
|
|
|
trackClick: false,
|
2021-06-16 08:10:18 -04:00
|
|
|
});
|
2019-09-16 05:06:25 -04:00
|
|
|
}
|
2019-01-24 09:48:03 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['setRenderTreeList', 'setShowWhitespace']),
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
render(createElement) {
|
2020-12-17 19:10:04 -05:00
|
|
|
const { mrPath } = getDerivedMergeRequestInformation({ endpoint: this.endpoint });
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
return createElement('diffs-app', {
|
|
|
|
props: {
|
|
|
|
endpoint: this.endpoint,
|
2019-11-26 04:08:36 -05:00
|
|
|
endpointMetadata: this.endpointMetadata,
|
|
|
|
endpointBatch: this.endpointBatch,
|
2020-03-17 14:09:44 -04:00
|
|
|
endpointCoverage: this.endpointCoverage,
|
2021-04-02 20:09:02 -04:00
|
|
|
endpointCodequality: this.endpointCodequality,
|
2021-04-05 17:09:19 -04:00
|
|
|
endpointUpdateUser: this.endpointUpdateUser,
|
2018-06-21 08:22:40 -04:00
|
|
|
currentUser: this.currentUser,
|
2018-06-26 14:49:22 -04:00
|
|
|
projectPath: this.projectPath,
|
2018-12-13 14:17:19 -05:00
|
|
|
helpPagePath: this.helpPagePath,
|
2018-06-21 08:22:40 -04:00
|
|
|
shouldShow: this.activeTab === 'diffs',
|
2018-12-13 05:57:45 -05:00
|
|
|
changesEmptyStateIllustration: this.changesEmptyStateIllustration,
|
2019-04-12 04:32:05 -04:00
|
|
|
isFluidLayout: this.isFluidLayout,
|
2019-06-14 09:01:24 -04:00
|
|
|
dismissEndpoint: this.dismissEndpoint,
|
|
|
|
showSuggestPopover: this.showSuggestPopover,
|
2020-12-02 16:09:44 -05:00
|
|
|
fileByFileUserPreference: this.viewDiffsFileByFile,
|
2021-01-19 07:10:46 -05:00
|
|
|
defaultSuggestionCommitMessage: this.defaultSuggestionCommitMessage,
|
2021-03-08 13:09:12 -05:00
|
|
|
rehydratedMrReviews: getReviewsForMergeRequest(mrPath),
|
2021-08-10 08:11:00 -04:00
|
|
|
sourceProjectDefaultUrl: this.sourceProjectDefaultUrl,
|
|
|
|
sourceProjectFullPath: this.sourceProjectFullPath,
|
|
|
|
isForked: this.isForked,
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2021-09-09 11:09:24 -04:00
|
|
|
|
|
|
|
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-10-25 05:12:21 -04:00
|
|
|
this.scrollToFile({ path: file.path });
|
2021-09-09 11:09:24 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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-06-21 08:22:40 -04:00
|
|
|
}
|