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

fix(svelte): Preserve selected lines in codehost URL#63334

Merged
fkling merged 1 commit into
mainfrom
fkling/srch-131-line-selection-is-lost-in-the-experimental-sveltekit-ui-when
Jun 26, 2024
Merged

fix(svelte): Preserve selected lines in codehost URL#63334
fkling merged 1 commit into
mainfrom
fkling/srch-131-line-selection-is-lost-in-the-experimental-sveltekit-ui-when

Conversation

@fkling

@fkling fkling commented Jun 19, 2024

Copy link
Copy Markdown
Contributor

Fixes srch-131

It was reported that the new web app doesn't preserve the selected lines when navigating to the corresponding file in the code host. This commit fixes that.

Additionally this commit adds file actions (most importantly the 'view in codehost' one) to the 'file at revision' view. I've excluded the 'open in editor' action from that view because I don't think it works with different commits (although that would also be a problem if someone was browsing the repo at a specific commit).

And while working on that I also fixed the 'view at commit' button in the history panel, which should not show 'close commit' when the inline diff view is open and the missing file icon in the inline diff view.

Test plan

Manual testing:

  • Selected lines are preserved
  • The currently selected revision (including inline override) is preserved
  • The raw URL respects the selected revision
  • File icon is no visible in inline diff view
  • 'view at commit' button works as expected when in inline diff view

Changelog

  • Line selection is preserved when navigating to GitHub or GitLab external URLs
  • File actions are now available in the inline 'at commit' view
  • File icon is now rendered in the file header for the inline diff view

It was reported that the new web app doesn't preserve the selected lines
when navigating to the corresponding file in the code host. This commit
fixes that.

Additionally this commit adds file actions (most importantly the 'view
in codehost' one) to the 'file at revision' view.

And while working on that I also fixed the 'view at commit' button in
the history panel, which should not show 'close commit' when the inline
diff view is open.
@fkling fkling requested a review from a team June 19, 2024 09:56
@fkling fkling self-assigned this Jun 19, 2024
@cla-bot cla-bot Bot added the cla-signed label Jun 19, 2024
Comment on lines +93 to +94
<Tooltip tooltip={selected && !diffEnabled ? 'Close commit' : 'View at commit'}>
<a href={selected && !diffEnabled ? closeURL : `?rev=${commit.oid}`}

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.

It should only say 'Close commit' when the we are in 'at commit' mode, not 'inline diff' mode.

Comment on lines +19 to +42
switch (externalLink.serviceKind) {
case ExternalServiceKind.GITHUB: {
// Add range or position path to the code host URL.
if (lineOrPosition?.line !== undefined) {
url += `#L${lineOrPosition.line}`

if (lineOrPosition.endLine) {
url += `-L${lineOrPosition.endLine}`
}
}
break
}
case ExternalServiceKind.GITLAB: {
// Add range or position path to the code host URL.
if (lineOrPosition?.line !== undefined) {
url += `#L${lineOrPosition.line}`

if (lineOrPosition.endLine) {
url += `-${lineOrPosition.endLine}`
}
}
break
}
}

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.

Comment on lines +22 to +26
<svelte:fragment slot="icon">
{#if $commit.value?.blob}
<FileIcon file={$commit.value.blob} inline />
{/if}
</svelte:fragment>

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.

It's not possible to 'assign' to a named slot inside a conditional, but apparently there is no error thrown when using a component with slot (only for elements). The Svelte team decided not add support for this in favor of Svelte 5's snippets (where this seems to be possible).

$: rawURL = (function () {
const url = `${repoURL}/-/raw/${filePath}`
return revisionOverride ? replaceRevisionInURL(url, revisionOverride.abbreviatedOID) : url
})()

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.

It's times like this that I really miss Rust's block expressions 🙂

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.

Yes 😞

@fkling fkling merged commit 617599b into main Jun 26, 2024
@fkling fkling deleted the fkling/srch-131-line-selection-is-lost-in-the-experimental-sveltekit-ui-when branch June 26, 2024 05:08
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