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

View File

@ -6,10 +6,29 @@ import HomeIcon from '@material-ui/icons/Home';
import ListItem from '@material-ui/core/ListItem'; import ListItem from '@material-ui/core/ListItem';
import Tooltip from '@material-ui/core/Tooltip'; import Tooltip from '@material-ui/core/Tooltip';
import { PackageMetaInterface } from 'types/packageMeta';
import Tag from '../Tag'; import Tag from '../Tag';
import fileSizeSI from '../../utils/file-size'; import fileSizeSI from '../../utils/file-size';
import { formatDate, formatDateDistance } from '../../utils/package'; 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 { interface Author {
name: string; name: string;
avatar?: string; avatar?: string;
@ -30,32 +49,11 @@ export interface PackageInterface {
author: Author; author: Author;
description?: string; description?: string;
keywords?: string[]; keywords?: string[];
license?: string | null; license?: PackageMetaInterface['latest']['license'];
homepage?: string; homepage?: string;
bugs?: Bugs; bugs?: Bugs;
dist?: Dist; 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> = ({ const Package: React.FC<PackageInterface> = ({
author: { name: authorName, avatar: authorAvatar }, author: { name: authorName, avatar: authorAvatar },

View File

@ -6,11 +6,6 @@ import { isObject } from 'util';
export const TIMEFORMAT = 'DD.MM.YYYY, HH:mm:ss'; export const TIMEFORMAT = 'DD.MM.YYYY, HH:mm:ss';
export interface License {
type: string;
url: string;
}
/** /**
* Formats license field for webui. * Formats license field for webui.
* @see https://docs.npmjs.com/files/package.json#license * @see https://docs.npmjs.com/files/package.json#license

View File

@ -5,7 +5,12 @@ export interface PackageMetaInterface {
fileCount: number; fileCount: number;
unpackedSize: number; unpackedSize: number;
}; };
license: string; license?: Partial<LicenseInterface> | string | null;
}; };
_uplinks: {}; _uplinks: {};
} }
interface LicenseInterface {
type: string;
url: string;
}