1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-05-18 09:21:37 +07:00
verdaccio-ui/src/components/UpLinks/UpLinks.tsx
Juan Picado @jotadeveloper 97e8448098
fix: refactoring version page / fix issue not found page #100 (#117)
* chore: refactoring version page

* refactor: migrate version page to hooks

* refactor: Version page better imports

* fix: #100 render not found on click item

* test: add test for version page

* chore: update mocks

* test: add scenario for not found package

* chore: fix wrong mock path

* chore: update mock

* chore: add todo list
2019-08-25 14:34:27 +02:00

59 lines
1.6 KiB
TypeScript

import React, { ReactElement } from 'react';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import { DetailContextConsumer } from '../../pages/Version';
import NoItems from '../NoItems';
import { formatDateDistance } from '../../utils/package';
import { Heading, Spacer, ListItemText } from './styles';
class UpLinks extends React.PureComponent<{}> {
public render(): ReactElement<HTMLElement> {
return (
<DetailContextConsumer>
{context => {
return (
context &&
context.packageMeta &&
context.packageMeta &&
context.packageMeta._uplinks &&
context.packageMeta.latest &&
this.renderContent(context.packageMeta._uplinks, context.packageMeta.latest)
);
}}
</DetailContextConsumer>
);
}
public 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>
);
public renderContent(uplinks, { name }): ReactElement<HTMLElement> {
if (Object.keys(uplinks).length > 0) {
return (
uplinks && (
<>
<Heading variant="subheading">{'Uplinks'}</Heading>
{this.renderUpLinksList(uplinks)}
</>
)
);
}
return <NoItems text={`${name} has no uplinks.`} />;
}
}
export default UpLinks;