verdaccio-ui/src/components/UpLinks/UpLinks.tsx
Priscila Oliveira 82d7107de7 fix: listItem Component - Introduced ForwardRef (#183)
* refactor: introduced forwardRef

* fix: fixed button prop listItem

* chore: rollback package upgrade

* fix: fixed snap
2019-10-12 21:11:23 +02:00

43 lines
1.1 KiB
TypeScript

import React, { useContext } from 'react';
import List from '@material-ui/core/List';
import { DetailContext } from '../../pages/Version';
import NoItems from '../NoItems';
import { formatDateDistance } from '../../utils/package';
import ListItem from '../../muiComponents/ListItem';
import { Heading, Spacer, ListItemText } from './styles';
const UpLinks: React.FC = () => {
const { packageMeta } = useContext(DetailContext);
if (!packageMeta || !packageMeta._uplinks || !packageMeta.latest) {
return null;
}
const { _uplinks: uplinks, latest } = packageMeta;
if (Object.keys(uplinks).length === 0) {
return <NoItems text={`${latest.name} has no uplinks.`} />;
}
return (
<>
<Heading variant="subtitle1">{'Uplinks'}</Heading>
<List>
{Object.keys(uplinks)
.reverse()
.map(name => (
<ListItem key={name}>
<ListItemText>{name}</ListItemText>
<Spacer />
<ListItemText>{`${formatDateDistance(uplinks[name].fetched)} ago`}</ListItemText>
</ListItem>
))}
</List>
</>
);
};
export default UpLinks;