-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add basic package infos and resource links to sidebar.
Shows homepage, repository url and license if available in meta data. If no data is available the module isn't shown.
- Loading branch information
Peter Kaske
committed
Jun 13, 2018
1 parent
9159e20
commit 7bd3a4f
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/webui/src/components/PackageSidebar/modules/Infos/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import get from 'lodash/get'; | ||
import Module from '../../Module'; | ||
|
||
import classes from './style.scss'; | ||
|
||
export default class Infos extends React.Component { | ||
static propTypes = { | ||
packageMeta: PropTypes.object.isRequired | ||
}; | ||
|
||
get infos() { | ||
const homepage = this.normalizeInfo(get(this, 'props.packageMeta.latest.homepage', null)); | ||
const repo = this.normalizeInfo(get(this, 'props.packageMeta.latest.repository', null)); | ||
const license = get(this, 'props.packageMeta.latest.license', 'N/A'); | ||
|
||
return {homepage, repo, license}; | ||
} | ||
|
||
normalizeInfo(infoObj) { | ||
if (typeof infoObj === 'string') { | ||
return {url: infoObj}; | ||
} else if (infoObj === null) { | ||
return {url: ''}; | ||
} | ||
|
||
infoObj.url = infoObj.url.replace(/^git\+/, ''); | ||
|
||
return infoObj; | ||
} | ||
|
||
render() { | ||
const infos = this.infos; | ||
|
||
if (!infos.homepage.url && !infos.repo.url && infos.license === 'N/A') { | ||
return ''; | ||
} | ||
|
||
return ( | ||
<Module | ||
title="Infos" | ||
className={classes.infosModule} | ||
> | ||
<ul> | ||
{infos.homepage.url && | ||
<li><span>Homepage</span><a href={infos.homepage.url} target="_blank">{infos.homepage.url}</a></li> | ||
} | ||
|
||
{infos.repo.url && | ||
<li><span>Repository</span><a href={infos.repo.url} target="_blank">{infos.repo.url}</a></li> | ||
} | ||
|
||
{infos.license && | ||
<li><span>License</span><span>{infos.license}</span></li> | ||
} | ||
</ul> | ||
</Module> | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/webui/src/components/PackageSidebar/modules/Infos/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@import '../../../../styles/variable'; | ||
|
||
.infosModule { | ||
li { | ||
display: flex; | ||
font-size: 14px; | ||
line-height: 2; | ||
|
||
a { | ||
color: inherit; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
max-width: 150px; | ||
} | ||
|
||
a:last-child, | ||
span:last-child { | ||
margin-left: auto; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<PackageSidebar /> : <Infos /> should load the Info component and match snapshot 1`] = `"<div class=\\"module infosModule\\"><h2 class=\\"moduleTitle\\">Infos</h2><div><ul><li><span>Homepage</span><a href=\\"https://github.com/verdaccio/verdaccio#readme\\" target=\\"_blank\\">https://github.com/verdaccio/verdaccio#readme</a></li><li><span>Repository</span><a href=\\"git://github.com/verdaccio/verdaccio.git\\" target=\\"_blank\\">git://github.com/verdaccio/verdaccio.git</a></li><li><span>License</span><span>WTFPL</span></li></ul></div></div>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* LastSync component | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mount, shallow } from 'enzyme'; | ||
import Infos from '../../../../src/webui/src/components/PackageSidebar/modules/Infos'; | ||
import { packageMeta } from '../store/packageMeta'; | ||
|
||
console.error = jest.fn(); | ||
|
||
describe('<PackageSidebar /> : <Infos />', () => { | ||
it('should load the component and check getter: info with package data', () => { | ||
const wrapper = mount(<Infos packageMeta={packageMeta} />); | ||
const instance = wrapper.instance(); | ||
const result = { | ||
repo: { type: 'git', url: 'git://github.com/verdaccio/verdaccio.git' }, | ||
homepage: { url: 'https://github.com/verdaccio/verdaccio#readme' }, | ||
license: 'WTFPL' | ||
}; | ||
|
||
expect(instance.infos).toEqual(result); | ||
}); | ||
|
||
it('should load the Info component and match snapshot', () => { | ||
const wrapper = shallow(<Infos packageMeta={packageMeta} />); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
}); |