Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

New file tree#46602

Merged
philipp-spiess merged 22 commits into
mainfrom
ps/new-tree-sidebar
Jan 24, 2023
Merged

New file tree#46602
philipp-spiess merged 22 commits into
mainfrom
ps/new-tree-sidebar

Conversation

@philipp-spiess

@philipp-spiess philipp-spiess commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

Part of #12916

Screenshot 2023-01-17 at 18 46 45

Todo

  • Add a proper feature flag
  • Fix the weird jumping when big section are focused
  • Propose a fix for the scrolling upstream
  • Wait for upstream to fix maybe? ➡️ We can also use the monkeypatch (I won't enable the feature flag for others until this is fixed!) for now.

Todo for later

➡️ moved to #12916

Test plan

@cla-bot cla-bot Bot added the cla-signed label Jan 17, 2023
@github-actions github-actions Bot added the team/code-exploration Issues owned by the Code Exploration team label Jan 17, 2023
@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Jan 17, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (+0.08 kb) 0.16% (+22.73 kb) 🔺 0.20% (+22.65 kb) 🔺 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 90c163b and 83270f4 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@felixfbecker

felixfbecker commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

This is awesome! Could we introduce a Tree component to the Wildcard library that wraps the underlying open source library so that it can be easily reused in other places (like symbols sidebar, reference panel)?

@philipp-spiess

Copy link
Copy Markdown
Contributor Author

@felixfbecker

Could we introduce a Tree component to the Wildcard library that wraps the underlying open source library so that it can be easily reused in other places (like symbols sidebar, reference panel)?

I think this would be AWESOME and we should do that but I’m a bit hesitant to do this just yet because I don't fully understand the different needs of these views yet.

What about we add this as a one-off for now, iron out the edge cases, maybe start thinking about what symbols and the references panel would need, and then onboard it to Wildcard?

@philipp-spiess philipp-spiess self-assigned this Jan 18, 2023
@philipp-spiess philipp-spiess requested review from a team January 18, 2023 15:35
@philipp-spiess philipp-spiess marked this pull request as ready for review January 18, 2023 15:37
// on the folder name as well and thus the jumping is unexpected. To fix this,
// we have to patch `.focus()` and handle the case ourselves.
//
// TODO: This should be fixed upstream in react-accessible-treeview.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd suggest making a PR there, maybe it'll get merged quickly. Monkey-patching HTMLElement.prototype.focus() seems really hacky

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@felixfbecker Yeah I can look into it. We could also vendor the library, it's just two files. But I'll try to come up with a reasonable API (Maybe providing a custom focus helper? Maybe just a callback + a way to set the preventScroll option?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe I’m overthinking it, I'll just post the same fix that I did, since this is also a weird experience in the examples of this library if you start to constrain the size:

Screen.Recording.2023-01-18.at.19.11.58.mov

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

either upstream fix or vendoring sounds both reasonable to me :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@felixfbecker

Copy link
Copy Markdown
Contributor

@felixfbecker

Could we introduce a Tree component to the Wildcard library that wraps the underlying open source library so that it can be easily reused in other places (like symbols sidebar, reference panel)?

I think this would be AWESOME and we should do that but I’m a bit hesitant to do this just yet because I don't fully understand the different needs of these views yet.

What about we add this as a one-off for now, iron out the edge cases, maybe start thinking about what symbols and the references panel would need, and then onboard it to Wildcard?

If you can extend it to the additional use cases as a direct follow-up that makes sense. I think the explicit goal here should be to find something that is generically reusable for other areas, so you're right that we don't really know until we use it in at least two places, which only means we should do that rather sooner than later.

I could also see an argument for already reusing it in this PR for the symbols sidebar to figure out if we can make it work like that (because maybe the library is actually not well generalizable, who knows). But that's up to you, certainly good to ship improvements faster too.

@philipp-spiess

Copy link
Copy Markdown
Contributor Author

I could also see an argument for already reusing it in this PR for the symbols sidebar to figure out if we can make it work like that (because maybe the library is actually not well generalizable, who knows). But that's up to you, certainly good to ship improvements faster too.

Yeah that's what I want to figure out. I had to build a bit of book-keeping to make it work well for the files use case, and I think that's fine to be kept file-tree-specific. Maybe what's reusable is the the general layout and UI (so everything beside the icons and the text that is rendered)

@mrnugget mrnugget left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only looked at *.go and left some comments that should be addressed, after that, as long as you tested this, I'm good withit

Comment thread cmd/frontend/graphqlbackend/git_tree.go Outdated
Comment thread cmd/frontend/graphqlbackend/git_tree_entry.go Outdated
Comment thread cmd/frontend/graphqlbackend/schema.graphql Outdated
Comment thread cmd/frontend/graphqlbackend/git_tree_entry.go Outdated
Comment thread cmd/frontend/graphqlbackend/git_tree.go Outdated
// on the folder name as well and thus the jumping is unexpected. To fix this,
// we have to patch `.focus()` and handle the case ourselves.
//
// TODO: This should be fixed upstream in react-accessible-treeview.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

either upstream fix or vendoring sounds both reasonable to me :)

@eseliger

Copy link
Copy Markdown
Member

This looks great btw :)

