1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-24 21:15:51 +01:00

feat: display publication time on sidebar (#3408)

- Show the publication time next to the version on the sidebar
- Bonus: display the full date and time on hover
This commit is contained in:
Marc Bernard 2022-09-30 13:53:46 -04:00 committed by GitHub
parent 0783eeec1e
commit 6ad13de884
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 5 deletions

@ -0,0 +1,5 @@
---
'@verdaccio/ui-theme': patch
---
feat: Display publication time on sidebar

@ -96,7 +96,8 @@
"sidebar": { "sidebar": {
"detail": { "detail": {
"latest-version": "Latest v{{version}}", "latest-version": "Latest v{{version}}",
"version": "v{{version}}" "version": "v{{version}}",
"published": "Published"
}, },
"installation": { "installation": {
"title": "Installation", "title": "Installation",

@ -2,7 +2,7 @@ import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem'; import ListItem from '@mui/material/ListItem';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { formatDateDistance } from 'verdaccio-ui/utils/package'; import { formatDate, formatDateDistance } from 'verdaccio-ui/utils/package';
import { Time, Versions } from '../../../../../types/packageMeta'; import { Time, Versions } from '../../../../../types/packageMeta';
import { ListItemText, Spacer, StyledLink } from './styles'; import { ListItemText, Spacer, StyledLink } from './styles';
@ -26,7 +26,7 @@ const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) =
<ListItemText>{version}</ListItemText> <ListItemText>{version}</ListItemText>
</StyledLink> </StyledLink>
<Spacer /> <Spacer />
<ListItemText> <ListItemText title={formatDate(time[version])}>
{time[version] ? formatDateDistance(time[version]) : t('versions.not-available')} {time[version] ? formatDateDistance(time[version]) : t('versions.not-available')}
</ListItemText> </ListItemText>
</ListItem> </ListItem>

@ -32,6 +32,8 @@ const DetailSidebar: React.FC = () => {
const detailContext = useContext(DetailContext); const detailContext = useContext(DetailContext);
const { packageMeta, packageName, packageVersion } = detailContext; const { packageMeta, packageName, packageVersion } = detailContext;
const { configOptions } = useConfig(); const { configOptions } = useConfig();
const version = packageVersion || packageMeta?.latest.version || '';
const time = packageMeta?.time ? packageMeta.time[version] : '';
if (!packageMeta || !packageName) { if (!packageMeta || !packageName) {
return null; return null;
@ -45,7 +47,8 @@ const DetailSidebar: React.FC = () => {
isLatest={typeof packageVersion === 'undefined'} isLatest={typeof packageVersion === 'undefined'}
moduleType={getModuleType(packageMeta)} moduleType={getModuleType(packageMeta)}
packageName={packageName} packageName={packageName}
version={packageVersion || packageMeta.latest.version} time={time}
version={version}
/> />
<ActionBar <ActionBar
showDownloadTarball={configOptions.showDownloadTarball} showDownloadTarball={configOptions.showDownloadTarball}

@ -6,6 +6,7 @@ import { ModuleType } from 'types/packageMeta';
import Heading from 'verdaccio-ui/components/Heading'; import Heading from 'verdaccio-ui/components/Heading';
import { CommonJS, ES6Modules, TypeScript } from 'verdaccio-ui/components/Icons'; import { CommonJS, ES6Modules, TypeScript } from 'verdaccio-ui/components/Icons';
import { Theme } from 'verdaccio-ui/design-tokens/theme'; import { Theme } from 'verdaccio-ui/design-tokens/theme';
import { formatDate, formatDateDistance } from 'verdaccio-ui/utils/package';
interface Props { interface Props {
packageName: string; packageName: string;
@ -14,6 +15,7 @@ interface Props {
isLatest: boolean; isLatest: boolean;
hasTypes?: boolean; hasTypes?: boolean;
moduleType: ModuleType | void; moduleType: ModuleType | void;
time: string;
} }
const ModuleJS: React.FC<{ module: ModuleType | void }> = ({ module }) => { const ModuleJS: React.FC<{ module: ModuleType | void }> = ({ module }) => {
@ -33,6 +35,7 @@ const DetailSidebarTitle: React.FC<Props> = ({
isLatest, isLatest,
hasTypes, hasTypes,
moduleType, moduleType,
time,
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
@ -47,10 +50,13 @@ const DetailSidebarTitle: React.FC<Props> = ({
</TitleWrapper> </TitleWrapper>
</StyledHeading> </StyledHeading>
{description && <div>{description}</div>} {description && <div>{description}</div>}
<StyledBoxVersion> <StyledBoxVersion title={formatDate(time)}>
{isLatest {isLatest
? t('sidebar.detail.latest-version', { version }) ? t('sidebar.detail.latest-version', { version })
: t('sidebar.detail.version', { version })} : t('sidebar.detail.version', { version })}
{time
? ' - ' + t('sidebar.detail.published') + ' ' + formatDateDistance(time)
: t('versions.not-available')}
</StyledBoxVersion> </StyledBoxVersion>
</Box> </Box>
); );