1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-26 21:15:32 +07:00
verdaccio-ui/src/webui/components/ActionBar/index.js

86 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-03-28 05:39:06 +07:00
/**
* @prettier
*/
import React, { Component } from 'react';
import BugReportIcon from '@material-ui/icons/BugReport';
import DownloadIcon from '@material-ui/icons/CloudDownload';
2019-03-28 05:39:06 +07:00
import HomeIcon from '@material-ui/icons/Home';
import List from '@material-ui/core/List/index';
2019-03-28 05:39:06 +07:00
import Tooltip from '@material-ui/core/Tooltip/index';
import { DetailContextConsumer } from '../../pages/version/index';
2019-03-28 05:39:06 +07:00
import { Fab, ActionListItem } from './styles';
import { isURL } from '../../utils/url';
2019-03-28 05:39:06 +07:00
const ACTIONS = {
homepage: {
icon: <HomeIcon />,
title: 'Visit homepage',
},
issue: {
icon: <BugReportIcon />,
title: 'Open an issue',
},
tarball: {
icon: <DownloadIcon />,
title: 'Download tarball',
},
};
class ActionBar extends Component<any, any> {
render() {
return (
<DetailContextConsumer>
{context => {
return this.renderActionBar(context);
}}
</DetailContextConsumer>
);
}
renderIconsWithLink(link, component) {
return (
<a href={link} target={'_blank'}>
2019-03-28 05:39:06 +07:00
{component}
</a>
);
}
renderActionBarListItems = packageMeta => {
const { latest: { bugs: { url: issue } = {}, homepage, dist: { tarball } = {} } = {} } = packageMeta;
2019-03-28 05:39:06 +07:00
const actionsMap = {
homepage,
issue,
tarball,
};
const renderList = Object.keys(actionsMap).reduce((component, value, key) => {
const link = actionsMap[value];
if (link && isURL(link)) {
const fab = <Fab size={'small'}>{ACTIONS[value]['icon']}</Fab>;
2019-03-28 05:39:06 +07:00
component.push(
<Tooltip key={key} title={ACTIONS[value]['title']}>
{this.renderIconsWithLink(link, fab)}
</Tooltip>
);
}
return component;
}, []);
return (
<>
<ActionListItem alignItems={'flex-start'}>{renderList}</ActionListItem>
2019-03-28 05:39:06 +07:00
</>
);
};
renderActionBar = ({ packageMeta = {} }) => {
return <List>{this.renderActionBarListItems(packageMeta)}</List>;
2019-03-28 05:39:06 +07:00
};
}
export default ActionBar;