2019-12-03 15:44:44 +07:00
|
|
|
import React from 'react';
|
|
|
|
import styled from '@emotion/styled';
|
|
|
|
import BugReportIcon from '@material-ui/icons/BugReport';
|
|
|
|
import DownloadIcon from '@material-ui/icons/CloudDownload';
|
|
|
|
import HomeIcon from '@material-ui/icons/Home';
|
2020-03-08 22:45:07 +07:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2019-12-03 15:44:44 +07:00
|
|
|
|
|
|
|
import Tooltip from '../../muiComponents/Tooltip';
|
|
|
|
import Link from '../Link';
|
|
|
|
import FloatingActionButton from '../../muiComponents/FloatingActionButton';
|
|
|
|
import { Theme } from '../../design-tokens/theme';
|
|
|
|
|
|
|
|
import downloadTarball from './download-tarball';
|
|
|
|
|
|
|
|
export const Fab = styled(FloatingActionButton)<{ theme?: Theme }>(props => ({
|
|
|
|
backgroundColor: props.theme && props.theme.palette.primary.main,
|
|
|
|
color: props.theme && props.theme.palette.white,
|
|
|
|
marginRight: 10,
|
|
|
|
}));
|
|
|
|
|
|
|
|
type ActionType = 'VISIT_HOMEPAGE' | 'OPEN_AN_ISSUE' | 'DOWNLOAD_TARBALL';
|
|
|
|
|
|
|
|
export interface ActionBarActionProps {
|
|
|
|
type: ActionType;
|
|
|
|
link: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eslint-disable react/jsx-no-bind */
|
|
|
|
const ActionBarAction: React.FC<ActionBarActionProps> = ({ type, link }) => {
|
2020-03-08 22:45:07 +07:00
|
|
|
const { t } = useTranslation();
|
2019-12-03 15:44:44 +07:00
|
|
|
switch (type) {
|
|
|
|
case 'VISIT_HOMEPAGE':
|
|
|
|
return (
|
2020-03-08 22:45:07 +07:00
|
|
|
<Tooltip title={t('action-bar-action.visit-home-page')}>
|
2019-12-03 15:44:44 +07:00
|
|
|
<Link external={true} to={link}>
|
|
|
|
<Fab size="small">
|
|
|
|
<HomeIcon />
|
|
|
|
</Fab>
|
|
|
|
</Link>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
case 'OPEN_AN_ISSUE':
|
|
|
|
return (
|
2020-03-08 22:45:07 +07:00
|
|
|
<Tooltip title={t('action-bar-action.open-an-issue')}>
|
2019-12-03 15:44:44 +07:00
|
|
|
<Link external={true} to={link}>
|
|
|
|
<Fab size="small">
|
|
|
|
<BugReportIcon />
|
|
|
|
</Fab>
|
|
|
|
</Link>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
case 'DOWNLOAD_TARBALL':
|
|
|
|
return (
|
2020-03-08 22:45:07 +07:00
|
|
|
<Tooltip title={t('action-bar-action.download-tarball')}>
|
2019-12-03 15:44:44 +07:00
|
|
|
<Fab data-testid="download-tarball-btn" onClick={downloadTarball(link)} size="small">
|
|
|
|
<DownloadIcon />
|
|
|
|
</Fab>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ActionBarAction;
|