mirror of
https://github.com/SomboChea/ui
synced 2024-11-24 06:54:27 +07:00
fix: support deprecated license object properties
This commit is contained in:
parent
283464fd13
commit
b2e420dbd9
@ -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;
|
||||
}
|
||||
|
@ -6,10 +6,29 @@ import HomeIcon from '@material-ui/icons/Home';
|
||||
import ListItem from '@material-ui/core/ListItem';
|
||||
import Tooltip from '@material-ui/core/Tooltip';
|
||||
|
||||
import { PackageMetaInterface } from 'types/packageMeta';
|
||||
import Tag from '../Tag';
|
||||
import fileSizeSI from '../../utils/file-size';
|
||||
import { formatDate, formatDateDistance } from '../../utils/package';
|
||||
|
||||
import {
|
||||
Author,
|
||||
Avatar,
|
||||
Description,
|
||||
Details,
|
||||
GridRightAligned,
|
||||
Icon,
|
||||
IconButton,
|
||||
OverviewItem,
|
||||
PackageList,
|
||||
PackageListItem,
|
||||
PackageListItemText,
|
||||
PackageTitle,
|
||||
Published,
|
||||
TagContainer,
|
||||
Text,
|
||||
WrapperLink,
|
||||
} from './styles';
|
||||
import { isURL } from '../../utils/url';
|
||||
interface Author {
|
||||
name: string;
|
||||
avatar?: string;
|
||||
@ -30,32 +49,11 @@ export interface PackageInterface {
|
||||
author: Author;
|
||||
description?: string;
|
||||
keywords?: string[];
|
||||
license?: string | null;
|
||||
license?: PackageMetaInterface['latest']['license'];
|
||||
homepage?: string;
|
||||
bugs?: Bugs;
|
||||
dist?: Dist;
|
||||
}
|
||||
// interface Props {} & PackageInterface;
|
||||
|
||||
import {
|
||||
Author,
|
||||
Avatar,
|
||||
Description,
|
||||
Details,
|
||||
GridRightAligned,
|
||||
Icon,
|
||||
IconButton,
|
||||
OverviewItem,
|
||||
PackageList,
|
||||
PackageListItem,
|
||||
PackageListItemText,
|
||||
PackageTitle,
|
||||
Published,
|
||||
TagContainer,
|
||||
Text,
|
||||
WrapperLink,
|
||||
} from './styles';
|
||||
import { isURL } from '../../utils/url';
|
||||
|
||||
const Package: React.FC<PackageInterface> = ({
|
||||
author: { name: authorName, avatar: authorAvatar },
|
||||
|
@ -6,11 +6,6 @@ import { isObject } from 'util';
|
||||
|
||||
export const TIMEFORMAT = 'DD.MM.YYYY, HH:mm:ss';
|
||||
|
||||
export interface License {
|
||||
type: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats license field for webui.
|
||||
* @see https://docs.npmjs.com/files/package.json#license
|
||||
|
@ -5,7 +5,12 @@ export interface PackageMetaInterface {
|
||||
fileCount: number;
|
||||
unpackedSize: number;
|
||||
};
|
||||
license: string;
|
||||
license?: Partial<LicenseInterface> | string | null;
|
||||
};
|
||||
_uplinks: {};
|
||||
}
|
||||
|
||||
interface LicenseInterface {
|
||||
type: string;
|
||||
url: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user