1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-16 08:05:44 +07:00

fix: support deprecated license object properties

This commit is contained in:
Griffithtp
2019-07-06 10:50:09 +01:00
parent 283464fd13
commit b2e420dbd9
4 changed files with 41 additions and 45 deletions

View File

@@ -6,6 +6,7 @@ import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/ver
import { Heading, DistListItem, DistChips } from './styles';
import fileSizeSI from '../../utils/file-size';
import { PackageMetaInterface } from 'types/packageMeta';
import { formatLicense } from '../../utils/package';
class Dist extends Component {
public render(): JSX.Element {
@@ -18,28 +19,25 @@ class Dist extends Component {
);
}
private renderChips(dist, license: string): JSX.Element | never[] {
private renderChips(dist, license: PackageMetaInterface['latest']['license']): (JSX.Element | undefined)[] {
const distDict = {
'file-count': dist.fileCount,
size: dist.unpackedSize && fileSizeSI(dist.unpackedSize),
license,
};
const chipsList = Object.keys(distDict).reduce((componentList, title, key) => {
// @ts-ignore
const value = distDict[title];
if (value) {
const label = (
<span>
{/* eslint-disable-next-line */}
<b>{title.split('-').join(' ')}</b>:{value}
</span>
);
// @ts-ignore is not assignable to parameter of type 'never'
componentList.push(<DistChips key={key} label={label} />);
}
return componentList;
}, []);
const chipsList = Object.keys(distDict).map((dist, key) => {
if (!distDict[dist]) return;
const value = dist === 'license' ? formatLicense(distDict[dist]) : distDict[dist];
const label = (
<span>
{/* eslint-disable-next-line */}
<b>{dist.replace('-', ' ')}</b>: {value}
</span>
);
return <DistChips key={key} label={label} />;
});
return chipsList;
}