This repository was archived by the owner on Sep 30, 2024. It is now read-only.
feat(svelte): Add 'y' shortcut to navigate to permalink #63719
Merged
fkling merged 2 commits intoJul 10, 2024
Conversation
This implements the 'y' shortcut to navigate to the permalink page, just like we have in the React app. According to aria guidelines it should be possible to disable single character shortcuts but this actually never worked for the 'y' shortcut because it was implemented differently. So adding it without the option to turn it off is at least not a regression. For reference this the code handling the shortcut in the React app: https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph@d9dff1191a3bad812aa5b50315b8e77ee0e40e55/-/blob/client/web/src/repo/actions/CopyPermalinkAction.tsx?L64-77
248f6c6 to
695a73f
Compare
camdencheek
approved these changes
Jul 10, 2024
Comment on lines
-111
to
-116
| $: if (!!lastCommitQuery) { | ||
| // Reset last commit when the query observable changes. Without | ||
| // this we are showing the last commit of the previously selected | ||
| // file/folder until the last commit is loaded. | ||
| lastCommit = null | ||
| } |
Member
There was a problem hiding this comment.
Oh, that's a nice simplification.
|
|
||
| if (shouldResolveRepositoryInformation(data)) { | ||
| data = (await client.query(ResolveRepoRevision, { repoName, revision }, { requestPolicy: 'network-only' })).data | ||
| const cacheKey = `${repoName}@${revspec}` |
Member
There was a problem hiding this comment.
Since this is only in memory, this cache wouldn't be hit on a refresh, right?
Contributor
Author
There was a problem hiding this comment.
That's right, just like with all other GraphQL queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes srch-589
This implements the 'y' shortcut to navigate to the permalink page, just
like we have in the React app.
According to aria guidelines it should be possible to disable single
character shortcuts but this actually never worked for the 'y' shortcut
because it was implemented differently. So adding it without the option
to turn it off is at least not a regression.
For reference this the code handling the shortcut in the React app: https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph@d9dff1191a3bad812aa5b50315b8e77ee0e40e55/-/blob/client/web/src/repo/actions/CopyPermalinkAction.tsx?L64-77
When initially implementing this I noticed that there is a slight delay between pressing 'y' and the URL/UI updating. That's because SvelteKit has to wait for
ResolveRepoRevisioncall to resolve before updating the page. A new request is made because the URL changes which triggers the data loader. But we already know that such a request will return the same data, so the request is unnecessary. To avoid the second call I added another caching layer (see code and video).sg-sk-resolved-revision.mp4
I also noticed that the last commit info would be reloaded which is unnecessary. I changed the implementation to use the resolved revision instead of the revision from the URL. Now the request will be properly cached on the commit ID and the implementation is also much simpler.
Test plan
Manual testing.