mirror of
https://github.com/SomboChea/ui
synced 2024-11-05 22:24:27 +07:00
1d705da38c
* refactor: replaced classes by func comp * fix: fixed space margin * refactor: changed display logic * fix: fixed types * fix: fixed Version test * fix: fixed version style
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import React, { useContext } from 'react';
|
|
|
|
import { DetailContext } from '../../pages/Version';
|
|
|
|
import { Heading } from './styles';
|
|
|
|
import VersionsTagList from './VersionsTagList';
|
|
import VersionsHistoryList from './VersionsHistoryList';
|
|
|
|
import { DIST_TAGS } from '../../../lib/constants';
|
|
|
|
export const NOT_AVAILABLE = 'Not available';
|
|
export const LABEL_CURRENT_TAGS = 'Current Tags';
|
|
export const LABEL_VERSION_HISTORY = 'Version History';
|
|
|
|
const Versions: React.FC = () => {
|
|
const detailContext = useContext(DetailContext);
|
|
|
|
const { packageMeta, packageName } = detailContext;
|
|
|
|
if (!packageMeta) {
|
|
return null;
|
|
}
|
|
|
|
// @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} />
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Versions;
|