Skip to content

Conversation

calvin-codecov
Copy link
Contributor

@calvin-codecov calvin-codecov commented Aug 7, 2025

Closes https://linear.app/getsentry/issue/CCMRG-1219/snowflake-flatten-file-paths-in-the-file-viewer-component

This PR modifies how the "tree" viewer shows directories that have a single directory as its only child by flattening. This scenario occurs often in java/kotlin/go projects and while our "list" viewer shows full file paths, it is not the most efficient way to navigate to files.

SOLUTION: If a directory has a single child that is a directory, we tack on the child to the parent and link them together. This is similar to how GitHub shows their tree directories and gives users quick navigation with clarity. (This is slightly different from the proposed solution in the ticket).

Flatten example:

src/a/file1.py
src/a/b/c/d/file2.py

Clicking into directory src/a will show a link to file1.py and a flattened link to /b/c/d as b and c only have one child that is directory.

Note:
I originally implemented a solution that started flattening at a directory that was an only child and only had one child, directory or file, as its child but I decided that this was not as useful as its criteria was very narrow. For example, for the above input, even though /b only has one child, because it has a sibling in file1.py, the flattening would not start until inside of /b for /c/d/file2.py. If it were to start earlier inside /a, it could have been potentially confusing for the user seeing a link to a file and a link to file with flatten dirs in between.
Ex:

Viewing /src/a
- file.py
- /b/c/d/file2.py
Screen.Recording.2025-08-12.at.11.18.15.AM.mov

Copy link

linear bot commented Aug 7, 2025

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.19%. Comparing base (5ab0ecf) to head (ec31d7c).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #386   +/-   ##
=======================================
  Coverage   94.19%   94.19%           
=======================================
  Files        1256     1256           
  Lines       46544    46556   +12     
  Branches     1489     1489           
=======================================
+ Hits        43843    43855   +12     
  Misses       2396     2396           
  Partials      305      305           
Flag Coverage Δ
apiunit 96.10% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Comment on lines +33 to +34
[0, 10, 7, 3, 0, "70.00000", 0, 0, 0, 0, 0, 0, 0],
[[0, 10, 7, 3, 0, "70.00000", 0, 0, 0, 0, 0, 0, 0]],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this simply to differentiate from file_data1

@@ -26,7 +26,15 @@ class PathNode:

@property
def name(self) -> str:
return self.full_path.split("/")[-1]
if hasattr(self, "children"): # this is a Dir
max_levels = getattr(self, "max_directory_level", 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this ever not be 1?

@@ -70,6 +78,7 @@ class Dir(PathNode):

full_path: str
children: list[File | Dir]
max_directory_level: int = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the future, any chance we can add some comments to these fields while the context you have is still fresh?

Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks for walkthrough

@calvin-codecov calvin-codecov added this pull request to the merge queue Aug 13, 2025
@calvin-codecov calvin-codecov removed this pull request from the merge queue due to a manual request Aug 13, 2025
@calvin-codecov calvin-codecov changed the title feat(api): Flatten single directories with single children for tree v… feat(api): Flatten directories with single child directory for tree v… Aug 13, 2025
@calvin-codecov calvin-codecov added this pull request to the merge queue Aug 13, 2025
Merged via the queue into main with commit 1246a3c Aug 13, 2025
83 of 87 checks passed
@calvin-codecov calvin-codecov deleted the cy/flatten_tree_dirs branch August 13, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants