Skip to content
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 into
mainfrom
fkling-srch-589-add-support-for-y-or-similar-keyboard-shortcut
Jul 10, 2024
Merged

feat(svelte): Add 'y' shortcut to navigate to permalink #63719
fkling merged 2 commits into
mainfrom
fkling-srch-589-add-support-for-y-or-similar-keyboard-shortcut

Conversation

@fkling

@fkling fkling commented Jul 9, 2024

Copy link
Copy Markdown
Contributor

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 ResolveRepoRevision call 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.

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
@fkling fkling requested review from camdencheek and vovakulikov July 9, 2024 14:36
@fkling fkling self-assigned this Jul 9, 2024
@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2024
@fkling fkling force-pushed the fkling-srch-589-add-support-for-y-or-similar-keyboard-shortcut branch from 248f6c6 to 695a73f Compare July 9, 2024 14:42
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
}

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.

Oh, that's a nice simplification.


if (shouldResolveRepositoryInformation(data)) {
data = (await client.query(ResolveRepoRevision, { repoName, revision }, { requestPolicy: 'network-only' })).data
const cacheKey = `${repoName}@${revspec}`

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.

Since this is only in memory, this cache wouldn't be hit on a refresh, right?

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.

That's right, just like with all other GraphQL queries

@fkling fkling merged commit 9072b3a into main Jul 10, 2024
@fkling fkling deleted the fkling-srch-589-add-support-for-y-or-similar-keyboard-shortcut branch July 10, 2024 19:47
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