verdaccio-ui/src/components/UpLinks/UpLinks.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { useContext } from 'react';
2019-02-03 17:23:33 +07:00
import { DetailContext } from '../../pages/Version';
2019-03-28 05:39:06 +07:00
import NoItems from '../NoItems';
2019-02-03 17:23:33 +07:00
import { formatDateDistance } from '../../utils/package';
2019-10-13 03:26:56 +07:00
import List from '../../muiComponents/List';
import ListItem from '../../muiComponents/ListItem';
2019-03-28 05:39:06 +07:00
import { StyledText, Spacer, ListItemText } from './styles';
2019-02-03 17:23:33 +07:00
const UpLinks: React.FC = () => {
const { packageMeta } = useContext(DetailContext);
if (!packageMeta || !packageMeta._uplinks || !packageMeta.latest) {
return null;
2019-02-03 17:23:33 +07:00
}
const { _uplinks: uplinks, latest } = packageMeta;
2019-02-03 17:23:33 +07:00
if (Object.keys(uplinks).length === 0) {
return <NoItems text={`${latest.name} has no uplinks.`} />;
2019-02-03 17:23:33 +07:00
}
return (
<>
<StyledText variant="subtitle1">{'Uplinks'}</StyledText>
<List>
{Object.keys(uplinks)
.reverse()
.map(name => (
<ListItem key={name}>
<ListItemText>{name}</ListItemText>
<Spacer />
<ListItemText>{`${formatDateDistance(uplinks[name].fetched)} ago`}</ListItemText>
</ListItem>
))}
</List>
</>
);
};
2019-02-03 17:23:33 +07:00
export default UpLinks;