Skip to content

Commit

Permalink
feat: add dist-tags on ui
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpicado committed Jan 12, 2019
1 parent 6dbe9e9 commit 4f4720d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
*.yaml
Dockerfile
*.rpi
*.scss
4 changes: 2 additions & 2 deletions src/api/web/endpoint/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import _ from 'lodash';
import { addScope, addGravatarSupport, deleteProperties, sortByName, parseReadme } from '../../../lib/utils';
import { allow } from '../../middleware';
import { DIST_TAGS, HTTP_STATUS } from '../../../lib/constants';
import { DIST_TAGS, HEADER_TYPE, HEADERS, HTTP_STATUS } from '../../../lib/constants';
import type { Router } from 'express';
import type { IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer, IStorageHandler, $SidebarPackage } from '../../../../types';

Expand Down Expand Up @@ -67,7 +67,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth)
return next(err);
}

res.set('Content-Type', 'text/plain');
res.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.TEXT_PLAIN);
next(parseReadme(info.name, info.readme));
},
});
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const csrPem = 'verdaccio-csr.pem';
export const HEADERS = {
JSON: 'application/json',
CONTENT_TYPE: 'Content-type',
TEXT_PLAIN: 'text/plain',
FORWARDED_PROTO: 'X-Forwarded-Proto',
ETAG: 'ETag',
JSON_CHARSET: 'application/json; charset=utf-8',
Expand Down
8 changes: 7 additions & 1 deletion src/webui/components/PackageSidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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';
Expand All @@ -14,6 +15,7 @@ import {
getRecentReleases,
} from '../../utils/package';
import API from '../../utils/api';
import {DIST_TAGS} from '../../../lib/constants';

export default class PackageSidebar extends React.Component {
state = {};
Expand Down Expand Up @@ -61,6 +63,9 @@ export default class PackageSidebar extends React.Component {
);
const homepage = get(packageMeta, 'latest.homepage', null);

// dist-tags
const distTags = packageMeta[DIST_TAGS];

// Lastsync component
const recentReleases = getRecentReleases(time);
const lastUpdated = getLastUpdatedPackageTime(_uplinks);
Expand All @@ -70,14 +75,15 @@ export default class PackageSidebar extends React.Component {
const peerDependencies = get(packageMeta, 'latest.peerDependencies', {});

// Maintainers component
return (
return (
<aside className={'sidebar-info'}>
{time && (
<LastSync
lastUpdated={lastUpdated}
recentReleases={recentReleases}
/>
)}
<DistTags distTags={distTags} />
<Infos
homepage={homepage}
license={license}
Expand Down
50 changes: 50 additions & 0 deletions src/webui/components/PackageSidebar/modules/DistTags/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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 (
<ul>
{tags.map((tagItem) => {
const [tag, version] = tagItem;

return (
<li className={'dist-tag-item'} key={tag}>
<span>{tag}</span>
<span>{version}</span>
</li>
);
})}
</ul>
);
};

const DistTags = ({distTags = {}}) => {
const hasTags = Object.keys(distTags).length > 0;

return (
<Module
className={classes.releasesModule}
description={''}
title={'Dist-Tags'}
>
{hasTags ? (
renderDistTags(distTags)
) : (
<ModuleContentPlaceholder text={'Not Available!'} />
)}
</Module>
);
};

DistTags.propTypes = {
distTags: propTypes.array,
};

export default DistTags;
13 changes: 13 additions & 0 deletions src/webui/components/PackageSidebar/modules/DistTags/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import '../../../../styles/variables';

.releasesModule {
li {
display: flex;
font-size: $font-size-sm;
line-height: $line-height-xs;

span:last-child {
margin-left: auto;
}
}
}

0 comments on commit 4f4720d

Please sign in to comment.