Commit 184cd5cd authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/fixDiffTreeListClickNotWorking' into 'master'

Fixes diff tree list not working

See merge request gitlab-org/gitlab!67598
parents bdc84702 6a8bf70a
...@@ -172,7 +172,6 @@ export default { ...@@ -172,7 +172,6 @@ export default {
treeWidth, treeWidth,
diffFilesLength: 0, diffFilesLength: 0,
virtualScrollCurrentIndex: -1, virtualScrollCurrentIndex: -1,
disableVirtualScroller: false,
}; };
}, },
computed: { computed: {
...@@ -414,6 +413,7 @@ export default { ...@@ -414,6 +413,7 @@ export default {
'setShowTreeList', 'setShowTreeList',
'navigateToDiffFileIndex', 'navigateToDiffFileIndex',
'setFileByFile', 'setFileByFile',
'disableVirtualScroller',
]), ]),
subscribeToEvents() { subscribeToEvents() {
notesEventHub.$once('fetchDiffData', this.fetchData); notesEventHub.$once('fetchDiffData', this.fetchData);
...@@ -522,11 +522,11 @@ export default { ...@@ -522,11 +522,11 @@ export default {
// To make sure the user is using the find function we need to wait for blur // To make sure the user is using the find function we need to wait for blur
// and max 1000ms to be sure it the search box is filtered // and max 1000ms to be sure it the search box is filtered
if (delta >= 0 && delta < 1000) { if (delta >= 0 && delta < 1000) {
this.disableVirtualScroller = true; this.disableVirtualScroller();
if (window.gon?.features?.diffSearchingUsageData) { if (window.gon?.features?.diffSearchingUsageData) {
api.trackRedisHllUserEvent('i_code_review_user_searches_diff'); api.trackRedisHllUserEvent('i_code_review_user_searches_diff');
api.trackRedisCounterEvent('user_searches_diffs'); api.trackRedisCounterEvent('diff_searches');
} }
} }
} }
...@@ -651,7 +651,7 @@ export default { ...@@ -651,7 +651,7 @@ export default {
<div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div> <div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div>
<template v-else-if="renderDiffFiles"> <template v-else-if="renderDiffFiles">
<dynamic-scroller <dynamic-scroller
v-if="!disableVirtualScroller && isVirtualScrollingEnabled" v-if="isVirtualScrollingEnabled"
ref="virtualScroller" ref="virtualScroller"
:items="diffs" :items="diffs"
:min-item-size="70" :min-item-size="70"
......
...@@ -520,14 +520,14 @@ export const toggleActiveFileByHash = ({ commit }, hash) => { ...@@ -520,14 +520,14 @@ export const toggleActiveFileByHash = ({ commit }, hash) => {
commit(types.VIEW_DIFF_FILE, hash); commit(types.VIEW_DIFF_FILE, hash);
}; };
export const scrollToFile = ({ state, commit }, path) => { export const scrollToFile = ({ state, commit, getters }, path) => {
if (!state.treeEntries[path]) return; if (!state.treeEntries[path]) return;
const { fileHash } = state.treeEntries[path]; const { fileHash } = state.treeEntries[path];
commit(types.VIEW_DIFF_FILE, fileHash); commit(types.VIEW_DIFF_FILE, fileHash);
if (window.gon?.features?.diffsVirtualScrolling) { if (getters.isVirtualScrollingEnabled) {
eventHub.$emit('scrollToFileHash', fileHash); eventHub.$emit('scrollToFileHash', fileHash);
setTimeout(() => { setTimeout(() => {
...@@ -535,6 +535,10 @@ export const scrollToFile = ({ state, commit }, path) => { ...@@ -535,6 +535,10 @@ export const scrollToFile = ({ state, commit }, path) => {
}); });
} else { } else {
document.location.hash = fileHash; document.location.hash = fileHash;
setTimeout(() => {
handleLocationHash();
});
} }
}; };
...@@ -844,3 +848,5 @@ export function reviewFile({ commit, state }, { file, reviewed = true }) { ...@@ -844,3 +848,5 @@ export function reviewFile({ commit, state }, { file, reviewed = true }) {
setReviewsForMergeRequest(mrPath, reviews); setReviewsForMergeRequest(mrPath, reviews);
commit(types.SET_MR_FILE_REVIEWS, reviews); commit(types.SET_MR_FILE_REVIEWS, reviews);
} }
export const disableVirtualScroller = ({ commit }) => commit(types.DISABLE_VIRTUAL_SCROLLING);
...@@ -177,6 +177,10 @@ export function suggestionCommitMessage(state, _, rootState) { ...@@ -177,6 +177,10 @@ export function suggestionCommitMessage(state, _, rootState) {
export const isVirtualScrollingEnabled = (state) => { export const isVirtualScrollingEnabled = (state) => {
const vSrollerCookie = Cookies.get('diffs_virtual_scrolling'); const vSrollerCookie = Cookies.get('diffs_virtual_scrolling');
if (state.disableVirtualScroller) {
return false;
}
if (vSrollerCookie) { if (vSrollerCookie) {
return vSrollerCookie === 'true'; return vSrollerCookie === 'true';
} }
......
...@@ -43,4 +43,5 @@ export default () => ({ ...@@ -43,4 +43,5 @@ export default () => ({
defaultSuggestionCommitMessage: '', defaultSuggestionCommitMessage: '',
mrReviews: {}, mrReviews: {},
latestDiff: true, latestDiff: true,
disableVirtualScroller: false,
}); });
...@@ -47,3 +47,4 @@ export const SET_DIFF_FILE_VIEWER = 'SET_DIFF_FILE_VIEWER'; ...@@ -47,3 +47,4 @@ export const SET_DIFF_FILE_VIEWER = 'SET_DIFF_FILE_VIEWER';
export const SET_SHOW_SUGGEST_POPOVER = 'SET_SHOW_SUGGEST_POPOVER'; export const SET_SHOW_SUGGEST_POPOVER = 'SET_SHOW_SUGGEST_POPOVER';
export const TOGGLE_LINE_DISCUSSIONS = 'TOGGLE_LINE_DISCUSSIONS'; export const TOGGLE_LINE_DISCUSSIONS = 'TOGGLE_LINE_DISCUSSIONS';
export const DISABLE_VIRTUAL_SCROLLING = 'DISABLE_VIRTUAL_SCROLLING';
...@@ -362,4 +362,7 @@ export default { ...@@ -362,4 +362,7 @@ export default {
[types.SET_MR_FILE_REVIEWS](state, newReviews) { [types.SET_MR_FILE_REVIEWS](state, newReviews) {
state.mrReviews = newReviews; state.mrReviews = newReviews;
}, },
[types.DISABLE_VIRTUAL_SCROLLING](state) {
state.disableVirtualScroller = true;
},
}; };
...@@ -874,6 +874,7 @@ describe('DiffsStoreActions', () => { ...@@ -874,6 +874,7 @@ describe('DiffsStoreActions', () => {
describe('scrollToFile', () => { describe('scrollToFile', () => {
let commit; let commit;
const getters = { isVirtualScrollingEnabled: false };
beforeEach(() => { beforeEach(() => {
commit = jest.fn(); commit = jest.fn();
...@@ -888,7 +889,7 @@ describe('DiffsStoreActions', () => { ...@@ -888,7 +889,7 @@ describe('DiffsStoreActions', () => {
}, },
}; };
scrollToFile({ state, commit }, 'path'); scrollToFile({ state, commit, getters }, 'path');
expect(document.location.hash).toBe('#test'); expect(document.location.hash).toBe('#test');
}); });
...@@ -902,7 +903,7 @@ describe('DiffsStoreActions', () => { ...@@ -902,7 +903,7 @@ describe('DiffsStoreActions', () => {
}, },
}; };
scrollToFile({ state, commit }, 'path'); scrollToFile({ state, commit, getters }, 'path');
expect(commit).toHaveBeenCalledWith(types.VIEW_DIFF_FILE, 'test'); expect(commit).toHaveBeenCalledWith(types.VIEW_DIFF_FILE, 'test');
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment