Skip to content

Commit 684131e

Browse files
feat(web): add link to view reference tree on nextstrain org
1 parent f4bda75 commit 684131e

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

packages/nextclade-web/src/components/Main/ButtonLoadExample.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isEmpty } from 'lodash'
33
import React, { useCallback } from 'react'
44
import { Button } from 'reactstrap'
55
import { useRecoilValue } from 'recoil'
6+
import { LinkExternal } from 'src/components/Link/LinkExternal'
67
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
78
import { useRunSeqAutodetect } from 'src/hooks/useRunSeqAutodetect'
89
import { useRunAnalysis } from 'src/hooks/useRunAnalysis'
@@ -11,6 +12,7 @@ import { datasetCurrentAtom } from 'src/state/dataset.state'
1112
import { hasInputErrorsAtom } from 'src/state/error.state'
1213
import { useQuerySeqInputs } from 'src/state/inputs.state'
1314
import { shouldRunAutomaticallyAtom, shouldSuggestDatasetsOnDatasetPageAtom } from 'src/state/settings.state'
15+
import styled from 'styled-components'
1416

1517
export function useSetExampleSequences() {
1618
const { addQryInputs } = useQuerySeqInputs()
@@ -50,8 +52,16 @@ export function ButtonLoadExample({ ...rest }) {
5052
}
5153

5254
return (
53-
<Button {...rest} color="link" onClick={onClick} disabled={hasInputErrors || !datasetCurrent}>
55+
<ButtonStyled {...rest} color="link" onClick={onClick} disabled={hasInputErrors || !datasetCurrent}>
5456
{t('Load example')}
55-
</Button>
57+
</ButtonStyled>
5658
)
5759
}
60+
61+
const ButtonStyled = styled(Button)`
62+
margin: 0 0.5rem;
63+
max-width: 300px;
64+
overflow: hidden;
65+
white-space: nowrap;
66+
text-overflow: ellipsis;
67+
`

packages/nextclade-web/src/components/Main/DatasetCurrent.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react'
22
import { Col, Row, Container as ContainerBase } from 'reactstrap'
33
import { useRecoilValue } from 'recoil'
4+
import { ButtonLoadExample } from 'src/components/Main/ButtonLoadExample'
45
import { ButtonRun } from 'src/components/Main/ButtonRun'
6+
import { LinkOpenTree } from 'src/components/Main/LinkOpenTree'
57
import { useRunAnalysis } from 'src/hooks/useRunAnalysis'
68
import styled from 'styled-components'
79
import { useUpdatedDataset } from 'src/io/fetchDatasets'
@@ -87,6 +89,15 @@ export function DatasetCurrent() {
8789
<DatasetInfo dataset={dataset} />
8890
</Col>
8991
</Row>
92+
93+
<Row noGutters className="d-flex w-100">
94+
<Col className="d-flex">
95+
<div className="d-flex ml-auto">
96+
<LinkOpenTree className="my-auto" dataset={dataset} />
97+
<ButtonLoadExample />
98+
</div>
99+
</Col>
100+
</Row>
90101
</CurrentDatasetInfoBody>
91102
</Header>
92103

packages/nextclade-web/src/components/Main/DatasetCurrentSummary.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MdClear as IconClearBase } from 'react-icons/md'
55
import { ButtonTransparent } from 'src/components/Common/ButtonTransparent'
66
import { ButtonLoadExample } from 'src/components/Main/ButtonLoadExample'
77
import { DatasetCustomizationsIndicatorLink } from 'src/components/Main/DatasetCustomizationIndicator'
8+
import { LinkOpenTree } from 'src/components/Main/LinkOpenTree'
89
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
910
import styled from 'styled-components'
1011
import { useUpdatedDataset } from 'src/io/fetchDatasets'
@@ -51,9 +52,13 @@ export function DatasetCurrentSummary() {
5152
<DatasetCustomizationsIndicatorLink />
5253
</DatasetCustomizationWrapper>
5354
</Col>
54-
55-
<Col className="d-flex ml-auto mt-2">
56-
<ButtonLoadExample className="ml-auto" />
55+
</Row>
56+
<Row noGutters className="d-flex w-100">
57+
<Col className="d-flex">
58+
<div className="d-flex ml-auto">
59+
<LinkOpenTree className="my-auto" dataset={dataset} />
60+
<ButtonLoadExample />
61+
</div>
5762
</Col>
5863
</Row>
5964
</Col>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { Dataset } from 'src/types'
2+
import React, { HTMLProps, useMemo } from 'react'
3+
import { LinkExternal } from 'src/components/Link/LinkExternal'
4+
import { useTranslationSafe } from 'src/helpers/useTranslationSafe'
5+
import styled from 'styled-components'
6+
import urljoin from 'url-join'
7+
8+
export interface LinkOpenTreeProps extends HTMLProps<HTMLDivElement> {
9+
dataset: Dataset
10+
}
11+
12+
export function LinkOpenTree({ dataset }: LinkOpenTreeProps) {
13+
const { t } = useTranslationSafe()
14+
const nextstrainOrgTreeUrl = useMemo(() => {
15+
if (!dataset.files?.treeJson) {
16+
return undefined
17+
}
18+
const path = dataset.files.treeJson.replace(/^https?:\/\//, '')
19+
return urljoin('https://nextstrain.org/fetch', path)
20+
}, [dataset.files?.treeJson])
21+
return (
22+
<LinkContainer className="mx-2">
23+
<LinkExternalStyled
24+
disabled={!!nextstrainOrgTreeUrl}
25+
title={t('Open reference tree for this dataset on nextstrain.org')}
26+
href={nextstrainOrgTreeUrl}
27+
>
28+
{t('Open tree')}
29+
</LinkExternalStyled>
30+
</LinkContainer>
31+
)
32+
}
33+
34+
const LinkContainer = styled.div`
35+
margin: auto 0;
36+
max-width: 200px;
37+
overflow: hidden;
38+
text-overflow: ellipsis;
39+
`
40+
41+
const LinkExternalStyled = styled(LinkExternal)`
42+
white-space: nowrap;
43+
`

0 commit comments

Comments
 (0)