2019-10-03 15:27:08 +07:00
|
|
|
import React, { useContext } from 'react';
|
2020-03-08 22:45:07 +07:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2019-08-25 19:34:27 +07:00
|
|
|
|
2019-10-03 15:27:08 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
2019-10-08 03:19:18 +07:00
|
|
|
import { DIST_TAGS } from '../../../lib/constants';
|
2019-10-03 15:27:08 +07:00
|
|
|
|
2019-10-13 02:41:42 +07:00
|
|
|
import { StyledText } from './styles';
|
2019-10-03 15:27:08 +07:00
|
|
|
import VersionsTagList from './VersionsTagList';
|
|
|
|
import VersionsHistoryList from './VersionsHistoryList';
|
|
|
|
const Versions: React.FC = () => {
|
|
|
|
const detailContext = useContext(DetailContext);
|
2020-03-08 22:45:07 +07:00
|
|
|
const { t } = useTranslation();
|
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
|
|
|
const { versions = {}, time = {}, [DIST_TAGS]: distTags = {} } = packageMeta;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{distTags && Object.keys(distTags).length > 0 && (
|
|
|
|
<>
|
2020-03-08 22:45:07 +07:00
|
|
|
<StyledText variant="subtitle1">{t('versions.current-tags')}</StyledText>
|
2019-10-03 15:27:08 +07:00
|
|
|
<VersionsTagList tags={distTags} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{versions && Object.keys(versions).length > 0 && packageName && (
|
|
|
|
<>
|
2020-03-08 22:45:07 +07:00
|
|
|
<StyledText variant="subtitle1">{t('versions.version-history')}</StyledText>
|
2019-10-03 15:27:08 +07:00
|
|
|
<VersionsHistoryList packageName={packageName} time={time} versions={versions} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
export default Versions;
|