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 {
treeWidth,
diffFilesLength: 0,
virtualScrollCurrentIndex: -1,
disableVirtualScroller: false,
};
},
computed: {
......@@ -414,6 +413,7 @@ export default {
'setShowTreeList',
'navigateToDiffFileIndex',
'setFileByFile',
'disableVirtualScroller',
]),
subscribeToEvents() {
notesEventHub.$once('fetchDiffData', this.fetchData);
......@@ -522,11 +522,11 @@ export default {
// 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
if (delta >= 0 && delta < 1000) {
this.disableVirtualScroller = true;
this.disableVirtualScroller();
if (window.gon?.features?.diffSearchingUsageData) {
api.trackRedisHllUserEvent('i_code_review_user_searches_diff');
api.trackRedisCounterEvent('user_searches_diffs');
api.trackRedisCounterEvent('diff_searches');
}
}
}
......@@ -651,7 +651,7 @@ export default {
<div v-if="isBatchLoading" class="loading"><gl-loading-icon size="lg" /></div>
<template v-else-if="renderDiffFiles">
<dynamic-scroller
v-if="!disableVirtualScroller && isVirtualScrollingEnabled"
v-if="isVirtualScrollingEnabled"
ref="virtualScroller"
:items="diffs"
:min-item-size="70"
......
......@@ -520,14 +520,14 @@ export const toggleActiveFileByHash = ({ commit }, 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;
const { fileHash } = state.treeEntries[path];
commit(types.VIEW_DIFF_FILE, fileHash);
if (window.gon?.features?.diffsVirtualScrolling) {
if (getters.isVirtualScrollingEnabled) {
eventHub.$emit('scrollToFileHash', fileHash);
setTimeout(() => {
......@@ -535,6 +535,10 @@ export const scrollToFile = ({ state, commit }, path) => {
});
} else {
document.location.hash = fileHash;
setTimeout(() => {
handleLocationHash();
});
}
};
......@@ -844,3 +848,5 @@ export function reviewFile({ commit, state }, { file, reviewed = true }) {
setReviewsForMergeRequest(mrPath, 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) {
export const isVirtualScrollingEnabled = (state) => {
const vSrollerCookie = Cookies.get('diffs_virtual_scrolling');
if (state.disableVirtualScroller) {
return false;
}
if (vSrollerCookie) {
return vSrollerCookie === 'true';
}
......
......@@ -43,4 +43,5 @@ export default () => ({
defaultSuggestionCommitMessage: '',
mrReviews: {},
latestDiff: true,
disableVirtualScroller: false,
});
......@@ -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 TOGGLE_LINE_DISCUSSIONS = 'TOGGLE_LINE_DISCUSSIONS';
export const DISABLE_VIRTUAL_SCROLLING = 'DISABLE_VIRTUAL_SCROLLING';
......@@ -362,4 +362,7 @@ export default {
[types.SET_MR_FILE_REVIEWS](state, newReviews) {
state.mrReviews = newReviews;
},
[types.DISABLE_VIRTUAL_SCROLLING](state) {
state.disableVirtualScroller = true;
},
};
......@@ -874,6 +874,7 @@ describe('DiffsStoreActions', () => {
describe('scrollToFile', () => {
let commit;
const getters = { isVirtualScrollingEnabled: false };
beforeEach(() => {
commit = jest.fn();
......@@ -888,7 +889,7 @@ describe('DiffsStoreActions', () => {
},
};
scrollToFile({ state, commit }, 'path');
scrollToFile({ state, commit, getters }, 'path');
expect(document.location.hash).toBe('#test');
});
......@@ -902,7 +903,7 @@ describe('DiffsStoreActions', () => {
},
};
scrollToFile({ state, commit }, 'path');
scrollToFile({ state, commit, getters }, 'path');
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