2019-02-03 17:23:33 +07:00
|
|
|
/**
|
|
|
|
* @prettier
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { DetailContextConsumer } from '../../pages/version/index';
|
|
|
|
import { formatDateDistance } from '../../utils/package';
|
|
|
|
import { Heading, Spacer, ListItemText } from './styles';
|
|
|
|
import List from '@material-ui/core/List/index';
|
|
|
|
import ListItem from '@material-ui/core/ListItem/index';
|
|
|
|
import React from 'react';
|
|
|
|
import { DIST_TAGS } from '../../../lib/constants';
|
|
|
|
|
|
|
|
class Versions extends React.PureComponent<any> {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
// $FlowFixMe
|
|
|
|
<DetailContextConsumer>
|
|
|
|
{({ packageMeta }) => {
|
2019-03-28 05:39:06 +07:00
|
|
|
return this.renderContent(packageMeta);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-28 05:39:06 +07:00
|
|
|
renderPackageList = (packages: any, isVersion: boolean = false, timeMap: Object = {}) => {
|
|
|
|
return (
|
|
|
|
<List>
|
|
|
|
{Object.keys(packages)
|
|
|
|
.reverse()
|
|
|
|
.map(version => (
|
|
|
|
<ListItem className={'version-item'} key={version}>
|
|
|
|
<ListItemText>{version}</ListItemText>
|
|
|
|
<Spacer />
|
|
|
|
<ListItemText>{isVersion && timeMap[version] ? `${formatDateDistance(timeMap[version])} ago` : packages[version]}</ListItemText>
|
|
|
|
</ListItem>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
// $FlowFixMe
|
2019-03-28 05:39:06 +07:00
|
|
|
renderContent(packageMeta) {
|
|
|
|
const { versions = {}, time: timeMap = {}, [DIST_TAGS]: distTags = {} } = packageMeta;
|
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{distTags && (
|
|
|
|
<>
|
|
|
|
<Heading variant={'subheading'}>{'Current Tags'}</Heading>
|
2019-03-28 05:39:06 +07:00
|
|
|
{this.renderPackageList(distTags, false, timeMap)}
|
2019-02-03 17:23:33 +07:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{versions && (
|
|
|
|
<>
|
|
|
|
<Heading variant={'subheading'}>{'Version History'}</Heading>
|
2019-03-28 05:39:06 +07:00
|
|
|
{this.renderPackageList(versions, true, timeMap)}
|
2019-02-03 17:23:33 +07:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Versions;
|