1
0
mirror of https://github.com/SomboChea/ui synced 2024-09-30 05:17:47 +07:00
verdaccio-ui/src/webui/components/Engines/index.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
* @prettier
*/
import React, { Component } from 'react';
2019-03-28 05:39:06 +07:00
import Avatar from '@material-ui/core/Avatar/index';
import Grid from '@material-ui/core/Grid/index';
import List from '@material-ui/core/List/index';
import ListItemText from '@material-ui/core/ListItemText/index';
import { DetailContextConsumer } from '../../pages/version/index';
import { Heading, EngineListItem } from './styles';
import node from './img/node.png';
import npm from '../Install/img/npm.svg';
2019-03-28 05:39:06 +07:00
const ICONS = {
'node-JS': <Avatar src={node} />,
'NPM-version': <Avatar src={npm} />,
};
2019-03-28 05:39:06 +07:00
class Engine extends Component {
render() {
return (
<DetailContextConsumer>
{context => {
2019-03-28 05:39:06 +07:00
return this.renderEngine(context);
}}
</DetailContextConsumer>
);
}
2019-03-28 05:39:06 +07:00
renderEngine = ({ packageMeta }) => {
2019-03-28 05:39:06 +07:00
const { engines } = packageMeta.latest;
if (!engines) {
return null;
}
const engineDict = {
'node-JS': engines.node,
'NPM-version': engines.npm,
};
2019-03-28 05:39:06 +07:00
const items = Object.keys(engineDict).reduce((markup, text, key) => {
const heading = engineDict[text];
if (heading) {
2019-03-28 05:39:06 +07:00
markup.push(
<Grid item={true} key={key} xs={6}>
2019-03-28 05:39:06 +07:00
{this.renderListItems(heading, text)}
</Grid>
);
}
return markup;
}, []);
if (items.length < 1) {
return null;
}
return <Grid container={true}>{items}</Grid>;
};
2019-03-28 05:39:06 +07:00
renderListItems = (heading, text) => {
return (
<List subheader={<Heading variant={'subheading'}>{text.split('-').join(' ')}</Heading>}>
2019-03-28 05:39:06 +07:00
<EngineListItem>
{ICONS[text]}
2019-03-28 05:39:06 +07:00
<ListItemText primary={heading} />
</EngineListItem>
</List>
);
};
2019-03-28 05:39:06 +07:00
}
export default Engine;