0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

Changes as requested by reviewer.

- Fix test name in spec file
- Use lodash isString and isNill
- Move normalisation of git url into it's own function
- Create a renderSection() function to render links in a more "dry" way
This commit is contained in:
Peter Kaske 2018-06-14 08:43:01 +02:00
parent 7bd3a4f292
commit 453bceec4c
2 changed files with 19 additions and 11 deletions

View file

@ -2,6 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import get from 'lodash/get'; import get from 'lodash/get';
import Module from '../../Module'; import Module from '../../Module';
import isString from 'lodash/isString';
import isNil from 'lodash/isNil';
import classes from './style.scss'; import classes from './style.scss';
@ -19,21 +21,25 @@ export default class Infos extends React.Component {
} }
normalizeInfo(infoObj) { normalizeInfo(infoObj) {
if (typeof infoObj === 'string') { if (isString(infoObj)) {
return {url: infoObj}; return {url: infoObj};
} else if (infoObj === null) { } else if (isNil(infoObj)) {
return {url: ''}; return {url: ''};
} }
infoObj.url = infoObj.url.replace(/^git\+/, ''); infoObj.url = this.normalizeGitUrl(infoObj);
return infoObj; return infoObj;
} }
normalizeGitUrl(infoObj) {
return infoObj.url.replace(/^git\+/, '');
}
render() { render() {
const infos = this.infos; const infos = this.infos;
if (!infos.homepage.url && !infos.repo.url && infos.license === 'N/A') { if (infos.homepage.url === '' && infos.repo.url === '' && infos.license === 'N/A') {
return ''; return '';
} }
@ -43,13 +49,9 @@ export default class Infos extends React.Component {
className={classes.infosModule} className={classes.infosModule}
> >
<ul> <ul>
{infos.homepage.url && {infos.homepage.url && this.renderSection('Homepage', infos.homepage.url)}
<li><span>Homepage</span><a href={infos.homepage.url} target="_blank">{infos.homepage.url}</a></li>
}
{infos.repo.url && {infos.repo.url && this.renderSection('Repository', infos.repo.url)}
<li><span>Repository</span><a href={infos.repo.url} target="_blank">{infos.repo.url}</a></li>
}
{infos.license && {infos.license &&
<li><span>License</span><span>{infos.license}</span></li> <li><span>License</span><span>{infos.license}</span></li>
@ -58,4 +60,10 @@ export default class Infos extends React.Component {
</Module> </Module>
); );
} }
renderSection(title, url) {
return (
<li><span>{title}</span><a href={url} target="_blank">{url}</a></li>
);
}
} }

View file

@ -1,5 +1,5 @@
/** /**
* LastSync component * Infos component
*/ */
import React from 'react'; import React from 'react';