Commit f654d44e authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/collapsedFileVirtualScrollerBug' into 'master'

Fixes expansion bug with diffs virtual scroller

See merge request gitlab-org/gitlab!65884
parents c79db67d a5e8268f
...@@ -20,7 +20,7 @@ import { ...@@ -20,7 +20,7 @@ import {
} from '../constants'; } from '../constants';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import { DIFF_FILE, GENERIC_ERROR } from '../i18n'; import { DIFF_FILE, GENERIC_ERROR } from '../i18n';
import { collapsedType, isCollapsed, getShortShaFromFile } from '../utils/diff_file'; import { collapsedType, getShortShaFromFile } from '../utils/diff_file';
import DiffContent from './diff_content.vue'; import DiffContent from './diff_content.vue';
import DiffFileHeader from './diff_file_header.vue'; import DiffFileHeader from './diff_file_header.vue';
...@@ -84,7 +84,7 @@ export default { ...@@ -84,7 +84,7 @@ export default {
return { return {
isLoadingCollapsedDiff: false, isLoadingCollapsedDiff: false,
forkMessageVisible: false, forkMessageVisible: false,
isCollapsed: isCollapsed(this.file), hasToggled: false,
}; };
}, },
i18n: { i18n: {
...@@ -102,9 +102,7 @@ export default { ...@@ -102,9 +102,7 @@ export default {
return getShortShaFromFile(this.file); return getShortShaFromFile(this.file);
}, },
showLoadingIcon() { showLoadingIcon() {
return ( return this.idState.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed);
this.idState.isLoadingCollapsedDiff || (!this.file.renderIt && !this.idState.isCollapsed)
);
}, },
hasDiff() { hasDiff() {
return hasDiff(this.file); return hasDiff(this.file);
...@@ -148,13 +146,13 @@ export default { ...@@ -148,13 +146,13 @@ export default {
return collapsedType(this.file) === DIFF_FILE_MANUAL_COLLAPSE; return collapsedType(this.file) === DIFF_FILE_MANUAL_COLLAPSE;
}, },
showBody() { showBody() {
return !this.idState.isCollapsed || this.automaticallyCollapsed; return !this.isCollapsed || this.automaticallyCollapsed;
}, },
showWarning() { showWarning() {
return this.idState.isCollapsed && this.automaticallyCollapsed && !this.viewDiffsFileByFile; return this.isCollapsed && this.automaticallyCollapsed && !this.viewDiffsFileByFile;
}, },
showContent() { showContent() {
return !this.idState.isCollapsed && !this.isFileTooLarge; return !this.isCollapsed && !this.isFileTooLarge;
}, },
showLocalFileReviews() { showLocalFileReviews() {
const loggedIn = Boolean(gon.current_user_id); const loggedIn = Boolean(gon.current_user_id);
...@@ -165,6 +163,13 @@ export default { ...@@ -165,6 +163,13 @@ export default {
codequalityDiffForFile() { codequalityDiffForFile() {
return this.codequalityDiff?.files?.[this.file.file_path] || []; return this.codequalityDiff?.files?.[this.file.file_path] || [];
}, },
isCollapsed() {
if (collapsedType(this.file) !== DIFF_FILE_MANUAL_COLLAPSE) {
return this.viewDiffsFileByFile ? false : this.file.viewer?.automaticallyCollapsed;
}
return this.file.viewer?.manuallyCollapsed;
},
}, },
watch: { watch: {
'file.id': { 'file.id': {
...@@ -176,23 +181,11 @@ export default { ...@@ -176,23 +181,11 @@ export default {
}, },
'file.file_hash': { 'file.file_hash': {
handler: function hashChangeWatch(newHash, oldHash) { handler: function hashChangeWatch(newHash, oldHash) {
this.isCollapsed = isCollapsed(this.file);
if (newHash && oldHash && !this.hasDiff && !this.preRender) { if (newHash && oldHash && !this.hasDiff && !this.preRender) {
this.requestDiff(); this.requestDiff();
} }
}, },
}, },
'file.viewer.automaticallyCollapsed': {
handler: function autoChangeWatch(automaticValue) {
this.handleAutomaticallyCollapsed(automaticValue);
},
},
'file.viewer.manuallyCollapsed': {
handler: function manualChangeWatch(manualValue) {
this.handleManualChangeWatch(manualValue);
},
},
}, },
created() { created() {
if (this.preRender) return; if (this.preRender) return;
...@@ -208,8 +201,6 @@ export default { ...@@ -208,8 +201,6 @@ export default {
} }
this.manageViewedEffects(); this.manageViewedEffects();
this.handleAutomaticallyCollapsed(this.file.viewer.automaticallyCollapsed);
this.handleManualChangeWatch(this.file.viewer.manuallyCollapsed);
}, },
beforeDestroy() { beforeDestroy() {
if (this.preRender) return; if (this.preRender) return;
...@@ -224,12 +215,18 @@ export default { ...@@ -224,12 +215,18 @@ export default {
'setFileCollapsedByUser', 'setFileCollapsedByUser',
]), ]),
manageViewedEffects() { manageViewedEffects() {
if (this.reviewed && !this.idState.isCollapsed && this.showLocalFileReviews) { if (
!this.idState.hasToggled &&
this.reviewed &&
!this.isCollapsed &&
this.showLocalFileReviews
) {
this.handleToggle(); this.handleToggle();
this.idState.hasToggled = true;
} }
}, },
expandAllListener() { expandAllListener() {
if (this.idState.isCollapsed) { if (this.isCollapsed) {
this.handleToggle(); this.handleToggle();
} }
}, },
...@@ -251,7 +248,7 @@ export default { ...@@ -251,7 +248,7 @@ export default {
}); });
}, },
handleToggle({ viaUserInteraction = false } = {}) { handleToggle({ viaUserInteraction = false } = {}) {
const collapsingNow = !this.idState.isCollapsed; const collapsingNow = !this.isCollapsed;
const contentElement = this.$el.querySelector(`#diff-content-${this.file.file_hash}`); const contentElement = this.$el.querySelector(`#diff-content-${this.file.file_hash}`);
this.setFileCollapsedByUser({ this.setFileCollapsedByUser({
...@@ -297,16 +294,6 @@ export default { ...@@ -297,16 +294,6 @@ export default {
hideForkMessage() { hideForkMessage() {
this.idState.forkMessageVisible = false; this.idState.forkMessageVisible = false;
}, },
handleAutomaticallyCollapsed(automaticValue) {
if (collapsedType(this.file) !== DIFF_FILE_MANUAL_COLLAPSE) {
this.idState.isCollapsed = this.viewDiffsFileByFile ? false : automaticValue;
}
},
handleManualChangeWatch(manualValue) {
if (manualValue !== null) {
this.idState.isCollapsed = manualValue;
}
},
}, },
}; };
</script> </script>
...@@ -328,7 +315,7 @@ export default { ...@@ -328,7 +315,7 @@ export default {
:diff-file="file" :diff-file="file"
:collapsible="true" :collapsible="true"
:reviewed="reviewed" :reviewed="reviewed"
:expanded="!idState.isCollapsed" :expanded="!isCollapsed"
:add-merge-request-buttons="true" :add-merge-request-buttons="true"
:view-diffs-file-by-file="viewDiffsFileByFile" :view-diffs-file-by-file="viewDiffsFileByFile"
:show-local-file-reviews="showLocalFileReviews" :show-local-file-reviews="showLocalFileReviews"
......
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