@sourcegraph-bot

sourcegraph-bot commented Jan 23, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in OWNERS files for diff a528304...90c163b.

Notify File(s)
@sourcegraph/code-exploration-devs client/wildcard/src/components/Tree/Tree.module.scss
client/wildcard/src/components/Tree/Tree.story.module.scss
client/wildcard/src/components/Tree/Tree.story.tsx
client/wildcard/src/components/Tree/Tree.tsx
client/wildcard/src/components/Tree/index.ts
client/wildcard/src/components/Tree/react-accessible-treeview/LICENSE
client/wildcard/src/components/Tree/react-accessible-treeview/README.md
client/wildcard/src/components/Tree/react-accessible-treeview/index.tsx
client/wildcard/src/components/Tree/react-accessible-treeview/utils.ts
client/wildcard/src/components/index.ts
@vovakulikov client/wildcard/src/components/Tree/Tree.module.scss
client/wildcard/src/components/Tree/Tree.story.module.scss
client/wildcard/src/components/Tree/Tree.story.tsx
client/wildcard/src/components/Tree/Tree.tsx
client/wildcard/src/components/Tree/index.ts
client/wildcard/src/components/Tree/react-accessible-treeview/LICENSE
client/wildcard/src/components/Tree/react-accessible-treeview/README.md
client/wildcard/src/components/Tree/react-accessible-treeview/index.tsx
client/wildcard/src/components/Tree/react-accessible-treeview/utils.ts
client/wildcard/src/components/index.ts

@philipp-spiess

Copy link
Copy Markdown
Contributor Author

It's unclear when the upstream fix will be merged (dgreene1/react-accessible-treeview#81) and I don't want to be blocked by it, so I went ahead and vendored the library for now to avoid the controversial hack. Let me know if you can think of any issues with this approach (as a nice upside we can also remove the PropTypes usage, yay!). Included the LICENSE file as well.

@taras-yemets taras-yemets left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work, Philipp!

@valerybugakov valerybugakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome work! Excited to start using it on S2 as soon as it becomes available 🔥

Comment thread client/web/src/repo/RepoRevisionSidebarFileTree.tsx Outdated
Comment thread client/web/src/repo/RepoRevisionSidebarFileTree.tsx Outdated
Comment thread client/web/src/repo/RepoRevisionSidebarFileTree.tsx Outdated
}

return (
<Tree<TreeNode>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice typed stuff

Comment thread client/wildcard/src/components/Tree/Tree.tsx Outdated
@philipp-spiess philipp-spiess merged commit ab00308 into main Jan 24, 2023
@philipp-spiess philipp-spiess deleted the ps/new-tree-sidebar branch January 24, 2023 14:37
philipp-spiess added a commit that referenced this pull request Jan 31, 2023
Part of #46602

This adds single-child folder expansion to the new tree view based on
how VS Code does it 🎉

Since the implementation of the tree is append-only, only a bit of
bookkeeping is needed to detect single-child expansion scenarios and
change the tree entries accordingly. I've left various comments in the
code which should explain the implementation for the curious.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/code-exploration Issues owned by the Code Exploration team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants