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

Svelte: implement new reference panel against new Usages API#63724

Merged
camdencheek merged 14 commits into
mainfrom
cc/usages-api
Jul 18, 2024
Merged

Svelte: implement new reference panel against new Usages API#63724
camdencheek merged 14 commits into
mainfrom
cc/usages-api

Conversation

@camdencheek

@camdencheek camdencheek commented Jul 9, 2024

Copy link
Copy Markdown
Member

This implements a first pass at the new references panel built against the new usages API.

Stacked on https://github.com/sourcegraph/sourcegraph/pull/63816

Notable omissions:

  • Precise code intel. Not implemented by the backend yet, will get automatic support once that rolls out. Will need to update the UI to surface the preciseness of results.
  • In-panel filtering. Just ran out of time since. It's surprisingly complex to define (and implement) the exact behavior here.
  • Pagination. It's actually theoretically implemented in the client (it uses infinityQuery), but the backend just returns everything, so we just render a massive list.
  • Collapsing file names. The logic to collapse file names is pretty performance heavy (requires the browser to do a full layout calculation), and since we have large lists from not paginating, it's very noticeable. I spent a fair amount of time trying to find alternatives, and still haven't found anything better than what we have now. Am open to being nerd sniped.
  • Full browser history support. The reference panel inputs are snapshotted on navigation, but opening the reference panel or adding a filter does not constitute a "navigation". I did not find an obvious way of making pushState and Snapshot work together nicely, but would love to pair on this.

Notable decisions:

  • No preview panel. It added complexity, was way to small with the additional filter panel on the left, and didn't actually feel good when you already have a perfectly good file view above.
  • The currently-open tab no longer lives in the URL, however it is still stored in the history entry. I want the state of the explore panel to persist across navigations, and I want state other than just the open tab to live with the history entry. IMO, it's not really useful to navigate to directly to "file with an open history/preview" panel, so I don't think we lose much with this. Certainly willing to be convinced otherwise though.

Test plan

  • Added a couple of storybook states. Are currently not very useful though because global styles do not seem to be applying to storybook.
  • Skipping playwright tests for now since they would need to rely on an unhealthy amount of mocking.
  • Manual testing of basic functionality

@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2024
@camdencheek camdencheek force-pushed the cc/usages-api branch 9 times, most recently from c5c3f13 to 140667a Compare July 15, 2024 17:34
@camdencheek camdencheek changed the base branch from main to cc/optimize-observe-intersection July 15, 2024 17:39
@camdencheek camdencheek changed the title Cc/usages api Svelte: implement new reference panel against new Usages API Jul 15, 2024
Comment thread client/web-sveltekit/src/lib/TreeNode.svelte
Comment on lines -133 to +146
box-shadow: var(--focus-box-shadow);
box-shadow: var(--focus-shadow-inner);

@camdencheek camdencheek Jul 15, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unrelated: use an inner box shadow so that stack order of siblings doesn't interfere and so we show it on all four sides (the left and right get cut off)

Comment thread client/web-sveltekit/src/lib/codenav/ExplorePanel.stories.svelte
Comment on lines -80 to -81
// Wait until DOM was updated to possibly show the history panel
await tick()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@fkling do you have more context on this? It seemed to be causing some very weird bugs when I tried to add explore panel stuff to the snapshot.

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.

The historyPanel component is only rendered when it's selected. When we restore selectedTab we have to wait for the DOM to update before historyPanel is available and before we can restore its data.
Which problems did you encounter?

@camdencheek camdencheek marked this pull request as ready for review July 16, 2024 00:20
@camdencheek camdencheek force-pushed the cc/optimize-observe-intersection branch from c65e8b2 to 5ac65b3 Compare July 17, 2024 00:08
Base automatically changed from cc/optimize-observe-intersection to main July 17, 2024 02:13
@camdencheek camdencheek force-pushed the cc/usages-api branch 2 times, most recently from 23d02d4 to 64de261 Compare July 17, 2024 02:45
@vovakulikov

vovakulikov commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

Did try this locally, works cool, found a few small layout problems (mostly about content overflow, nothing that big)

  • File breadcrumbs cause horizontal scroll in the panel content container
Screenshot 2024-07-17 at 17 39 19
  • Long repo and file name cut off if the left panel is too narrow
Screenshot 2024-07-17 at 17 39 25
  • Not a problem but a suggestion, maybe it's time to increase the max height for the ref/history panel up to 75%

cc @camdencheek

@camdencheek

Copy link
Copy Markdown
Member Author

Thanks @vovakulikov!

Made long paths wrap rather than creating a scroll container:
screenshot-2024-07-17_15-16-24@2x

Added word-break: break-all to the file list in the tree to ensure that we can always wrap even given a small column size:
screenshot-2024-07-17_15-14-09@2x

Increased the max panel height to 70%:
screenshot-2024-07-17_15-15-07@2x

@camdencheek camdencheek requested a review from a team July 18, 2024 00:02

@fkling fkling 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.

I feel like we should still update the URL to include a reference to the line/range of the symbol you just clicked. That will also highlight that line in the blob view.
After clicking 'find references', or rather after navigating back to a page with the reference panel open, it's not obvious where I opened the reference panel from (if that makes sense).

2024-07-18_13-32

Compare that with the current reference panel implementation:

2024-07-18_13-34

That aside, I love that we got rid of the preview 😃

Comment thread client/web-sveltekit/src/auto-imports.d.ts Outdated
Comment thread client/web-sveltekit/src/auto-imports.d.ts Outdated
Comment thread client/web-sveltekit/src/auto-imports.d.ts
Comment thread client/web-sveltekit/src/lib/TreeNode.svelte
Comment thread client/web-sveltekit/src/lib/codenav/ExplorePanel.svelte
export let repo: string
export let path: string
export let usages: ExplorePanel_Usage[]
export let scrollContainer: HTMLElement | undefined

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.

Makes me wonder whether we should pass the scrollContainer as context. Then we wouldn't have to pass props around. Not sure if it's possible to have optional contexts though.

But in general I find the idea reasonable: We have one "Scroller" component that's supposed to be used whenever you want to react to visibility or scroll events and that component provides the context for other components.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I like the idea of tying this in to context with a Scroller. Will save that for a followup though.

Comment thread client/web-sveltekit/src/routes/+layout.svelte
Comment on lines -80 to -81
// Wait until DOM was updated to possibly show the history panel
await tick()

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.

The historyPanel component is only rendered when it's selected. When we restore selectedTab we have to wait for the DOM to update before historyPanel is available and before we can restore its data.
Which problems did you encounter?

@fkling

fkling commented Jul 18, 2024

Copy link
Copy Markdown
Contributor

The last commit message is not truncated anymore, it's overflowing:
2024-07-18_13-39

@camdencheek

Copy link
Copy Markdown
Member Author

After clicking 'find references', or rather after navigating back to a page with the reference panel open, it's not obvious where I opened the reference panel from (if that makes sense).

Yep, that makes perfect sense, and if I'm understanding you right, that's exactly what this issue is all about.

@camdencheek camdencheek merged commit f7511c4 into main Jul 18, 2024
@camdencheek camdencheek deleted the cc/usages-api branch July 18, 2024 19:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants