2019-02-03 17:23:33 +07:00
|
|
|
/* eslint react/jsx-max-depth: 0 */
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import React, { Component, Fragment, ReactElement } from 'react';
|
2019-03-28 05:39:06 +07:00
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import { DetailContextConsumer } from '../../pages/version/Version';
|
2019-02-03 17:23:33 +07:00
|
|
|
import CopyToClipBoard from '../CopyToClipBoard';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
import { Heading, GithubLink, RepositoryListItem } from './styles';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-03-28 05:39:06 +07:00
|
|
|
import git from './img/git.png';
|
2019-05-16 21:25:40 +07:00
|
|
|
import { isURL } from '../../utils/url';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-22 16:43:59 +07:00
|
|
|
class Repository extends Component {
|
2019-06-20 19:37:28 +07:00
|
|
|
public render(): ReactElement<HTMLElement> {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-20 19:37:28 +07:00
|
|
|
{context => {
|
|
|
|
return context && context.packageMeta && this.renderRepository(context.packageMeta);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
2019-06-20 19:37:28 +07:00
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
private renderRepositoryText(url: string): ReactElement<HTMLElement> {
|
|
|
|
return (
|
|
|
|
<GithubLink href={url} target="_blank">
|
|
|
|
{url}
|
|
|
|
</GithubLink>
|
|
|
|
);
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
private renderRepository = packageMeta => {
|
2019-06-22 16:43:59 +07:00
|
|
|
const { repository: { url = null } = {} } = packageMeta.latest;
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-05-16 21:25:40 +07:00
|
|
|
if (!url || isURL(url) === false) {
|
2019-02-03 17:23:33 +07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-06-20 19:37:28 +07:00
|
|
|
<Fragment>
|
|
|
|
<List dense={true} subheader={<Heading variant="subheading">{'Repository'}</Heading>}>
|
2019-03-28 05:39:06 +07:00
|
|
|
<RepositoryListItem>
|
|
|
|
<Avatar src={git} />
|
|
|
|
<ListItemText primary={this.renderContent(url)} />
|
|
|
|
</RepositoryListItem>
|
|
|
|
</List>
|
2019-06-20 19:37:28 +07:00
|
|
|
</Fragment>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
2019-06-20 19:37:28 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
private renderContent(url: string): ReactElement<HTMLElement> {
|
|
|
|
return <CopyToClipBoard text={url}>{this.renderRepositoryText(url)}</CopyToClipBoard>;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Repository;
|