2019-03-28 05:39:06 +07:00
|
|
|
import React, { Component } from 'react';
|
2019-04-09 03:29:20 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import List from '@material-ui/core/List';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import { DetailContextConsumer } from '../../pages/version/Version';
|
2019-04-09 03:29:20 +07:00
|
|
|
import { Heading, DistListItem, DistChips } from './styles';
|
2019-03-28 05:39:06 +07:00
|
|
|
import fileSizeSI from '../../utils/file-size';
|
|
|
|
|
|
|
|
class Dist extends Component<any, any> {
|
2019-06-25 04:03:21 +07:00
|
|
|
public render() {
|
2019-03-28 05:39:06 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-20 19:37:28 +07:00
|
|
|
{(context: any) => {
|
2019-03-28 05:39:06 +07:00
|
|
|
return this.renderDist(context);
|
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 04:03:21 +07:00
|
|
|
private renderChips(dist: any, license: string) {
|
2019-03-28 05:39:06 +07:00
|
|
|
const distDict = {
|
|
|
|
'file-count': dist.fileCount,
|
|
|
|
size: dist.unpackedSize && fileSizeSI(dist.unpackedSize),
|
|
|
|
license,
|
|
|
|
};
|
|
|
|
|
|
|
|
const chipsList = Object.keys(distDict).reduce((componentList, title, key) => {
|
2019-06-20 19:37:28 +07:00
|
|
|
// @ts-ignore
|
2019-03-28 05:39:06 +07:00
|
|
|
const value = distDict[title];
|
|
|
|
if (value) {
|
|
|
|
const label = (
|
|
|
|
<span>
|
2019-04-09 03:29:20 +07:00
|
|
|
{/* eslint-disable-next-line */}
|
|
|
|
<b>{title.split('-').join(' ')}</b>:{value}
|
2019-03-28 05:39:06 +07:00
|
|
|
</span>
|
|
|
|
);
|
2019-06-20 19:37:28 +07:00
|
|
|
// @ts-ignore is not assignable to parameter of type 'never'
|
2019-04-09 03:29:20 +07:00
|
|
|
componentList.push(<DistChips key={key} label={label} />);
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
return componentList;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return chipsList;
|
|
|
|
}
|
|
|
|
|
2019-06-25 04:03:21 +07:00
|
|
|
private renderDist = ({ packageMeta }: any) => {
|
2019-03-28 05:39:06 +07:00
|
|
|
const { dist = {}, license } = packageMeta.latest;
|
|
|
|
|
|
|
|
return (
|
2019-06-20 19:37:28 +07:00
|
|
|
<List subheader={<Heading variant="subheading">{'Latest Distribution'}</Heading>}>
|
2019-03-28 05:39:06 +07:00
|
|
|
<DistListItem>{this.renderChips(dist, license)}</DistListItem>
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Dist;
|