Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/assets/javascripts/diffs/store
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/assets/javascripts/diffs/store')
-rw-r--r--app/assets/javascripts/diffs/store/actions.js68
-rw-r--r--app/assets/javascripts/diffs/store/modules/diff_state.js11
-rw-r--r--app/assets/javascripts/diffs/store/utils.js9
3 files changed, 77 insertions, 11 deletions
diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js
index a8d348e1836..d469ed8ee82 100644
--- a/app/assets/javascripts/diffs/store/actions.js
+++ b/app/assets/javascripts/diffs/store/actions.js
@@ -25,7 +25,6 @@ import {
DIFF_VIEW_COOKIE_NAME,
MR_TREE_SHOW_KEY,
TREE_LIST_STORAGE_KEY,
- WHITESPACE_STORAGE_KEY,
TREE_LIST_WIDTH_STORAGE_KEY,
OLD_LINE_KEY,
NEW_LINE_KEY,
@@ -38,6 +37,9 @@ import {
INLINE_DIFF_LINES_KEY,
PARALLEL_DIFF_LINES_KEY,
DIFFS_PER_PAGE,
+ DIFF_WHITESPACE_COOKIE_NAME,
+ SHOW_WHITESPACE,
+ NO_SHOW_WHITESPACE,
} from '../constants';
import { diffViewerModes } from '~/ide/constants';
@@ -103,7 +105,9 @@ export const fetchDiffFiles = ({ state, commit }) => {
.catch(() => worker.terminate());
};
-export const fetchDiffFilesBatch = ({ commit, state }) => {
+export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
+ const id = window?.location?.hash;
+ const isNoteLink = id.indexOf('#note') === 0;
const urlParams = {
per_page: DIFFS_PER_PAGE,
w: state.showWhitespace ? '0' : '1',
@@ -123,16 +127,36 @@ export const fetchDiffFilesBatch = ({ commit, state }) => {
commit(types.SET_DIFF_DATA_BATCH, { diff_files });
commit(types.SET_BATCH_LOADING, false);
+ if (!isNoteLink && !state.currentDiffFileId) {
+ commit(types.UPDATE_CURRENT_DIFF_FILE_ID, diff_files[0].file_hash);
+ }
+
+ if (isNoteLink) {
+ dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop());
+ }
+
if (!pagination.next_page) {
commit(types.SET_RETRIEVING_BATCHES, false);
+
+ // We need to check that the currentDiffFileId points to a file that exists
+ if (
+ state.currentDiffFileId &&
+ !state.diffFiles.some(f => f.file_hash === state.currentDiffFileId) &&
+ !isNoteLink
+ ) {
+ commit(types.UPDATE_CURRENT_DIFF_FILE_ID, state.diffFiles[0].file_hash);
+ }
+
if (gon.features?.codeNavigation) {
// eslint-disable-next-line promise/catch-or-return,promise/no-nesting
import('~/code_navigation').then(m =>
m.default({
- blobs: state.diffFiles.map(f => ({
- path: f.new_path,
- codeNavigationPath: f.code_navigation_path,
- })),
+ blobs: state.diffFiles
+ .filter(f => f.code_navigation_path)
+ .map(f => ({
+ path: f.new_path,
+ codeNavigationPath: f.code_navigation_path,
+ })),
definitionPathPrefix: state.definitionPathPrefix,
}),
);
@@ -211,9 +235,11 @@ export const setHighlightedRow = ({ commit }, lineCode) => {
// This is adding line discussions to the actual lines in the diff tree
// once for parallel and once for inline mode
export const assignDiscussionsToDiff = (
- { commit, state, rootState },
+ { commit, state, rootState, dispatch },
discussions = rootState.notes.discussions,
) => {
+ const id = window?.location?.hash;
+ const isNoteLink = id.indexOf('#note') === 0;
const diffPositionByLineCode = getDiffPositionByLineCode(
state.diffFiles,
state.useSingleDiffStyle,
@@ -230,6 +256,10 @@ export const assignDiscussionsToDiff = (
});
});
+ if (isNoteLink) {
+ dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop());
+ }
+
Vue.nextTick(() => {
eventHub.$emit('scrollToDiscussion');
});
@@ -448,6 +478,8 @@ export const toggleTreeOpen = ({ commit }, path) => {
};
export const scrollToFile = ({ state, commit }, path) => {
+ if (!state.treeEntries[path]) return;
+
const { fileHash } = state.treeEntries[path];
document.location.hash = fileHash;
@@ -484,11 +516,12 @@ export const setRenderTreeList = ({ commit }, renderTreeList) => {
export const setShowWhitespace = ({ commit }, { showWhitespace, pushState = false }) => {
commit(types.SET_SHOW_WHITESPACE, showWhitespace);
+ const w = showWhitespace ? SHOW_WHITESPACE : NO_SHOW_WHITESPACE;
- localStorage.setItem(WHITESPACE_STORAGE_KEY, showWhitespace);
+ Cookies.set(DIFF_WHITESPACE_COOKIE_NAME, w);
if (pushState) {
- historyPushState(mergeUrlParams({ w: showWhitespace ? '0' : '1' }, window.location.href));
+ historyPushState(mergeUrlParams({ w }, window.location.href));
}
eventHub.$emit('refetchDiffData');
@@ -710,5 +743,22 @@ export function moveToNeighboringCommit({ dispatch, state }, { direction }) {
}
}
+export const setCurrentDiffFileIdFromNote = ({ commit, rootGetters }, noteId) => {
+ const note = rootGetters.notesById[noteId];
+
+ if (!note) return;
+
+ const fileHash = rootGetters.getDiscussion(note.discussion_id).diff_file.file_hash;
+
+ commit(types.UPDATE_CURRENT_DIFF_FILE_ID, fileHash);
+};
+
+export const navigateToDiffFileIndex = ({ commit, state }, index) => {
+ const fileHash = state.diffFiles[index].file_hash;
+ document.location.hash = fileHash;
+
+ commit(types.UPDATE_CURRENT_DIFF_FILE_ID, fileHash);
+};
+
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
diff --git a/app/assets/javascripts/diffs/store/modules/diff_state.js b/app/assets/javascripts/diffs/store/modules/diff_state.js
index 87938ababed..1f165dd4971 100644
--- a/app/assets/javascripts/diffs/store/modules/diff_state.js
+++ b/app/assets/javascripts/diffs/store/modules/diff_state.js
@@ -1,10 +1,17 @@
import Cookies from 'js-cookie';
import { getParameterValues } from '~/lib/utils/url_utility';
-import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants';
+import {
+ INLINE_DIFF_VIEW_TYPE,
+ DIFF_VIEW_COOKIE_NAME,
+ DIFF_WHITESPACE_COOKIE_NAME,
+} from '../../constants';
+import { getDefaultWhitespace } from '../utils';
const viewTypeFromQueryString = getParameterValues('view')[0];
const viewTypeFromCookie = Cookies.get(DIFF_VIEW_COOKIE_NAME);
const defaultViewType = INLINE_DIFF_VIEW_TYPE;
+const whiteSpaceFromQueryString = getParameterValues('w')[0];
+const whiteSpaceFromCookie = Cookies.get(DIFF_WHITESPACE_COOKIE_NAME);
export default () => ({
isLoading: true,
@@ -29,7 +36,7 @@ export default () => ({
commentForms: [],
highlightedRow: null,
renderTreeList: true,
- showWhitespace: true,
+ showWhitespace: getDefaultWhitespace(whiteSpaceFromQueryString, whiteSpaceFromCookie),
fileFinderVisible: false,
dismissEndpoint: '',
showSuggestPopover: true,
diff --git a/app/assets/javascripts/diffs/store/utils.js b/app/assets/javascripts/diffs/store/utils.js
index d261be1b550..bc85dd0a1d4 100644
--- a/app/assets/javascripts/diffs/store/utils.js
+++ b/app/assets/javascripts/diffs/store/utils.js
@@ -15,6 +15,8 @@ import {
TREE_TYPE,
INLINE_DIFF_VIEW_TYPE,
PARALLEL_DIFF_VIEW_TYPE,
+ SHOW_WHITESPACE,
+ NO_SHOW_WHITESPACE,
} from '../constants';
export function findDiffFile(files, match, matchKey = 'file_hash') {
@@ -701,3 +703,10 @@ export const allDiscussionWrappersExpanded = diff => {
return discussionsExpanded;
};
+
+export const getDefaultWhitespace = (queryString, cookie) => {
+ // Querystring should override stored cookie value
+ if (queryString) return queryString === SHOW_WHITESPACE;
+ if (cookie === NO_SHOW_WHITESPACE) return false;
+ return true;
+};