-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1544 from nextstrain/feat/tree-link
- Loading branch information
Showing
4 changed files
with
116 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
63 changes: 63 additions & 0 deletions
63
packages/nextclade-web/src/components/Main/LinkOpenTree.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import classNames from 'classnames' | ||
import type { Dataset } from 'src/types' | ||
import React, { HTMLProps, useMemo } from 'react' | ||
import { LinkExternal } from 'src/components/Link/LinkExternal' | ||
import { useTranslationSafe } from 'src/helpers/useTranslationSafe' | ||
import styled from 'styled-components' | ||
import urljoin from 'url-join' | ||
|
||
export interface LinkOpenTreeProps extends HTMLProps<HTMLDivElement> { | ||
dataset: Dataset | ||
} | ||
|
||
export function LinkOpenTree({ dataset }: LinkOpenTreeProps) { | ||
const { t } = useTranslationSafe() | ||
const nextstrainOrgTreeUrl = useMemo(() => { | ||
if (!dataset.files?.treeJson) { | ||
return undefined | ||
} | ||
const path = dataset.files.treeJson.replace(/^https?:\/\//, '') | ||
return urljoin('https://nextstrain.org/fetch', path) | ||
}, [dataset.files?.treeJson]) | ||
|
||
const title = useMemo( | ||
() => | ||
nextstrainOrgTreeUrl | ||
? t('Open reference tree for this dataset on nextstrain.org') | ||
: t('There is no reference tree in this dataset'), | ||
[nextstrainOrgTreeUrl, t], | ||
) | ||
|
||
return ( | ||
<LinkContainer className="mx-2"> | ||
<LinkExternalStyled | ||
className={classNames(!nextstrainOrgTreeUrl && 'disabled')} | ||
title={title} | ||
href={nextstrainOrgTreeUrl} | ||
> | ||
{t('Open tree')} | ||
</LinkExternalStyled> | ||
</LinkContainer> | ||
) | ||
} | ||
|
||
const LinkContainer = styled.div` | ||
margin: auto 0; | ||
max-width: 200px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
` | ||
|
||
const LinkExternalStyled = styled(LinkExternal)` | ||
white-space: nowrap; | ||
&.disabled { | ||
color: #7b838a !important; | ||
opacity: 0.65 !important; | ||
text-decoration: none; | ||
cursor: not-allowed !important; | ||
transition: none !important; | ||
} | ||
transition: none !important; | ||
` |