Automatically expand collapsed file if clicked from the tree view
### Problem to solve
When using the file tree view in the "Changes" tab of the MR page, clicking on a file that is collapsed does not expand it automatically. That makes it easy to miss that file.
### Proposal
Expand collapsed files if clicked from the tree view.
### Implementation guide
Add functionality to `scrollToFile` (used when "Show one file at a time is disabled") and `goToFile` (used when "Show one file at a time is enabled").
The following patch should be the right start and might even be everything that's required:
```diff
diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js
index f0a2ca967cfd..8d50410dc9e9 100644
--- a/app/assets/javascripts/diffs/store/actions.js
+++ b/app/assets/javascripts/diffs/store/actions.js
@@ -685,6 +685,22 @@ export const goToFile = ({ state, commit, dispatch, getters }, { path }) => {
commit(types.SET_CURRENT_DIFF_FILE, fileHash);
+ // Expand the file content
+ const file = state.diffFiles.find((f) => f.file_hash === fileHash);
+ if (file) {
+ // Set both manual and automatic collapse to false to ensure the file expands
+ commit(types.SET_FILE_COLLAPSED, {
+ filePath: file.file_path,
+ collapsed: false,
+ trigger: DIFF_FILE_MANUAL_COLLAPSE
+ });
+
+ // If the file is automatically collapsed, load its content
+ if (file.viewer?.automaticallyCollapsed) {
+ notesEventHub.$emit(`loadCollapsedDiff/${fileHash}`);
+ }
+ }
+
const newUrl = new URL(window.location);
newUrl.hash = fileHash;
historyPushState(newUrl, { skipScrolling: true });
@@ -703,6 +719,11 @@ export const scrollToFile = ({ state, commit, getters }, { path }) => {
commit(types.SET_CURRENT_DIFF_FILE, fileHash);
+ const file = state.diffFiles.find((f) => f.file_hash === fileHash);
+ if (file) {
+ commit(types.SET_FILE_COLLAPSED, { filePath: file.file_path, collapsed: false });
+ }
+
if (getters.isVirtualScrollingEnabled) {
eventHub.$emit('scrollToFileHash', fileHash);
```
issue