From 453bceec4c819b9680f0d5867e86f651d798f1af Mon Sep 17 00:00:00 2001
From: Peter Kaske
Date: Thu, 14 Jun 2018 08:43:01 +0200
Subject: [PATCH] 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
---
.../PackageSidebar/modules/Infos/index.jsx | 28 ++++++++++++-------
.../components/PackageSidebar/infos.spec.js | 2 +-
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/webui/src/components/PackageSidebar/modules/Infos/index.jsx b/src/webui/src/components/PackageSidebar/modules/Infos/index.jsx
index f6f4f9b51..bdff8df79 100644
--- a/src/webui/src/components/PackageSidebar/modules/Infos/index.jsx
+++ b/src/webui/src/components/PackageSidebar/modules/Infos/index.jsx
@@ -2,6 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import get from 'lodash/get';
import Module from '../../Module';
+import isString from 'lodash/isString';
+import isNil from 'lodash/isNil';
import classes from './style.scss';
@@ -19,21 +21,25 @@ export default class Infos extends React.Component {
}
normalizeInfo(infoObj) {
- if (typeof infoObj === 'string') {
+ if (isString(infoObj)) {
return {url: infoObj};
- } else if (infoObj === null) {
+ } else if (isNil(infoObj)) {
return {url: ''};
}
- infoObj.url = infoObj.url.replace(/^git\+/, '');
+ infoObj.url = this.normalizeGitUrl(infoObj);
return infoObj;
}
+ normalizeGitUrl(infoObj) {
+ return infoObj.url.replace(/^git\+/, '');
+ }
+
render() {
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 '';
}
@@ -43,13 +49,9 @@ export default class Infos extends React.Component {
className={classes.infosModule}
>
- {infos.homepage.url &&
- - Homepage{infos.homepage.url}
- }
+ {infos.homepage.url && this.renderSection('Homepage', infos.homepage.url)}
- {infos.repo.url &&
- - Repository{infos.repo.url}
- }
+ {infos.repo.url && this.renderSection('Repository', infos.repo.url)}
{infos.license &&
- License{infos.license}
@@ -58,4 +60,10 @@ export default class Infos extends React.Component {
);
}
+
+ renderSection(title, url) {
+ return (
+ - {title}{url}
+ );
+ }
}
diff --git a/test/webui/components/PackageSidebar/infos.spec.js b/test/webui/components/PackageSidebar/infos.spec.js
index 18cb27622..13778f556 100644
--- a/test/webui/components/PackageSidebar/infos.spec.js
+++ b/test/webui/components/PackageSidebar/infos.spec.js
@@ -1,5 +1,5 @@
/**
- * LastSync component
+ * Infos component
*/
import React from 'react';