-
Notifications
You must be signed in to change notification settings - Fork 7
feat(api): Flatten directories with single child directory for tree v… #386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
[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]], |
There was a problem hiding this comment.
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
2342740
to
e2dcc06
Compare
@@ -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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this 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
e2dcc06
to
ec31d7c
Compare
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:
Clicking into directory
src/a
will show a link to file1.py and a flattened link to/b/c/d
asb
andc
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:
Screen.Recording.2025-08-12.at.11.18.15.AM.mov