0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00

refactor: package list [WIP]

This commit is contained in:
Ayush Sharma 2019-03-03 20:01:41 +01:00
parent 07d9aebc62
commit c9858c85e3
9 changed files with 211 additions and 279 deletions

View file

@ -1,5 +1,6 @@
/**
* @prettier
* @flow
*/
import _ from 'lodash';
@ -515,7 +516,7 @@ export function getVersionFromTarball(name: string) {
* @see https://docs.npmjs.com/files/package.json#author
* @param {string|object|undefined} author
*/
export function formatAuthor(author:any) {
export function formatAuthor(author: any) {
let authorDetails = {
name: DEFAULT_USER,
email: '',

View file

@ -1,3 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" id="filebinary">
<svg xmlns="http://www.w3.org/2000/svg" id="fileBinary">
<path d="M8.5 1H1c-.55 0-1 .45-1 1v12c0 .55.45 1 1 1h10c.55 0 1-.45 1-1V4.5L8.5 1zM11 14H1V2h7l3 3v9zM5 6.98L3.5 8.5 5 10l-.5 1L2 8.5 4.5 6l.5.98zM7.5 6L10 8.5 7.5 11l-.5-.98L8.5 8.5 7 7l.5-1z"></path>
</svg>

Before

Width:  |  Height:  |  Size: 265 B

After

Width:  |  Height:  |  Size: 265 B

View file

@ -19,11 +19,11 @@ import austria from './img/austria.svg';
import spain from './img/spain.svg';
import earth from './img/earth.svg';
import verdaccio from './img/verdaccio.svg';
import license from './img/license.svg';
import fileBinary from './img/fileBinary.svg';
import law from './img/law.svg';
import license from './img/license.svg';
import time from './img/time.svg';
import version from './img/version.svg';
import filebinary from './img/filebinary.svg';
export const Icons: $Shape<IIconsMap> = {
// flags
@ -36,11 +36,12 @@ export const Icons: $Shape<IIconsMap> = {
austria,
earth,
verdaccio,
// other icons
fileBinary,
law,
license,
time,
law,
version,
filebinary,
};
const Icon = ({ className, name, size = 'sm', img = false, pointer = false, ...props }: IProps): Node => {

View file

@ -19,7 +19,7 @@ export interface IIconsMap {
time: string;
law: string;
version: string;
filebinary: string;
fileBinary: string;
[key: string]: string;
}

View file

@ -1,72 +1,53 @@
/**
* @prettier
* @flow
*/
/* eslint-disable */
import React from 'react';
import type { Element } from 'react';
import { spacing } from '../../utils/styles/mixings';
import Grid from '@material-ui/core/Grid/index';
import List from '@material-ui/core/List/index';
import ListItem from '@material-ui/core/ListItem/index';
import ListItemText from '@material-ui/core/ListItemText/index';
// import ListItemAvatar from '@material-ui/core/ListItemAvatar/index';
// import Avatar2 from '@material-ui/core/Avatar/index';
import Typography from '@material-ui/core/Typography/index';
import IconButton from '@material-ui/core/IconButton';
import BugReport from '@material-ui/icons/BugReport';
import Tooltip from '@material-ui/core/Tooltip/index';
import Grid from '@material-ui/core/Grid/index';
import HomeIcon from '@material-ui/icons/Home';
// import BookmarkBorder from '@material-ui/icons/BookmarkBorder/index';
import ListItem from '@material-ui/core/ListItem/index';
import Tooltip from '@material-ui/core/Tooltip/index';
import Tag from '../Tag';
import fileSizeSI from '../../utils/file-size';
import { formatDate, formatDateDistance } from '../../utils/package';
import { IProps } from './types';
import {
WrapperLink,
Header,
MainInfo,
Name,
Version,
Overview,
Published,
OverviewItem,
Description,
Icon,
Text,
Details,
Avatar,
Author,
Field,
Content,
Footer,
PackageName,
} from './styles';
import { fontWeight } from '../../utils/styles/sizes';
// const getInitialsName = (name: string) =>
// name
// .split(' ')
// .reduce((accumulator, currentValue) => accumulator.charAt(0) + currentValue.charAt(0), '')
// .toUpperCase();
import {
Author,
Avatar,
Description,
Details,
GridRightAligned,
Icon,
IconButton,
OverviewItem,
PackageList,
PackageListItem,
PackageListItemText,
PackageTitle,
Published,
TagContainer,
Text,
WrapperLink,
} from './styles';
const Package = ({
name: label,
version,
dist: { unpackedSize } = {},
time,
author: { name, avatar },
author: { name: authorName, avatar: authorAvatar },
bugs: { url } = {},
description,
license,
keywords = [],
dist: { unpackedSize } = {},
homepage,
bugs,
keywords = [],
license,
name: packageName,
time,
version,
}: IProps): Element<WrapperLink> => {
console.log(homepage);
//
const renderVersionInfo = () =>
version && (
<OverviewItem>
@ -75,21 +56,20 @@ const Package = ({
</OverviewItem>
);
const renderAuthorInfo = () => {
return (
const renderAuthorInfo = () =>
authorName && (
<Author>
<Avatar alt={name} src={avatar} style={{ width: '20px', height: '20px' }} />
<Avatar alt={authorName} src={authorAvatar} />
<Details>
<Text text={name} />
<Text text={authorName} />
</Details>
</Author>
);
}
const renderFileSize = () =>
unpackedSize && (
<OverviewItem>
<Icon name={'filebinary'} />
<Icon name={'fileBinary'} />
{fileSizeSI(unpackedSize)}
</OverviewItem>
);
@ -102,114 +82,79 @@ const Package = ({
</OverviewItem>
);
const renderPublishedInfo = () => (
<OverviewItem>
<Icon name={'time'} />
<Published modifiers={spacing('margin', '0px', '5px', '0px', '0px')}>{`Published on ${formatDate(time)}`}</Published>
{`${formatDateDistance(time)} ago`}
</OverviewItem>
);
const renderDescription = () =>
description && (
<Field>
<Description>{description}</Description>
</Field>
const renderPublishedInfo = () =>
time && (
<OverviewItem>
<Icon name={'time'} />
<Published>{`Published on ${formatDate(time)}`}</Published>
{`${formatDateDistance(time)} ago`}
</OverviewItem>
);
// return (
// <WrapperLink className={'package'} to={`/-/web/detail/${label}`}>
// <Header>
// {renderMainInfo()}
// <Overview>
// {renderLicenseInfo()}
// {renderPublishedInfo()}
// </Overview>
// </Header>
// <Content>
// <Field>{renderAuthorInfo()}</Field>
// {renderDescription()}
// </Content>
// {keywords.length > 0 && (
// <Footer>
// {keywords.sort().map((keyword, index) => (
// <Tag key={index}>{keyword}</Tag>
// ))}
// </Footer>
// )}
// </WrapperLink>
// );
const tags = keywords.sort().map((keyword, index) => (
<Tag style={{ color: '#485A3E' }} key={index}>
{keyword}
</Tag>
));
const renderHomePageLink = () =>
homepage && (
<a href={homepage} target="_blank">
<Tooltip title="Visit homepage" aria-label="Add">
<IconButton aria-label="Report" style={{ padding: '6px' }}>
<HomeIcon fontSize="small" style={{ fontSize: '16px' }} />
<a href={homepage} target={'_blank'}>
<Tooltip aria-label={'Homepage'} title={'Visit homepage'}>
<IconButton aria-label={'Homepage'}>
{/* eslint-disable-next-line react/jsx-max-depth */}
<HomeIcon />
</IconButton>
</Tooltip>
</a>
);
const renderBugsLink = () =>
bugs &&
bugs.url && (
<a href={bugs.url} target="_blank">
<Tooltip title="Open an issue" aria-label="Add">
<IconButton aria-label="Report" style={{ padding: '6px' }}>
<BugReport fontSize="small" style={{ fontSize: '16px' }} />
url && (
<a href={url} target={'_blank'}>
<Tooltip aria-label={'Bugs'} title={'Open an issue'}>
<IconButton aria-label={'Bugs'}>
{/* eslint-disable-next-line react/jsx-max-depth */}
<BugReport />
</IconButton>
</Tooltip>
</a>
);
const renderPrimaryComponent = () => {
return (
<Grid container={true} item={true} xs={12}>
<Grid item={true} xs={true}>
<WrapperLink to={`/-/web/detail/${packageName}`}>
{/* eslint-disable-next-line react/jsx-max-depth */}
<PackageTitle>{packageName}</PackageTitle>
</WrapperLink>
</Grid>
<GridRightAligned item={true} xs={true}>
{renderHomePageLink()}
{renderBugsLink()}
</GridRightAligned>
</Grid>
);
};
const renderSecondaryComponent = () => {
const tags = keywords.sort().map((keyword, index) => <Tag key={index}>{keyword}</Tag>);
return (
<>
<Description component={'span'}>{description}</Description>
{tags.length > 0 && <TagContainer>{tags}</TagContainer>}
</>
);
};
return (
<List style={{ padding: '12px 0 12px 0' }}>
<ListItem alignItems="flex-start">
<ListItemText
component="div"
style={{ paddingRight: 0 }}
primary={
<Grid item xs={12} container>
<Grid item xs>
<WrapperLink to={`/-/web/detail/${label}`}>
<PackageName>{label}</PackageName>
</WrapperLink>
</Grid>
<Grid item xs style={{ textAlign: 'right' }}>
{renderHomePageLink()}
{renderBugsLink()}
{/* <Tooltip title="Pin it" aria-label="Add">
<IconButton aria-label="Report" style={{ padding: '6px' }}>
<BookmarkBorder fontSize="small" style={{ fontSize: '16px' }} />
</IconButton>
</Tooltip> */}
</Grid>
</Grid>
}
secondary={
<React.Fragment>
<Typography component="span" style={{ color: '#586069', fontSize: '14px', paddingRight: 0 }}>
{description}
</Typography>
{tags.length > 0 && <span style={{ marginTop: '8px', display: 'block' }}>{tags}</span>}
</React.Fragment>
}
/>
<PackageList>
<ListItem alignItems={'flex-start'}>
<PackageListItemText component={'div'} primary={renderPrimaryComponent()} secondary={renderSecondaryComponent()} />
</ListItem>
<ListItem alignItems="flex-start">
<PackageListItem alignItems={'flex-start'}>
{renderAuthorInfo()}
{renderVersionInfo()}
{renderPublishedInfo()}
{renderFileSize()}
{renderLicenseInfo()}
</ListItem>
</List>
</PackageListItem>
</PackageList>
);
};
export default Package;

View file

@ -5,124 +5,66 @@
import styled from 'react-emotion';
import { Link } from 'react-router-dom';
import { default as Photo } from '@material-ui/core/Avatar';
import { default as Ico } from '../Icon';
// import mq from '../../utils/styles/media';
import { ellipsis } from '../../utils/styles/mixings';
import colors from '../../utils/styles/colors';
import Grid from '@material-ui/core/Grid/index';
import List from '@material-ui/core/List/index';
import ListItem from '@material-ui/core/ListItem/index';
import ListItemText from '@material-ui/core/ListItemText/index';
import MuiIconButton from '@material-ui/core/IconButton/index';
import Photo from '@material-ui/core/Avatar';
import Typography from '@material-ui/core/Typography/index';
import { breakpoints } from '../../utils/styles/media';
import Ico from '../Icon';
import Label from '../Label';
// HEADER
export const Header = styled.div`
&& {
display: flex;
flex-direction: column;
padding: 0 0 5px 0;
}
`;
export const Name = styled.span`
&& {
color: ${colors.primary};
}
`;
export const MainInfo = styled.span`
&& {
font-size: 16px;
font-weight: 600;
line-height: 30px;
flex: 1;
color: #3a8bff;
padding: 0 10px 0 0;
overflow: hidden;
display: flex;
align-items: center;
:hover {
${Name} {
text-decoration: underline;
}
}
}
`;
import colors from '../../utils/styles/colors';
export const OverviewItem = styled.span`
&& {
display: flex;
align-items: center;
margin: 0 0 0 16px;
color: #908ba1;
font-size: 16px;
}
`;
export const Overview = styled.span`
&& {
position: relative;
display: flex;
flex-direction: column;
}
`;
export const Version = styled.span`
&& {
color: ${colors.greyLight2};
font-size: 12px;
padding: 0 0 0 10px;
margin: 0 0 0 5px;
color: #9f9f9f;
position: relative;
${ellipsis('100%')};
:before {
content: '•';
position: absolute;
left: 0;
@media (max-width: ${breakpoints.medium}px) {
&:nth-child(3) {
display: none;
}
}
@media (max-width: ${breakpoints.small}px) {
&:nth-child(4) {
display: none;
}
}
}
`;
export const Icon = styled(Ico)`
&& {
margin: 0px 10px 0px 0;
fill: #908ba1;
margin: 2px 10px 0px 0;
fill: ${colors.greyLight2};
}
`;
export const Published = styled.span`
&& {
color: #908ba1;
${({ modifiers }) => modifiers};
}
`;
// Content
export const Field = styled.div`
&& {
padding: 0 0 5px 0;
}
`;
export const Content = styled.div`
&& {
${Field} {
:last-child {
padding: 0;
}
}
color: ${colors.greyLight2};
margin: 0px 5px 0px 0px;
}
`;
export const Text = styled(Label)`
&& {
color: #908ba1;
font-size: 12px;
font-weight: 500;
color: ${colors.greyLight2};
}
`;
export const Details = styled.span`
&& {
margin-left: 5px;
line-height: 14px;
line-height: 1.5;
display: flex;
flex-direction: column;
}
@ -137,49 +79,88 @@ export const Author = styled.div`
export const Avatar = styled(Photo)`
&& {
width: 30px;
height: 30px;
background: #4b5e40;
font-size: 15px;
width: 20px;
height: 20px;
}
`;
export const Description = styled.div`
&& {
margin: 5px 0;
}
`;
// Footer
export const Footer = styled.div`
&& {
display: none;
padding: 5px 0 0 0;
}
`;
// Container
export const WrapperLink = styled(Link)`
&& {
text-decoration: none;
}
`;
/**
* Ayush's style
*/
export const PackageName = styled.span`
export const PackageTitle = styled.span`
&& {
font-weight: 600;
font-size: 20px;
display: block;
margin-bottom: 12px;
color: #414141;
color: ${colors.eclipse};
cursor: pointer;
&:hover {
color: black;
color: ${colors.black};
}
@media (max-width: ${breakpoints.small}px) {
font-size: 14px;
margin-bottom: 8px;
}
}
`;
export const GridRightAligned = styled(Grid)`
&& {
text-align: right;
}
`;
export const PackageList = styled(List)`
&& {
padding: 12px 0 12px 0;
&:hover {
background-color: ${colors.greyLight3};
}
}
`;
export const IconButton = styled(MuiIconButton)`
&& {
padding: 6px;
svg {
font-size: 16px;
}
}
`;
export const TagContainer = styled.span`
&& {
margin-top: 8px;
margin-bottom: 12px;
display: block;
@media (max-width: ${breakpoints.medium}px) {
display: none;
}
}
`;
export const PackageListItem = styled(ListItem)`
&& {
padding-top: 0;
}
`;
export const PackageListItemText = styled(ListItemText)`
&& {
padding-right: 0;
}
`;
export const Description = styled(Typography)`
color: ${colors.greyDark2};
font-size: 14px;
padding-right: 0;
`;

View file

@ -2,6 +2,7 @@ import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import Divider from '@material-ui/core/Divider';
import Package from '../Package';
import Help from '../Help';
import { formatLicense } from '../../utils/package';
@ -13,6 +14,21 @@ export default class PackageList extends React.Component {
packages: PropTypes.array,
};
render() {
return (
<div className={"package-list-items"}>
<div className={classes.pkgContainer}>
{this.hasPackages() ? this.renderPackages(): <Help /> }
</div>
</div>
);
}
hasPackages() {
const {packages} = this.props;
return packages.length > 0;
}
renderPackages = () => {
return (
<Fragment>
@ -27,30 +43,15 @@ export default class PackageList extends React.Component {
packages.map((pkg, i) => {
const { name, version, description, time, keywords, dist, homepage, bugs } = pkg;
const author = pkg.author;
// TODO: move format license to API side.
const license = formatLicense(pkg.license);
return (
<React.Fragment key={i}>
{i !== 0 && <Divider style={{ margin: 0 }}></Divider>}
{i !== 0 && <Divider></Divider>}
<Package {...{ name, dist, version, author, description, license, time, keywords, homepage, bugs }} />
</React.Fragment>
);
})
);
}
render() {
return (
<div className={"package-list-items"}>
<div className={classes.pkgContainer}>
{this.hasPackages() ? this.renderPackages(): <Help /> }
</div>
</div>
);
}
hasPackages() {
const {packages} = this.props;
return packages.length > 0;
}
}

View file

@ -10,7 +10,10 @@ const colors = {
grey: '#808080',
greySuperLight: '#f5f5f5',
greyLight: '#d3d3d3',
greyLight2: '#908ba1',
greyLight3: '#f3f4f240',
greyDark: '#a9a9a9',
greyDark2: '#586069',
greyChateau: '#95989a',
greyGainsboro: '#e3e3e3',
greyAthens: '#d3dddd',

View file

@ -1,6 +1,6 @@
import { css } from 'emotion';
const breakpoints = {
export const breakpoints = {
small: 576,
medium: 768,
large: 1024,