2019-10-03 15:27:08 +07:00
|
|
|
import React, { useContext } from 'react';
|
2019-08-25 19:34:27 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
|
|
|
|
|
|
|
import { Heading } from './styles';
|
2019-09-01 18:09:23 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
import VersionsTagList from './VersionsTagList';
|
|
|
|
import VersionsHistoryList from './VersionsHistoryList';
|
|
|
|
|
|
|
|
import { DIST_TAGS } from '../../../lib/constants';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
export const NOT_AVAILABLE = 'Not available';
|
|
|
|
export const LABEL_CURRENT_TAGS = 'Current Tags';
|
|
|
|
export const LABEL_VERSION_HISTORY = 'Version History';
|
2019-04-28 18:15:45 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
const Versions: React.FC = () => {
|
|
|
|
const detailContext = useContext(DetailContext);
|
2019-09-01 18:09:23 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
const { packageMeta, packageName } = detailContext;
|
2019-09-01 18:09:23 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
if (!packageMeta) {
|
|
|
|
return null;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
// @ts-ignore - Property 'dist-tags' does not exist on type 'PackageMetaInterface'
|
|
|
|
const { versions = {}, time = {}, [DIST_TAGS]: distTags = {} } = packageMeta;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{distTags && Object.keys(distTags).length > 0 && (
|
|
|
|
<>
|
|
|
|
<Heading variant="subtitle1">{LABEL_CURRENT_TAGS}</Heading>
|
|
|
|
<VersionsTagList tags={distTags} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{versions && Object.keys(versions).length > 0 && packageName && (
|
|
|
|
<>
|
|
|
|
<Heading variant="subtitle1">{LABEL_VERSION_HISTORY}</Heading>
|
|
|
|
<VersionsHistoryList packageName={packageName} time={time} versions={versions} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
export default Versions;
|