From fed9711f485dc85725abe60b07ed22808c51a7fa Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Mon, 4 Feb 2019 22:08:26 +0100 Subject: [PATCH] refactor: removes old package sidebar --- .../PackageSidebar/Module/index.jsx | 25 ---- .../PackageSidebar/Module/style.scss | 24 ---- .../ModuleContentPlaceholder/index.jsx | 11 -- .../ModuleContentPlaceholder/style.scss | 8 -- src/webui/components/PackageSidebar/index.jsx | 104 --------------- .../modules/Dependencies/index.jsx | 50 ------- .../modules/Dependencies/style.scss | 13 -- .../PackageSidebar/modules/DistTags/index.jsx | 50 ------- .../modules/DistTags/style.scss | 13 -- .../PackageSidebar/modules/Infos/index.jsx | 40 ------ .../PackageSidebar/modules/Infos/style.scss | 21 --- .../PackageSidebar/modules/LastSync/index.jsx | 43 ------ .../modules/LastSync/style.scss | 13 -- .../Maintainers/MaintainerInfo/index.jsx | 22 ---- .../Maintainers/MaintainerInfo/style.scss | 26 ---- .../modules/Maintainers/index.jsx | 122 ------------------ .../modules/Maintainers/style.scss | 13 -- .../modules/PeerDependencies/index.jsx | 18 --- src/webui/pages/detail/detail.scss | 25 ---- src/webui/pages/detail/index.jsx | 87 ------------- src/webui/router.js | 13 -- .../__snapshots__/dependencies.spec.js.snap | 7 - .../__snapshots__/infos.spec.js.snap | 11 -- .../__snapshots__/lastsync.spec.js.snap | 5 - .../__snapshots__/maintainerInfo.spec.js.snap | 3 - .../__snapshots__/maintainers.spec.js.snap | 3 - .../__snapshots__/module.spec.js.snap | 3 - .../moduleContentPlaceholder.spec.js.snap | 3 - .../__snapshots__/packageSidebar.spec.js.snap | 3 - .../peerDependencies.spec.js.snap | 5 - .../PackageSidebar/dependencies.spec.js | 67 ---------- .../components/PackageSidebar/infos.spec.js | 46 ------- .../PackageSidebar/lastsync.spec.js | 27 ---- .../PackageSidebar/maintainerInfo.spec.js | 30 ----- .../PackageSidebar/maintainers.spec.js | 77 ----------- .../components/PackageSidebar/module.spec.js | 29 ----- .../moduleContentPlaceholder.spec.js | 23 ---- .../PackageSidebar/packageSidebar.spec.js | 35 ----- .../PackageSidebar/peerDependencies.spec.js | 64 --------- 39 files changed, 1182 deletions(-) delete mode 100644 src/webui/components/PackageSidebar/Module/index.jsx delete mode 100644 src/webui/components/PackageSidebar/Module/style.scss delete mode 100644 src/webui/components/PackageSidebar/ModuleContentPlaceholder/index.jsx delete mode 100644 src/webui/components/PackageSidebar/ModuleContentPlaceholder/style.scss delete mode 100644 src/webui/components/PackageSidebar/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/Dependencies/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/Dependencies/style.scss delete mode 100644 src/webui/components/PackageSidebar/modules/DistTags/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/DistTags/style.scss delete mode 100644 src/webui/components/PackageSidebar/modules/Infos/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/Infos/style.scss delete mode 100644 src/webui/components/PackageSidebar/modules/LastSync/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/LastSync/style.scss delete mode 100644 src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/style.scss delete mode 100644 src/webui/components/PackageSidebar/modules/Maintainers/index.jsx delete mode 100644 src/webui/components/PackageSidebar/modules/Maintainers/style.scss delete mode 100644 src/webui/components/PackageSidebar/modules/PeerDependencies/index.jsx delete mode 100644 src/webui/pages/detail/detail.scss delete mode 100644 src/webui/pages/detail/index.jsx delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/__snapshots__/peerDependencies.spec.js.snap delete mode 100644 test/unit/webui/components/PackageSidebar/dependencies.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/infos.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/lastsync.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/maintainers.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/module.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/packageSidebar.spec.js delete mode 100644 test/unit/webui/components/PackageSidebar/peerDependencies.spec.js diff --git a/src/webui/components/PackageSidebar/Module/index.jsx b/src/webui/components/PackageSidebar/Module/index.jsx deleted file mode 100644 index ba2409d29..000000000 --- a/src/webui/components/PackageSidebar/Module/index.jsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -import classes from './style.scss'; - -export default function Module({title, description, children, className}) { - return ( -
-

- {title} - {description && {description}} -

-
- {children} -
-
- ); -} - -Module.propTypes = { - title: PropTypes.string.isRequired, - description: PropTypes.string, - children: PropTypes.any.isRequired, - className: PropTypes.string, -}; diff --git a/src/webui/components/PackageSidebar/Module/style.scss b/src/webui/components/PackageSidebar/Module/style.scss deleted file mode 100644 index 80164c74c..000000000 --- a/src/webui/components/PackageSidebar/Module/style.scss +++ /dev/null @@ -1,24 +0,0 @@ -@import '../../../styles/variables'; -@import '../../../styles/mixins'; - -.module { - - margin-bottom: 10px; - - .moduleTitle { - display: flex; - align-items: flex-end; - font-size: $font-size-lg; - margin: 0 0 10px; - padding: 5px 0; - font-weight: $font-weight-semibold; - @include border-bottom-default($greyGainsboro); - - span { // description - font-size: $font-size-sm; - color: $greyChateau; - margin-left: auto; - font-weight: $font-weight-light; - } - } -} diff --git a/src/webui/components/PackageSidebar/ModuleContentPlaceholder/index.jsx b/src/webui/components/PackageSidebar/ModuleContentPlaceholder/index.jsx deleted file mode 100644 index 4df6744e8..000000000 --- a/src/webui/components/PackageSidebar/ModuleContentPlaceholder/index.jsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -import classes from './style.scss'; - -export default function ModuleContentPlaceholder({text}) { - return

{text}

; -} -ModuleContentPlaceholder.propTypes = { - text: PropTypes.string.isRequired, -}; diff --git a/src/webui/components/PackageSidebar/ModuleContentPlaceholder/style.scss b/src/webui/components/PackageSidebar/ModuleContentPlaceholder/style.scss deleted file mode 100644 index 7980ba7c3..000000000 --- a/src/webui/components/PackageSidebar/ModuleContentPlaceholder/style.scss +++ /dev/null @@ -1,8 +0,0 @@ -@import '../../../styles/variables'; - -.emptyPlaceholder { - text-align: center; - margin: 20px 0; - font-size: $font-size-base; - color: $greyChateau; -} diff --git a/src/webui/components/PackageSidebar/index.jsx b/src/webui/components/PackageSidebar/index.jsx deleted file mode 100644 index 19db61715..000000000 --- a/src/webui/components/PackageSidebar/index.jsx +++ /dev/null @@ -1,104 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import get from 'lodash/get'; -import LastSync from './modules/LastSync'; -import DistTags from './modules/DistTags'; -import Maintainers from './modules/Maintainers'; -import Dependencies from './modules/Dependencies'; -import PeerDependencies from './modules/PeerDependencies'; -import Infos from './modules/Infos'; - -import { - formatLicense, - formatRepository, - getLastUpdatedPackageTime, - getRecentReleases, -} from '../../utils/package'; -import API from '../../utils/api'; -import {DIST_TAGS} from '../../../lib/constants'; - -export default class PackageSidebar extends React.Component { - state = {}; - - static propTypes = { - packageName: PropTypes.string.isRequired, - }; - - constructor(props) { - super(props); - this.loadPackageData = this.loadPackageData.bind(this); - } - - async componentDidMount() { - const { packageName } = this.props; - await this.loadPackageData(packageName); - } - - async loadPackageData(packageName) { - let packageMeta; - - try { - packageMeta = await API.request(`sidebar/${packageName}`, 'GET'); - } catch (err) { - this.setState({ - failed: true, - }); - } - - this.setState({ - packageMeta, - }); - } - - render() { - const { packageMeta } = this.state; - - if (packageMeta) { - const {time, _uplinks} = packageMeta; - - // Infos component - const license = formatLicense(get(packageMeta, 'latest.license', null)); - const repository = formatRepository( - get(packageMeta, 'latest.repository', null) - ); - const homepage = get(packageMeta, 'latest.homepage', null); - - // dist-tags - const distTags = packageMeta[DIST_TAGS]; - - // Lastsync component - const recentReleases = getRecentReleases(time); - const lastUpdated = getLastUpdatedPackageTime(_uplinks); - - // Dependencies component - const dependencies = get(packageMeta, 'latest.dependencies', {}); - const peerDependencies = get(packageMeta, 'latest.peerDependencies', {}); - - // Maintainers component - return ( - - ); - } - return ( - - ); - } -} diff --git a/src/webui/components/PackageSidebar/modules/Dependencies/index.jsx b/src/webui/components/PackageSidebar/modules/Dependencies/index.jsx deleted file mode 100644 index d2bb7783c..000000000 --- a/src/webui/components/PackageSidebar/modules/Dependencies/index.jsx +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import Module from '../../Module'; - -import {getDetailPageURL} from '../../../../utils/url'; -import ModuleContentPlaceholder from '../../ModuleContentPlaceholder'; - -import classes from './style.scss'; - -export const NO_DEPENDENCIES = 'Zero Dependencies!'; -export const DEP_ITEM_CLASS = 'dependency-item'; - -const renderDependenciesList = (dependencies, dependenciesList) => { - return ( - - ); -}; - -const Dependencies = ({dependencies = {}, title = 'Dependencies'}) => { - const dependenciesList = Object.keys(dependencies); - return ( - - {dependenciesList.length > 0 ? ( - renderDependenciesList(dependencies, dependenciesList) - ) : ( - - )} - - ); -}; - -Dependencies.propTypes = { - dependencies: PropTypes.object, - title: PropTypes.string, -}; - -export default Dependencies; diff --git a/src/webui/components/PackageSidebar/modules/Dependencies/style.scss b/src/webui/components/PackageSidebar/modules/Dependencies/style.scss deleted file mode 100644 index 8c8f84aa4..000000000 --- a/src/webui/components/PackageSidebar/modules/Dependencies/style.scss +++ /dev/null @@ -1,13 +0,0 @@ -@import '../../../../styles/variables'; - -.dependenciesModule { - li { - display: inline-block; - font-size: $font-size-sm; - line-height: $line-height-xxs; - - a { - color: inherit; - } - } -} diff --git a/src/webui/components/PackageSidebar/modules/DistTags/index.jsx b/src/webui/components/PackageSidebar/modules/DistTags/index.jsx deleted file mode 100644 index 48f8cd1e8..000000000 --- a/src/webui/components/PackageSidebar/modules/DistTags/index.jsx +++ /dev/null @@ -1,50 +0,0 @@ -import React from 'react'; -import propTypes from 'prop-types'; -import Module from '../../Module'; -import ModuleContentPlaceholder from '../../ModuleContentPlaceholder'; - -import classes from './style.scss'; - -const renderDistTags = (distTags) => { - - const tags = Object.entries(distTags); - - return ( - - ); -}; - -const DistTags = ({distTags = {}}) => { - const hasTags = Object.keys(distTags).length > 0; - - return ( - - {hasTags ? ( - renderDistTags(distTags) - ) : ( - - )} - - ); -}; - -DistTags.propTypes = { - distTags: propTypes.object, -}; - -export default DistTags; diff --git a/src/webui/components/PackageSidebar/modules/DistTags/style.scss b/src/webui/components/PackageSidebar/modules/DistTags/style.scss deleted file mode 100644 index f7823ccd5..000000000 --- a/src/webui/components/PackageSidebar/modules/DistTags/style.scss +++ /dev/null @@ -1,13 +0,0 @@ -@import '../../../../styles/variables'; - -.releasesModule { - li { - display: flex; - font-size: $font-size-sm; - line-height: $line-height-xs; - - span:last-child { - margin-left: auto; - } - } -} diff --git a/src/webui/components/PackageSidebar/modules/Infos/index.jsx b/src/webui/components/PackageSidebar/modules/Infos/index.jsx deleted file mode 100644 index 14733b804..000000000 --- a/src/webui/components/PackageSidebar/modules/Infos/index.jsx +++ /dev/null @@ -1,40 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import Module from '../../Module'; -import ModuleContentPlaceholder from '../../ModuleContentPlaceholder'; - -import classes from './style.scss'; - -const renderSection = (title, url) => ( -
  • - {title} - - {url} - -
  • -); - -const Infos = ({homepage, repository, license}) => { - const showInfo = homepage || repository || license; - return ( - - {showInfo ? ( - ) : } - ); -}; - -Infos.propTypes = { - homepage: PropTypes.string, - repository: PropTypes.string, - license: PropTypes.string, -}; - -export default Infos; diff --git a/src/webui/components/PackageSidebar/modules/Infos/style.scss b/src/webui/components/PackageSidebar/modules/Infos/style.scss deleted file mode 100644 index 13c8aa245..000000000 --- a/src/webui/components/PackageSidebar/modules/Infos/style.scss +++ /dev/null @@ -1,21 +0,0 @@ -@import '../../../../styles/variables'; -@import '../../../../styles/mixins'; - -.infosModule { - li { - display: flex; - font-size: $font-size-sm; - line-height: $line-height-xs; - - a { - color: inherit; - max-width: 150px; - @include ellipsis; - } - - a:last-child, - span:last-child { - margin-left: auto; - } - } -} diff --git a/src/webui/components/PackageSidebar/modules/LastSync/index.jsx b/src/webui/components/PackageSidebar/modules/LastSync/index.jsx deleted file mode 100644 index 3730b8ea4..000000000 --- a/src/webui/components/PackageSidebar/modules/LastSync/index.jsx +++ /dev/null @@ -1,43 +0,0 @@ -import React from 'react'; -import propTypes from 'prop-types'; -import Module from '../../Module'; -import ModuleContentPlaceholder from '../../ModuleContentPlaceholder'; - -import classes from './style.scss'; - -const renderRecentReleases = (recentReleases) => ( - -); - -const LastSync = ({recentReleases = [], lastUpdated = ''}) => { - return ( - - {recentReleases.length ? ( - renderRecentReleases(recentReleases) - ) : ( - - )} - - ); -}; - -LastSync.propTypes = { - recentReleases: propTypes.array, - lastUpdated: propTypes.string, -}; - -export default LastSync; diff --git a/src/webui/components/PackageSidebar/modules/LastSync/style.scss b/src/webui/components/PackageSidebar/modules/LastSync/style.scss deleted file mode 100644 index f7823ccd5..000000000 --- a/src/webui/components/PackageSidebar/modules/LastSync/style.scss +++ /dev/null @@ -1,13 +0,0 @@ -@import '../../../../styles/variables'; - -.releasesModule { - li { - display: flex; - font-size: $font-size-sm; - line-height: $line-height-xs; - - span:last-child { - margin-left: auto; - } - } -} diff --git a/src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/index.jsx b/src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/index.jsx deleted file mode 100644 index 5975e30c1..000000000 --- a/src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/index.jsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -import classes from './style.scss'; - -const MaintainerInfo = ({title, name, avatar}) => { - const avatarDescription = `${title} ${name}'s avatar`; - return ( -
    - {avatarDescription} - {name} -
    - ); -}; - -MaintainerInfo.propTypes = { - title: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, - avatar: PropTypes.string.isRequired, -}; - -export default MaintainerInfo; diff --git a/src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/style.scss b/src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/style.scss deleted file mode 100644 index dc1805d3d..000000000 --- a/src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/style.scss +++ /dev/null @@ -1,26 +0,0 @@ -@import '../../../../../styles/variables'; -@import '../../../../../styles/mixins'; - -.maintainer { - display: flex; - line-height: $line-height-xl; - cursor: default; - - &:not(:last-child) { - margin-bottom: 10px; - } - - img { - width: 30px; - height: 30px; - margin-right: 10px; - border-radius: 100%; - flex-shrink: 0; - } - - span { - font-size: $font-size-sm; - flex-shrink: 1; - @include ellipsis; - } -} diff --git a/src/webui/components/PackageSidebar/modules/Maintainers/index.jsx b/src/webui/components/PackageSidebar/modules/Maintainers/index.jsx deleted file mode 100644 index bbdea2250..000000000 --- a/src/webui/components/PackageSidebar/modules/Maintainers/index.jsx +++ /dev/null @@ -1,122 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import get from 'lodash/get'; -import filter from 'lodash/filter'; -import size from 'lodash/size'; -import has from 'lodash/has'; -import uniqBy from 'lodash/uniqBy'; - -import Module from '../../Module'; -import MaintainerInfo from './MaintainerInfo'; -import ModuleContentPlaceholder from '../../ModuleContentPlaceholder'; - -import classes from './style.scss'; - -const CONTRIBUTORS_TO_SHOW = 5; - -export default class Maintainers extends React.Component { - static propTypes = { - packageMeta: PropTypes.object.isRequired, - }; - - state = {}; - - constructor(props) { - super(props); - this.handleShowAllContributors = this.handleShowAllContributors.bind(this); - } - - get author() { - return get(this, 'props.packageMeta.latest.author'); - } - - get contributors() { - const contributors = get(this, 'props.packageMeta.latest.contributors', {}); - return filter(contributors, (contributor) => { - return ( - contributor.name !== get(this, 'author.name') && - contributor.email !== get(this, 'author.email') - ); - }); - } - - get showAllContributors() { - const { showAllContributors } = this.state; - return showAllContributors || size(this.contributors) <= 5; - } - - get uniqueContributors() { - if (!this.contributors) { - return []; - } - - return uniqBy(this.contributors, (contributor) => contributor.name).slice( - 0, - CONTRIBUTORS_TO_SHOW - ); - } - - handleShowAllContributors() { - this.setState({ - showAllContributors: true, - }); - } - - renderContributors() { - if (!this.contributors) return null; - - return (this.showAllContributors - ? this.contributors - : this.uniqueContributors - ).map((contributor, index) => { - return ( - - ); - }); - } - - renderAuthorAndContributors(author) { - return ( -
    -
      - {author && - author.name && ( - - )} - {this.renderContributors()} -
    - {!this.showAllContributors && ( - - )} -
    - ); - } - - render() { - const contributors = this.renderContributors(); - return ( - - {contributors.length || has(this.author, 'name') ? ( - this.renderAuthorAndContributors(this.author) - ) : ( - - )} - - ); - } -} diff --git a/src/webui/components/PackageSidebar/modules/Maintainers/style.scss b/src/webui/components/PackageSidebar/modules/Maintainers/style.scss deleted file mode 100644 index 62949040e..000000000 --- a/src/webui/components/PackageSidebar/modules/Maintainers/style.scss +++ /dev/null @@ -1,13 +0,0 @@ -@import '../../../../styles/variables'; - -.maintainersModule { - .showAllContributors { - cursor: pointer; - width: 100%; - background: none; - border: none; - font-size: $font-size-sm; - text-align: center; - padding: 10px 0; - } -} diff --git a/src/webui/components/PackageSidebar/modules/PeerDependencies/index.jsx b/src/webui/components/PackageSidebar/modules/PeerDependencies/index.jsx deleted file mode 100644 index 287073f35..000000000 --- a/src/webui/components/PackageSidebar/modules/PeerDependencies/index.jsx +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import Dependencies from '../Dependencies'; - -export const TITLE = 'Peer Dependencies'; - -const PeerDependencies = ({dependencies = {}, title = TITLE}) => { - return ( - - ); -}; - -PeerDependencies.propTypes = { - dependencies: PropTypes.object, - title: PropTypes.string, -}; - -export default PeerDependencies; diff --git a/src/webui/pages/detail/detail.scss b/src/webui/pages/detail/detail.scss deleted file mode 100644 index 849a7f6de..000000000 --- a/src/webui/pages/detail/detail.scss +++ /dev/null @@ -1,25 +0,0 @@ -@import '../../styles/variables'; -@import '../../styles/mixins'; - -.twoColumn { - @include container-size; - display: flex; - - > div { - &:first-child { - flex-shrink: 1; - min-width: 300px; - width: 100%; - } - } - - > aside { - &:last-child { - margin-left: auto; - - padding-left: 15px; - flex-shrink: 0; - width: 285px; - } - } -} diff --git a/src/webui/pages/detail/index.jsx b/src/webui/pages/detail/index.jsx deleted file mode 100644 index bc526a402..000000000 --- a/src/webui/pages/detail/index.jsx +++ /dev/null @@ -1,87 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import isEmpty from 'lodash/isEmpty'; - -import PackageDetail from '../../components/PackageDetail'; -import NotFound from '../../components/NotFound'; -import Spinner from '../../components/Spinner'; -import API from '../../utils/api'; - -import classes from './detail.scss'; -import PackageSidebar from '../../components/PackageSidebar/index'; - -export default class Detail extends Component { - static propTypes = { - match: PropTypes.object, - isUserLoggedIn: PropTypes.bool, - }; - - state = { - readMe: '', - notFound: false, - }; - - getPackageName(props = this.props) { - const params = props.match.params; - return `${(params.scope && '@' + params.scope + '/') || ''}${ - params.package - }`; - } - - get packageName() { - return this.getPackageName(); - } - - async componentDidMount() { - await this.loadPackageInfo(this.packageName); - } - - componentDidUpdate(prevProps) { - const { isUserLoggedIn, match } = this.props; - const condition1 = prevProps.isUserLoggedIn !== isUserLoggedIn; - const condition2 = - prevProps.match.params.package !== match.params.package; - if (condition1 || condition2) { - const packageName = this.getPackageName(this.props); - this.loadPackageInfo(packageName); - } - } - - async loadPackageInfo(packageName) { - this.setState({ - readMe: '', - }); - - try { - const resp = await API.request(`package/readme/${packageName}`, 'GET'); - this.setState({ - readMe: resp, - notFound: false, - }); - } catch (err) { - this.setState({ - notFound: true, - }); - } - } - - render() { - const { notFound, readMe } = this.state; - - if (notFound) { - return ( -
    - -
    - ); - } else if (isEmpty(readMe)) { - return ; - } - return ( -
    - - -
    - ); - } -} diff --git a/src/webui/router.js b/src/webui/router.js index 6f8e5ab62..f7b150384 100644 --- a/src/webui/router.js +++ b/src/webui/router.js @@ -14,7 +14,6 @@ import history from './history'; import Header from './components/Header'; const NotFound = asyncComponent(() => import('./components/NotFound')); -const DetailPackage = asyncComponent(() => import('./pages/detail')); const VersionPackage = asyncComponent(() => import('./pages/version')); const HomePage = asyncComponent(() => import('./pages/home')); @@ -26,8 +25,6 @@ class RouterApp extends Component { {this.renderHeader()} - - @@ -59,16 +56,6 @@ class RouterApp extends Component { ); }; - renderDetailPage = (routerProps: any) => { - return ( - - {function renderConsumerVersionPage({ isUserLoggedIn }) { - return ; - }} - - ); - }; - renderVersionPage = (routerProps: any) => { return ( diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap deleted file mode 100644 index 0e00f4e9b..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/dependencies.spec.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should load dependencies 1`] = `"

    Dependencies

    "`; - -exports[` : should load the package without dependencies 1`] = `"

    Dependencies

    Zero Dependencies!

    "`; - -exports[` : should permit overriding title 1`] = `"

    Package dependencies

    Zero Dependencies!

    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap deleted file mode 100644 index 6530d3698..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/infos.spec.js.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should load the Info component with homepage only 1`] = `""`; - -exports[` : should load the Info component with license only 1`] = `"

    Infos

    • LicenseMIT
    "`; - -exports[` : should load the Info component with props 1`] = `""`; - -exports[` : should load the Info component with repository only 1`] = `""`; - -exports[` : should load the component without props 1`] = `"

    Infos

    Not Available!

    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap deleted file mode 100644 index 680141e45..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/lastsync.spec.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should check the default props condition 1`] = `"

    Last Sync

    Not Available!

    "`; - -exports[` : should load the LastSync component and match snapshot 1`] = `"

    Last Sync2017/12/14, 15:43:52

    • 2.7.12017/12/14, 15:43:27
    • 2.7.02017/12/05, 23:25:06
    • 2.6.62017/11/08, 22:47:16
    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap deleted file mode 100644 index 887561c88..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/maintainerInfo.spec.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should load the component and match with snapshot 1`] = `"
    \\"test-titletest
    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap deleted file mode 100644 index b1f130899..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/maintainers.spec.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should match with the props 1`] = `"

    Maintainers

      \\"AuthorUser NPM
      \\"Contributors030
      \\"ContributorsAlex Vernacchia
      \\"ContributorsAlexander Makarenko
      \\"ContributorsAlexandre-io
      \\"ContributorsAram Drevekenin
    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap deleted file mode 100644 index aa71b4fe2..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/module.spec.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should load module component 1`] = `"

    Test titleTest description

    test children

    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap deleted file mode 100644 index e90f3f755..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/moduleContentPlaceholder.spec.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should load module component 1`] = `"

    Test text

    "`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap deleted file mode 100644 index 714b44321..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/packageSidebar.spec.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` component should load the packageMeta 1`] = `""`; diff --git a/test/unit/webui/components/PackageSidebar/__snapshots__/peerDependencies.spec.js.snap b/test/unit/webui/components/PackageSidebar/__snapshots__/peerDependencies.spec.js.snap deleted file mode 100644 index 7baa15a47..000000000 --- a/test/unit/webui/components/PackageSidebar/__snapshots__/peerDependencies.spec.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` : should load dependencies 1`] = `"

    Peer Dependencies

    "`; - -exports[` : should load the package without dependencies 1`] = `"

    Peer Dependencies

    Zero Dependencies!

    "`; diff --git a/test/unit/webui/components/PackageSidebar/dependencies.spec.js b/test/unit/webui/components/PackageSidebar/dependencies.spec.js deleted file mode 100644 index 7f8911cfa..000000000 --- a/test/unit/webui/components/PackageSidebar/dependencies.spec.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Dependencies component - */ - -import React from 'react'; -import { mount, shallow } from 'enzyme'; -import Dependencies, { - NO_DEPENDENCIES, - DEP_ITEM_CLASS -} from '../../../../../src/webui/components/PackageSidebar/modules/Dependencies/index'; -import ModuleContentPlaceholder from '../../../../../src/webui/components/PackageSidebar/ModuleContentPlaceholder'; - - -describe(' : ', () => { - test('should load dependencies', () => { - const dependencies = { - '@verdaccio/file-locking': '0.0.3', - '@verdaccio/streams': '0.0.2', - JSONStream: '^1.1.1', - 'apache-md5': '^1.1.2', - async: '^2.0.1', - 'body-parser': '^1.15.0', - bunyan: '^1.8.0', - chalk: '^2.0.1', - commander: '^2.11.0', - compression: '1.6.2', - cookies: '^0.7.0', - cors: '^2.8.3', - express: '4.15.3', - global: '^4.3.2', - handlebars: '4.0.5', - 'http-errors': '^1.4.0', - 'js-string-escape': '1.0.1', - 'js-yaml': '^3.6.0', - jsonwebtoken: '^7.4.1', - lockfile: '^1.0.1', - lodash: '4.17.4', - lunr: '^0.7.0', - marked: '0.3.6', - mime: '^1.3.6', - minimatch: '^3.0.2', - mkdirp: '^0.5.1', - pkginfo: '^0.4.0', - request: '^2.72.0', - semver: '^5.1.0', - 'unix-crypt-td-js': '^1.0.0' - }; - const wrapper = shallow(); - - expect(wrapper.find(`.${DEP_ITEM_CLASS}`)).toHaveLength(Object.keys(dependencies).length); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the package without dependencies', () => { - const wrapper = shallow(); - - expect(wrapper.find(ModuleContentPlaceholder).props().text).toBe(NO_DEPENDENCIES); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should permit overriding title', () => { - const wrapper = mount(); - - expect(wrapper.find('h2').text()).toEqual('Package dependencies'); - expect(wrapper.html()).toMatchSnapshot(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/infos.spec.js b/test/unit/webui/components/PackageSidebar/infos.spec.js deleted file mode 100644 index 2962bd511..000000000 --- a/test/unit/webui/components/PackageSidebar/infos.spec.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Infos component - */ - -import React from 'react'; -import { shallow } from 'enzyme'; -import Infos from '../../../../../src/webui/components/PackageSidebar/modules/Infos/index'; - -describe(' : ', () => { - test('should load the component without props', () => { - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the Info component with props', () => { - const props = { - homepage: 'https://www.verdaccio.org', - license: 'MIT', - repository: 'https://github.com/verdaccio/verdaccio' - } - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the Info component with homepage only', () => { - const props = { - homepage: 'https://www.verdaccio.org' - } - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the Info component with license only', () => { - const props = { - license: 'MIT', - } - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the Info component with repository only', () => { - const props = { repository: 'https://github.com/verdaccio/verdaccio' }; - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/lastsync.spec.js b/test/unit/webui/components/PackageSidebar/lastsync.spec.js deleted file mode 100644 index c1015678b..000000000 --- a/test/unit/webui/components/PackageSidebar/lastsync.spec.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * LastSync component - */ - -import React from 'react'; -import { shallow } from 'enzyme'; -import LastSync from '../../../../../src/webui/components/PackageSidebar/modules/LastSync/index'; - -describe(' : ', () => { - test('should check the default props condition', () => { - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the LastSync component and match snapshot', () => { - const props = { - lastUpdated: '2017/12/14, 15:43:52', - recentReleases: [ - { time: '2017/12/14, 15:43:27', version: '2.7.1' }, - { time: '2017/12/05, 23:25:06', version: '2.7.0' }, - { time: '2017/11/08, 22:47:16', version: '2.6.6' } - ] - }; - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js b/test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js deleted file mode 100644 index 395b7eaaa..000000000 --- a/test/unit/webui/components/PackageSidebar/maintainerInfo.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * MaintainerInfo component - */ - -import React from 'react'; -import { shallow } from 'enzyme'; -import MaintainerInfo from '../../../../../src/webui/components/PackageSidebar/modules/Maintainers/MaintainerInfo/index'; - -console.error = jest.fn(); - -describe(' : ', () => { - test('should throw error for required props', () => { - shallow(); - expect(console.error).toHaveBeenCalled(); - }); - - test('should load the component and match with snapshot', () => { - const props = { - title: 'test-title', - name: 'test', - avatar: 'http://xyz.com/profile.jpg' - }; - const wrapper = shallow(); - expect(wrapper.find('.maintainer').prop('title')).toEqual('test'); - expect(wrapper.find('img').prop('src')).toEqual( - 'http://xyz.com/profile.jpg' - ); - expect(wrapper.html()).toMatchSnapshot(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/maintainers.spec.js b/test/unit/webui/components/PackageSidebar/maintainers.spec.js deleted file mode 100644 index f6f69f93a..000000000 --- a/test/unit/webui/components/PackageSidebar/maintainers.spec.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Maintainers component - */ - -import React from 'react'; -import { mount } from 'enzyme'; -import Maintainers from '../../../../../src/webui/components/PackageSidebar/modules/Maintainers/index'; -import { packageMeta } from '../store/packageMeta'; - -describe(' : ', () => { - let wrapper; - let instance; - - beforeEach(() => { - wrapper = mount(); - instance = wrapper.instance(); - }); - - test('should match with the props', () => { - expect(wrapper.props().packageMeta).toEqual(packageMeta); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('author shoule be equal to User NPM', () => { - expect(instance.author).toEqual({ - avatar: - 'https://www.gravatar.com/avatar/a5a236ba477ee98908600c40cda74f4a', - email: 'test@author.local', - name: 'User NPM' - }); - }); - - test('should get all the contributors with false for showAllContributors', () => { - expect(instance.showAllContributors).toBeFalsy(); - }); - - test('should get unique contributors', () => { - const result = [ - { - avatar: - 'https://www.gravatar.com/avatar/4ef03c2bf8d8689527903212d96fb45b', - email: 'test1@test.local', - name: '030' - }, - { - avatar: - 'https://www.gravatar.com/avatar/06975001f7f2be7052bcf978700c6112', - email: 'tes4@test.local', - name: 'Alex Vernacchia' - }, - { - avatar: - 'https://www.gravatar.com/avatar/d9acfc4ed4e49a436738ff26a722dce4', - email: 'test5@test.local', - name: 'Alexander Makarenko' - }, - { - avatar: - 'https://www.gravatar.com/avatar/2e095c7cfd278f72825d0fed6e12e3b1', - email: 'test6@test.local', - name: 'Alexandre-io' - }, - { - avatar: - 'https://www.gravatar.com/avatar/371edff6d79c39bb9e36bde39d41a4b0', - email: 'test7@test.local', - name: 'Aram Drevekenin' - } - ]; - expect(instance.uniqueContributors).toEqual(result); - }); - - test('should click on handleShowAllContributors', () => { - wrapper.find('button').simulate('click'); - expect(wrapper.state('showAllContributors')).toBeTruthy(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/module.spec.js b/test/unit/webui/components/PackageSidebar/module.spec.js deleted file mode 100644 index 0699ff279..000000000 --- a/test/unit/webui/components/PackageSidebar/module.spec.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Module component - */ - -import React from 'react'; -import { shallow } from 'enzyme'; -import Module from '../../../../../src/webui/components/PackageSidebar/Module/index'; - -console.error = jest.fn(); - -describe(' : ', () => { - test('should error for required props', () => { - shallow(); - expect(console.error).toHaveBeenCalled(); - }); - test('should load module component', () => { - const props = { - title: 'Test title', - description: 'Test description', - className: 'module-component' - }; - const wrapper = shallow( - -

    {'test children'}

    -
    - ); - expect(wrapper.html()).toMatchSnapshot(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js b/test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js deleted file mode 100644 index a0b8d2b3b..000000000 --- a/test/unit/webui/components/PackageSidebar/moduleContentPlaceholder.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * ModuleContentPlaceholder component - */ - -import React from 'react'; -import { shallow } from 'enzyme'; -import ModuleContentPlaceholder from '../../../../../src/webui/components/PackageSidebar/ModuleContentPlaceholder/index'; - -console.error = jest.fn(); - -describe(' : ', () => { - test('should error for required props', () => { - shallow(); - expect(console.error).toHaveBeenCalled(); - }); - test('should load module component', () => { - const props = { - text: 'Test text' - }; - const wrapper = shallow(); - expect(wrapper.html()).toMatchSnapshot(); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/packageSidebar.spec.js b/test/unit/webui/components/PackageSidebar/packageSidebar.spec.js deleted file mode 100644 index 205be74bc..000000000 --- a/test/unit/webui/components/PackageSidebar/packageSidebar.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Package Sidebar module - */ - -import React from 'react'; -import { mount } from 'enzyme'; -import PackageSidebar from '../../../../../src/webui/components/PackageSidebar/index'; -import { packageMeta } from '../store/packageMeta'; - -jest.mock('../../../../../src/webui/utils/api', () => ({ - request: require('../__mocks__/api').default.request, -})); - -console.error = jest.fn(); - -describe(' component', () => { - test('should throw error for the required props', () => { - const wrapper = mount(); - const { loadPackageData } = wrapper.instance(); - expect(console.error).toHaveBeenCalled(); - return loadPackageData().catch(response => { - expect(response).toBeUndefined(); - expect(wrapper.state()).toEqual({ failed: true }); - }); - }); - - test('should load the packageMeta', () => { - const wrapper = mount(); - const { loadPackageData } = wrapper.instance(); - expect(wrapper.html()).toMatchSnapshot(); - return loadPackageData('verdaccio').then(response => { - expect(wrapper.state('packageMeta')).toEqual(packageMeta); - }); - }); -}); diff --git a/test/unit/webui/components/PackageSidebar/peerDependencies.spec.js b/test/unit/webui/components/PackageSidebar/peerDependencies.spec.js deleted file mode 100644 index 0ba1a3717..000000000 --- a/test/unit/webui/components/PackageSidebar/peerDependencies.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Dependencies component - */ - -import React from 'react'; -import { mount } from 'enzyme'; -import { - NO_DEPENDENCIES, - DEP_ITEM_CLASS -} from '../../../../../src/webui/components/PackageSidebar/modules/Dependencies/index'; -import PeerDependencies, { - TITLE -} from '../../../../../src/webui/components/PackageSidebar/modules/PeerDependencies/index'; -import ModuleContentPlaceholder from '../../../../../src/webui/components/PackageSidebar/ModuleContentPlaceholder'; - - -describe(' : ', () => { - test('should load dependencies', () => { - const peerDependencies = { - '@verdaccio/file-locking': '0.0.3', - '@verdaccio/streams': '0.0.2', - JSONStream: '^1.1.1', - 'apache-md5': '^1.1.2', - async: '^2.0.1', - 'body-parser': '^1.15.0', - bunyan: '^1.8.0', - chalk: '^2.0.1', - commander: '^2.11.0', - compression: '1.6.2', - cookies: '^0.7.0', - cors: '^2.8.3', - express: '4.15.3', - global: '^4.3.2', - handlebars: '4.0.5', - 'http-errors': '^1.4.0', - 'js-string-escape': '1.0.1', - 'js-yaml': '^3.6.0', - jsonwebtoken: '^7.4.1', - lockfile: '^1.0.1', - lodash: '4.17.4', - lunr: '^0.7.0', - marked: '0.3.6', - mime: '^1.3.6', - minimatch: '^3.0.2', - mkdirp: '^0.5.1', - pkginfo: '^0.4.0', - request: '^2.72.0', - semver: '^5.1.0', - 'unix-crypt-td-js': '^1.0.0' - }; - const wrapper = mount(); - - expect(wrapper.find('h2').text()).toEqual(TITLE); - expect(wrapper.find(`.${DEP_ITEM_CLASS}`)).toHaveLength(Object.keys(peerDependencies).length); - expect(wrapper.html()).toMatchSnapshot(); - }); - - test('should load the package without dependencies', () => { - const wrapper = mount(); - - expect(wrapper.find(ModuleContentPlaceholder).props().text).toBe(NO_DEPENDENCIES); - expect(wrapper.html()).toMatchSnapshot(); - }); -});