{"size": 1397, "ext": "js", "max_stars_repo_path": "src/webui/components/UpLinks/index.js", "max_stars_repo_name": "abc3660170/pelipper-ui", "max_stars_repo_stars_event_min_datetime": "2019-05-03T14:35:44.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-16T00:18:00.000Z", "max_issues_repo_path": "src/webui/components/UpLinks/index.js", "max_issues_repo_name": "abc3660170/pelipper-ui", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/webui/components/UpLinks/index.js", "max_forks_repo_name": "abc3660170/pelipper-ui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.9464285714, "max_line_length": 93, "alphanum_fraction": 0.5733715104}
/**
 * @prettier
 */
import React from 'react';
import List from '@material-ui/core/List/index';
import ListItem from '@material-ui/core/ListItem/index';

import { DetailContextConsumer } from '../../pages/version/index';
import NoItems from '../NoItems';
import { formatDateDistance } from '../../utils/package';

import { Heading, Spacer, ListItemText } from './styles';

class UpLinks extends React.PureComponent<any> {
  render() {
    return (
      // $FlowFixMe
      <DetailContextConsumer>
        {({ packageMeta }) => {
          return this.renderContent(packageMeta._uplinks, packageMeta.latest);
        }}
      </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>
  );

  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.`} />;
  }
}

export default UpLinks;
