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-08-25 19:34:27 +07:00
|
|
|
import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/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';
|
2019-06-25 05:54:32 +07:00
|
|
|
import { PackageMetaInterface } from 'types/packageMeta';
|
2019-07-06 16:50:09 +07:00
|
|
|
import { formatLicense } from '../../utils/package';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-25 05:54:32 +07:00
|
|
|
class Dist extends Component {
|
2019-06-25 05:01:13 +07:00
|
|
|
public render(): JSX.Element {
|
2019-03-28 05:39:06 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-25 05:54:32 +07:00
|
|
|
{(context: Partial<VersionPageConsumerProps>) => {
|
|
|
|
return context && context.packageMeta && this.renderDist(context.packageMeta);
|
2019-03-28 05:39:06 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-06 16:50:09 +07:00
|
|
|
private renderChips(dist, license: PackageMetaInterface['latest']['license']): (JSX.Element | undefined)[] {
|
2019-03-28 05:39:06 +07:00
|
|
|
const distDict = {
|
|
|
|
'file-count': dist.fileCount,
|
|
|
|
size: dist.unpackedSize && fileSizeSI(dist.unpackedSize),
|
|
|
|
license,
|
|
|
|
};
|
|
|
|
|
2019-07-06 16:50:09 +07:00
|
|
|
const chipsList = Object.keys(distDict).map((dist, key) => {
|
|
|
|
if (!distDict[dist]) return;
|
|
|
|
|
|
|
|
const value = dist === 'license' ? formatLicense(distDict[dist]) : distDict[dist];
|
|
|
|
const label = (
|
2019-07-06 23:43:00 +07:00
|
|
|
<>
|
2019-07-06 16:50:09 +07:00
|
|
|
{/* eslint-disable-next-line */}
|
|
|
|
<b>{dist.replace('-', ' ')}</b>: {value}
|
2019-07-06 23:43:00 +07:00
|
|
|
</>
|
2019-07-06 16:50:09 +07:00
|
|
|
);
|
|
|
|
return <DistChips key={key} label={label} />;
|
|
|
|
});
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
return chipsList;
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:54:32 +07:00
|
|
|
private renderDist = (packageMeta: PackageMetaInterface) => {
|
|
|
|
const { dist, license } = packageMeta && packageMeta.latest;
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
return (
|
2019-08-31 16:02:46 +07:00
|
|
|
<List subheader={<Heading variant="subtitle1">{'Latest Distribution'}</Heading>}>
|
|
|
|
<DistListItem button={true}>{this.renderChips(dist, license)}</DistListItem>
|
2019-03-28 05:39:06 +07:00
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Dist;
|