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-25 05:54:32 +07:00
|
|
|
import { DetailContextConsumer, VersionPageConsumerProps } 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';
|
2019-06-25 05:54:32 +07:00
|
|
|
import { PackageMetaInterface } from 'types/packageMeta';
|
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-06-25 05:54:32 +07:00
|
|
|
private renderChips(dist, license: string): JSX.Element | never[] {
|
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 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-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;
|