Skip to content

Commit

Permalink
fix: view tomogram open in new tab (#1251)
Browse files Browse the repository at this point in the history
Fixes issue with view tomogram button not opening external links in new
tab. This works by passing the `Link` component to reuse the auto
opening in new tab functionality for the `Button` component
  • Loading branch information
codemonkey800 authored Oct 18, 2024
1 parent 4d76ee0 commit 3312884
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/packages/data-portal/app/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ export type VariantLinkProps = LinkProps & {
}

function BaseLink(
{ to, variant, className, ...props }: VariantLinkProps,
{
href,
to,
variant,
className,
...props
}: VariantLinkProps & { href?: string },
ref: ForwardedRef<HTMLAnchorElement>,
) {
let newTabProps: Partial<LinkProps> = {}
const url = href ?? to

if (typeof to === 'string' && isExternalUrl(to)) {
if (typeof url === 'string' && isExternalUrl(url)) {
// For new tabs, add rel=noreferrer for security:
// https://web.dev/external-anchors-use-rel-noopener/#how-to-improve-your-site's-performance-and-prevent-security-vulnerabilities
newTabProps = {
Expand All @@ -30,7 +37,7 @@ function BaseLink(
return (
<RemixLink
ref={ref}
to={to}
to={url}
className={cnsNoMerge(
variant === 'dashed-bordered' && DASHED_BORDERED_CLASSES,
variant === 'dashed-underlined' && DASHED_UNDERLINED_CLASSES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EventPayloads, Events, usePlausible } from 'app/hooks/usePlausible'
import { useFeatureFlag } from 'app/utils/featureFlags'
import { getNeuroglancerUrl } from 'app/utils/url'

import { Link } from './Link'
import { Tooltip } from './Tooltip'

export interface ViewTomogramButtonProps {
Expand Down Expand Up @@ -70,6 +71,7 @@ export function ViewTomogramButton({
<Button
href={enabled ? getNeuroglancerUrl(neuroglancerConfig) : undefined}
disabled={!enabled}
LinkComponent={Link}
{...buttonProps}
>
<span>{t('viewTomogram')}</span>
Expand Down

0 comments on commit 3312884

Please sign in to comment.