exportProfileButton.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import styled from '@emotion/styled';
  2. import {IconDownload} from 'sentry/icons';
  3. import {t} from 'sentry/locale';
  4. import space from 'sentry/styles/space';
  5. import useApi from 'sentry/utils/useApi';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. import useProjects from 'sentry/utils/useProjects';
  8. import Button, {ButtonPropsWithoutAriaLabel} from '../button';
  9. interface ExportProfileButtonProps
  10. extends Omit<ButtonPropsWithoutAriaLabel, 'onClick' | 'children'> {
  11. eventId: string | undefined;
  12. orgId: string | undefined;
  13. projectId: string | undefined;
  14. children?: React.ReactNode;
  15. variant?: 'xs' | 'default';
  16. }
  17. export function ExportProfileButton(props: ExportProfileButtonProps) {
  18. const api = useApi();
  19. const organization = useOrganization();
  20. const project = useProjects().projects.find(p => {
  21. return p.slug === props.projectId;
  22. });
  23. const href = `${api.baseUrl}/projects/${props.orgId}/${props.projectId}/profiling/raw_profiles/${props.eventId}/`;
  24. const download = `${organization.slug}_${
  25. project?.slug ?? props.projectId ?? 'unknown_project'
  26. }_${props.eventId}.profile.json`;
  27. const title = t('Export Profile');
  28. return props.variant === 'xs' ? (
  29. <StyledButtonSmall size="xs" title={title} href={href} download={download} {...props}>
  30. {props.children}
  31. <IconDownload size="xs" />
  32. </StyledButtonSmall>
  33. ) : (
  34. <Button
  35. icon={<IconDownload />}
  36. title={title}
  37. href={href}
  38. download={download}
  39. {...props}
  40. >
  41. {props.children}
  42. </Button>
  43. );
  44. }
  45. const StyledButtonSmall = styled(Button)`
  46. border: none;
  47. background-color: transparent;
  48. box-shadow: none;
  49. transition: none !important;
  50. opacity: 0.5;
  51. padding: ${space(0.5)} ${space(0.5)};
  52. &:hover {
  53. border: none;
  54. background-color: transparent;
  55. box-shadow: none;
  56. }
  57. `;