1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-05-18 09:21:37 +07:00
verdaccio-ui/src/components/Versions/Versions.tsx
Juan Picado @jotadeveloper 67d7188cf5
feat: update material-ui@4.x (#123)
* chore: update material-ui@4.x

* test: update test for ActionBar and TestField

* chore: add types

* chore: update types

* test: update test for Author

* chore: fixed bunch of unit test

* chore: remove unused import

* chore: remove comments

* chore: replace shallow my mount

* chore: update git hooks

* chore: fix styles

* chore: update dependencies

* chore: remove types material-ui
2019-08-31 02:02:46 -07:00

63 lines
2.0 KiB
TypeScript

import React, { ReactElement } from 'react';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import { DetailContextConsumer } from '../../pages/Version';
import { formatDateDistance } from '../../utils/package';
import { DIST_TAGS } from '../../../lib/constants';
import { Heading, Spacer, ListItemText } from './styles';
const NOT_AVAILABLE = 'Not available';
class Versions extends React.PureComponent {
public render(): ReactElement<HTMLDivElement> {
return (
<DetailContextConsumer>
{context => {
return context && context.packageMeta && this.renderContent(context.packageMeta);
}}
</DetailContextConsumer>
);
}
public renderPackageList = (packages: {}, isVersion: boolean = false, timeMap: Record<string, {}> = {}): ReactElement<HTMLDivElement> => {
return (
<List>
{Object.keys(packages)
.reverse()
.map(version => (
<ListItem className="version-item" key={version}>
<ListItemText>{version}</ListItemText>
<Spacer />
{isVersion && <ListItemText>{timeMap[version] ? `${formatDateDistance(timeMap[version])} ago` : NOT_AVAILABLE}</ListItemText>}
{isVersion === false && <ListItemText>{packages[version]}</ListItemText>}
</ListItem>
))}
</List>
);
};
public renderContent(packageMeta): ReactElement<HTMLDivElement> {
const { versions = {}, time: timeMap = {}, [DIST_TAGS]: distTags = {} } = packageMeta;
return (
<>
{distTags && (
<>
<Heading variant="subtitle1">{'Current Tags'}</Heading>
{this.renderPackageList(distTags, false, timeMap)}
</>
)}
{versions && (
<>
<Heading variant="subtitle1">{'Version History'}</Heading>
{this.renderPackageList(versions, true, timeMap)}
</>
)}
</>
);
}
}
export default Versions;