forked from GenSpectrum/cov-spectrum-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariantHosts.tsx
59 lines (53 loc) · 1.6 KB
/
VariantHosts.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { LoaderSmall } from './Loader';
import { HostCountSampleData } from '../data/sample/HostCountSampleDataset';
import { LapisSelector } from '../data/LapisSelector';
export interface Props {
selector: LapisSelector;
}
const LineageEntry = styled.li`
width: 250px;
`;
export const VariantHosts = ({ selector }: Props) => {
const [data, setData] = useState<
| {
host: string | null;
proportion: number;
}[]
| undefined
>(undefined);
useEffect(() => {
HostCountSampleData.fromApi(selector).then(hostCountDataset => {
const total = hostCountDataset.payload.reduce((prev, curr) => prev + curr.count, 0);
const proportions = hostCountDataset.payload.map(e => ({
host: e.host,
proportion: e.count / total,
}));
setData(proportions);
});
}, [selector]);
return (
<>
<div>Sequences of this variant were found in the following hosts:</div>
{!data ? (
<div className='h-20 w-full flex items-center'>
<LoaderSmall />
</div>
) : (
<ul className='list-disc flex flex-wrap max-h-24 overflow-y-auto '>
{data
.sort((a, b) => b.proportion - a.proportion)
.map(({ host, proportion }) => {
const label = host || 'Unknown';
return (
<LineageEntry key={label}>
{label} ({(proportion * 100).toFixed(2)}%)
</LineageEntry>
);
})}
</ul>
)}
</>
);
};