1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-26 13:05:33 +07:00
verdaccio-ui/src/webui/components/UpLinks/index.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-02-03 17:23:33 +07:00
/**
* @prettier
*/
2019-03-28 05:39:06 +07:00
import React from 'react';
import List from '@material-ui/core/List/index';
import ListItem from '@material-ui/core/ListItem/index';
2019-02-03 17:23:33 +07:00
import { DetailContextConsumer } from '../../pages/version/index';
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-03-28 05:39:06 +07:00
2019-02-03 17:23:33 +07:00
import { Heading, Spacer, ListItemText } from './styles';
class UpLinks extends React.PureComponent<any> {
render() {
return (
// $FlowFixMe
<DetailContextConsumer>
{({ packageMeta }) => {
2019-03-28 05:39:06 +07:00
return this.renderContent(packageMeta._uplinks, packageMeta.latest);
2019-02-03 17:23:33 +07:00
}}
</DetailContextConsumer>
);
}
renderUpLinksList = uplinks => (
<List>
{Object.keys(uplinks)
.reverse()
.map(name => (
<ListItem key={name}>
<ListItemText>{name}</ListItemText>
<Spacer />
<ListItemText>{`${formatDateDistance(uplinks[name].fetched)} ago`}</ListItemText>
</ListItem>
))}
</List>
);
2019-03-28 05:39:06 +07:00
renderContent(uplinks, { name }) {
if (Object.keys(uplinks).length > 0) {
return (
uplinks && (
<>
<Heading variant={'subheading'}>{'Uplinks'}</Heading>
{this.renderUpLinksList(uplinks)}
</>
)
);
}
return <NoItems text={`${name} has no uplinks.`} />;
2019-02-03 17:23:33 +07:00
}
}
export default UpLinks;