shortIdBreadcrumb.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import styled from '@emotion/styled';
  2. import {Chevron} from 'sentry/components/chevron';
  3. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import ShortId from 'sentry/components/shortId';
  6. import {Tooltip} from 'sentry/components/tooltip';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import type {Group} from 'sentry/types/group';
  10. import type {Organization} from 'sentry/types/organization';
  11. import type {Project} from 'sentry/types/project';
  12. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  13. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  14. interface ShortIdBreadcrumbProps {
  15. group: Group;
  16. organization: Organization;
  17. project: Project;
  18. }
  19. export function ShortIdBreadcrumb({
  20. organization,
  21. project,
  22. group,
  23. }: ShortIdBreadcrumbProps) {
  24. const {onClick: handleCopyShortId} = useCopyToClipboard({
  25. text: group.shortId,
  26. successMessage: t('Copied Short-ID to clipboard'),
  27. });
  28. const issueUrl =
  29. window.location.origin +
  30. normalizeUrl(`/organizations/${organization.slug}/issues/${group.id}/`);
  31. const {onClick: handleCopyUrl} = useCopyToClipboard({
  32. text: issueUrl,
  33. successMessage: t('Copied Issue URL to clipboard'),
  34. });
  35. const {onClick: handleCopyMarkdown} = useCopyToClipboard({
  36. text: `[${group.shortId}](${issueUrl})`,
  37. successMessage: t('Copied Markdown Issue Link to clipboard'),
  38. });
  39. if (!group.shortId) {
  40. return null;
  41. }
  42. return (
  43. <Wrapper>
  44. <ProjectBadge
  45. project={project}
  46. avatarSize={16}
  47. hideName
  48. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  49. />
  50. <ShortIdCopyable>
  51. <Tooltip
  52. title={t(
  53. 'This identifier is unique across your organization, and can be used to reference an issue in various places, like commit messages.'
  54. )}
  55. position="bottom"
  56. delay={1000}
  57. >
  58. <StyledShortId shortId={group.shortId} />
  59. </Tooltip>
  60. <DropdownMenu
  61. triggerProps={{
  62. 'aria-label': t('Issue copy actions'),
  63. icon: <Chevron direction="down" />,
  64. size: 'zero',
  65. borderless: true,
  66. showChevron: false,
  67. }}
  68. position="bottom"
  69. size="xs"
  70. items={[
  71. {
  72. key: 'copy-url',
  73. label: t('Copy Issue URL'),
  74. onAction: handleCopyUrl,
  75. },
  76. {
  77. key: 'copy-short-id',
  78. label: t('Copy Short-ID'),
  79. onAction: handleCopyShortId,
  80. },
  81. {
  82. key: 'copy-markdown-link',
  83. label: t('Copy Markdown Link'),
  84. onAction: handleCopyMarkdown,
  85. },
  86. ]}
  87. />
  88. </ShortIdCopyable>
  89. </Wrapper>
  90. );
  91. }
  92. const Wrapper = styled('div')`
  93. display: flex;
  94. gap: ${space(1)};
  95. align-items: center;
  96. `;
  97. const StyledShortId = styled(ShortId)`
  98. font-family: ${p => p.theme.text.family};
  99. font-size: ${p => p.theme.fontSizeMedium};
  100. line-height: 1;
  101. `;
  102. const ShortIdCopyable = styled('div')`
  103. display: flex;
  104. gap: ${space(0.25)};
  105. align-items: center;
  106. button[aria-haspopup] {
  107. display: block;
  108. opacity: 0;
  109. transition: opacity 50ms linear;
  110. }
  111. &:hover button[aria-haspopup],
  112. button[aria-expanded='true'],
  113. button[aria-haspopup]:focus-visible {
  114. opacity: 1;
  115. }
  116. `;