diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/assets/javascripts/diffs/store/actions.js | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/assets/javascripts/diffs/store/actions.js')
-rw-r--r-- | app/assets/javascripts/diffs/store/actions.js | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index 2e94f147086..66510edf3db 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -25,7 +25,6 @@ import { MIN_RENDERING_MS, START_RENDERING_INDEX, INLINE_DIFF_LINES_KEY, - DIFFS_PER_PAGE, DIFF_FILE_MANUAL_COLLAPSE, DIFF_FILE_AUTOMATIC_COLLAPSE, EVT_PERF_MARK_FILE_TREE_START, @@ -92,22 +91,18 @@ export const setBaseConfig = ({ commit }, options) => { }; export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { - const diffsGradualLoad = window.gon?.features?.diffsGradualLoad; - let perPage = DIFFS_PER_PAGE; + let perPage = state.viewDiffsFileByFile ? 1 : 5; let increaseAmount = 1.4; - - if (diffsGradualLoad) { - perPage = state.viewDiffsFileByFile ? 1 : 5; - } - - const startPage = diffsGradualLoad ? 0 : 1; + const startPage = 0; const id = window?.location?.hash; const isNoteLink = id.indexOf('#note') === 0; const urlParams = { w: state.showWhitespace ? '0' : '1', view: 'inline', }; + const hash = window.location.hash.replace('#', '').split('diff-content-').pop(); let totalLoaded = 0; + let scrolledVirtualScroller = false; commit(types.SET_BATCH_LOADING, true); commit(types.SET_RETRIEVING_BATCHES, true); @@ -122,6 +117,18 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { commit(types.SET_DIFF_DATA_BATCH, { diff_files }); commit(types.SET_BATCH_LOADING, false); + if (window.gon?.features?.diffsVirtualScrolling && !scrolledVirtualScroller) { + const index = state.diffFiles.findIndex( + (f) => + f.file_hash === hash || f[INLINE_DIFF_LINES_KEY].find((l) => l.line_code === hash), + ); + + if (index >= 0) { + eventHub.$emit('scrollToIndex', index); + scrolledVirtualScroller = true; + } + } + if (!isNoteLink && !state.currentDiffFileId) { commit(types.VIEW_DIFF_FILE, diff_files[0].file_hash); } @@ -130,11 +137,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop()); } - if ( - (diffsGradualLoad && - (totalLoaded === pagination.total_pages || pagination.total_pages === null)) || - (!diffsGradualLoad && !pagination.next_page) - ) { + if (totalLoaded === pagination.total_pages || pagination.total_pages === null) { commit(types.SET_RETRIEVING_BATCHES, false); // We need to check that the currentDiffFileId points to a file that exists @@ -164,15 +167,11 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { return null; } - if (diffsGradualLoad) { - const nextPage = page + perPage; - perPage = Math.min(Math.ceil(perPage * increaseAmount), 30); - increaseAmount = Math.min(increaseAmount + 0.2, 2); - - return nextPage; - } + const nextPage = page + perPage; + perPage = Math.min(Math.ceil(perPage * increaseAmount), 30); + increaseAmount = Math.min(increaseAmount + 0.2, 2); - return pagination.next_page; + return nextPage; }) .then((nextPage) => { dispatch('startRenderDiffsQueue'); @@ -186,7 +185,7 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { .catch(() => commit(types.SET_RETRIEVING_BATCHES, false)); return getBatch() - .then(handleLocationHash) + .then(() => !window.gon?.features?.diffsVirtualScrolling && handleLocationHash()) .catch(() => null); }; @@ -250,6 +249,8 @@ export const setHighlightedRow = ({ commit }, lineCode) => { const fileHash = lineCode.split('_')[0]; commit(types.SET_HIGHLIGHTED_ROW, lineCode); commit(types.VIEW_DIFF_FILE, fileHash); + + handleLocationHash(); }; // This is adding line discussions to the actual lines in the diff tree @@ -523,9 +524,18 @@ export const scrollToFile = ({ state, commit }, path) => { if (!state.treeEntries[path]) return; const { fileHash } = state.treeEntries[path]; - document.location.hash = fileHash; commit(types.VIEW_DIFF_FILE, fileHash); + + if (window.gon?.features?.diffsVirtualScrolling) { + eventHub.$emit('scrollToFileHash', fileHash); + + setTimeout(() => { + window.history.replaceState(null, null, `#${fileHash}`); + }); + } else { + document.location.hash = fileHash; + } }; export const setShowTreeList = ({ commit }, { showTreeList, saving = true }) => { @@ -570,7 +580,7 @@ export const setShowWhitespace = async ( { state, commit }, { url, showWhitespace, updateDatabase = true }, ) => { - if (updateDatabase) { + if (updateDatabase && Boolean(window.gon?.current_user_id)) { await axios.put(url || state.endpointUpdateUser, { show_whitespace_in_diffs: showWhitespace }); } |