exportProfileButton.tsx 1.8 KB

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