2019-06-20 19:37:28 +07:00
|
|
|
import React, { Component, ReactElement } from 'react';
|
2019-04-09 03:29:20 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
|
|
import Grid from '@material-ui/core/Grid';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
|
2019-03-28 05:39:06 +07:00
|
|
|
import { Heading, EngineListItem } from './styles';
|
2019-06-20 19:37:28 +07:00
|
|
|
// @ts-ignore
|
2019-03-28 05:39:06 +07:00
|
|
|
import node from './img/node.png';
|
2019-04-09 03:29:20 +07:00
|
|
|
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-04-09 03:29:20 +07:00
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
class Engine extends Component {
|
2019-06-20 19:37:28 +07:00
|
|
|
public render(): ReactElement<HTMLElement> {
|
2019-03-28 05:39:06 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-04-09 03:29:20 +07:00
|
|
|
{context => {
|
2019-06-20 19:37:28 +07:00
|
|
|
return this.renderEngine(context as VersionPageConsumerProps);
|
2019-03-28 05:39:06 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
2019-04-09 03:29:20 +07:00
|
|
|
}
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
private renderEngine = ({ packageMeta }): ReactElement<HTMLElement> | null => {
|
2019-03-28 05:39:06 +07:00
|
|
|
const { engines } = packageMeta.latest;
|
|
|
|
if (!engines) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const engineDict = {
|
|
|
|
'node-JS': engines.node,
|
2019-04-09 03:29:20 +07:00
|
|
|
'NPM-version': engines.npm,
|
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
const accumulator: React.ReactNode[] = [];
|
2019-03-28 05:39:06 +07:00
|
|
|
const items = Object.keys(engineDict).reduce((markup, text, key) => {
|
2019-04-09 03:29:20 +07:00
|
|
|
const heading = engineDict[text];
|
|
|
|
if (heading) {
|
2019-03-28 05:39:06 +07:00
|
|
|
markup.push(
|
2019-04-09 03:29:20 +07:00
|
|
|
<Grid item={true} key={key} xs={6}>
|
2019-03-28 05:39:06 +07:00
|
|
|
{this.renderListItems(heading, text)}
|
|
|
|
</Grid>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return markup;
|
2019-06-20 19:37:28 +07:00
|
|
|
}, accumulator);
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
if (items.length < 1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-09 03:29:20 +07:00
|
|
|
return <Grid container={true}>{items}</Grid>;
|
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
private renderListItems = (heading, text) => {
|
2019-03-28 05:39:06 +07:00
|
|
|
return (
|
2019-04-09 03:29:20 +07:00
|
|
|
<List subheader={<Heading variant={'subheading'}>{text.split('-').join(' ')}</Heading>}>
|
2019-03-28 05:39:06 +07:00
|
|
|
<EngineListItem>
|
2019-04-09 03:29:20 +07:00
|
|
|
{ICONS[text]}
|
2019-03-28 05:39:06 +07:00
|
|
|
<ListItemText primary={heading} />
|
|
|
|
</EngineListItem>
|
|
|
|
</List>
|
|
|
|
);
|
2019-04-09 03:29:20 +07:00
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Engine;
|