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

feat(svelte): Add compare page#63850

Merged
fkling merged 5 commits into
mainfrom
fkling-srch-736-add-support-for-compare-page
Jul 17, 2024
Merged

feat(svelte): Add compare page#63850
fkling merged 5 commits into
mainfrom
fkling-srch-736-add-support-for-compare-page

Conversation

@fkling

@fkling fkling commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

This commit adds the Svelte version of the compare page. Now that we have a revision picker this was easy to implement.

A couple of notes:

  • The URL parameter is a rest parameter ([...spec]) because revisions can contain slashes, and we don't encode those.
  • I changed the API of the revision selector so that it works on pages that don't have resolvedRevision available (also we never needed the repo property from that object), and to provide custom select handlers.
  • Moved the revision to lib since it's used on various different pages.
  • Unlike the React version this version
    • Provides forward/backward buttons to browse the commit list
    • Uses infinity scrolling to load the next diffs
    • Doesn't use a different style for the commit list. I experimented with adding a "compact" version of the commit but it didn't feel quite right. I'm sure we'll eventually redesign this.
  • The filePath parameter is supported (for backwards compatibility) but we don't use it anywhere atm.
sg-sk-compare-page.mp4

(note that the avatar size has changed since the video was recorded; it's larger now)

Test plan

Manual testing.

@fkling fkling self-assigned this Jul 16, 2024
@cla-bot cla-bot Bot added the cla-signed label Jul 16, 2024
@fkling fkling force-pushed the fkling-srch-736-add-support-for-compare-page branch 2 times, most recently from 9d41e38 to 08f670f Compare July 16, 2024 11:07

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.

This is a prop instead of an event because we want to provide a default handler. Also events become props in Svelte 5 anyway.

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.

Made this an inline element. It doesn't seem to affect any existing callsites.

Comment on lines 31 to 88

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.

Moved all those up one level to be available to the compare page.

Comment thread client/web-sveltekit/src/routes/[...repo=reporev]/-/branches/all/+page.svelte Outdated

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.

This seems like it could store a potentially very large amount of data in session storage

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.

diffQuery is an infinity store. The data that's captured depends on the restore strategy used. In this specific case it will be something like {count: x, variables: {first: x}}. What is stored is intentionally opaque to the page. https://github.com/sourcegraph/sourcegraph/blob/08f670f3556ff3895c31a691a6d51f31ba310e87/client/web-sveltekit/src/routes/%5B...repo%3Dreporev%5D/-/compare/%5B...spec%5D/%2Bpage.ts#L78-L83

@camdencheek camdencheek Jul 17, 2024

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.

Ooooh, gotcha. That's neat. I was thinking this was storing the full dataset. Didn't quite understand the restore strategy part

@fkling fkling Jul 17, 2024

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.

The tldr is that we either "paginate" until we loaded the same amount of data (but that can be slow because we have to this sequentially to get the cursor, if the data is not cached), or we simply fetch the first N items and replace any current state with it.
Which of those to use depends on the pagination API provided by the backend. E.g. for some we fetch the first N, N+X, N+2X, etc items, which transfers duplicate data but that also means the call for N+2X items is cached and we can just request that.
With cursor based we usually do first N, first N after C1, first N after C2, etc. If we did first 3N then that request wouldn't be cached and we would fetch the data unnecessarily. In that case simply "repeating" the original queries is faster. If those are not cached though we want to only do the first 3N request...
All of that might change when/if we change our GraphQL caching strategy, but then it should be easy to use a different restore strategy too.

Comment thread client/web-sveltekit/src/routes/[...repo=reporev]/-/compare/[...spec]/+page.ts Outdated
Comment thread client/web-sveltekit/vite.config.ts Outdated

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.

fkling added 2 commits July 17, 2024 22:05
This commit adds the Svelte version of the compare page. Now that we
have a revision picker this was easy to implement.

A couple of notes:
- The URL parameter is a rest parameter ([...spec]) because revisions
  can contain slashes, and we don't encode those.
- I changed the API of the revision selector so that it works on pages
  that don't have `resolvedRevision` available (also we never needed the
  `repo` property from that object), and to provide custom select
  handlers.
- Moved the revision to lib since it's used on various different pages.
- Unlike the React version this version
  - Provides forward/backward buttons to browse the commit list
  - Uses infinity scrolling to load the next diffs
- The `filePath` parameter is supported (for backwards compatibility)
  but we don't use it anywhere atm.
@fkling fkling force-pushed the fkling-srch-736-add-support-for-compare-page branch from 08f670f to a5751e9 Compare July 17, 2024 20:24
@fkling fkling merged commit 8661226 into main Jul 17, 2024
@fkling fkling deleted the fkling-srch-736-add-support-for-compare-page branch July 17, 2024 21:02
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.

2 participants