2019-06-20 19:37:28 +07:00
|
|
|
import React, { Component, ReactElement } from 'react';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version';
|
2019-10-06 23:30:05 +07:00
|
|
|
import Avatar from '../../muiComponents/Avatar';
|
2019-10-13 03:26:56 +07:00
|
|
|
import List from '../../muiComponents/List';
|
2019-10-08 03:19:18 +07:00
|
|
|
import npm from '../Install/img/npm.svg';
|
2019-10-31 14:12:18 +07:00
|
|
|
import ListItemText from '../../muiComponents/ListItemText';
|
|
|
|
import Grid from '../../muiComponents/Grid';
|
2019-10-06 23:30:05 +07:00
|
|
|
|
2019-10-13 02:41:42 +07:00
|
|
|
import { StyledText, 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';
|
|
|
|
|
|
|
|
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-10-11 03:20:05 +07:00
|
|
|
private renderListItems = (heading: string, text: string) => {
|
2019-03-28 05:39:06 +07:00
|
|
|
return (
|
2019-10-13 02:41:42 +07:00
|
|
|
<List subheader={<StyledText variant={'subtitle1'}>{text.split('-').join(' ')}</StyledText>}>
|
2019-08-31 16:02:46 +07:00
|
|
|
<EngineListItem button={true}>
|
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;
|