shortIdBreadcrumb.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. className="help-link"
  53. title={t(
  54. 'This identifier is unique across your organization, and can be used to reference an issue in various places, like commit messages.'
  55. )}
  56. position="bottom"
  57. delay={1000}
  58. >
  59. <StyledShortId shortId={group.shortId} />
  60. </Tooltip>
  61. <DropdownMenu
  62. triggerProps={{
  63. 'aria-label': t('Short-ID copy actions'),
  64. icon: <Chevron direction="down" />,
  65. size: 'zero',
  66. borderless: true,
  67. showChevron: false,
  68. }}
  69. position="bottom"
  70. size="xs"
  71. items={[
  72. {
  73. key: 'copy-url',
  74. label: t('Copy Issue URL'),
  75. onAction: handleCopyUrl,
  76. },
  77. {
  78. key: 'copy-short-id',
  79. label: t('Copy Short-ID'),
  80. onAction: handleCopyShortId,
  81. },
  82. {
  83. key: 'copy-markdown-link',
  84. label: t('Copy Markdown Link'),
  85. onAction: handleCopyMarkdown,
  86. },
  87. ]}
  88. />
  89. </ShortIdCopyable>
  90. </Wrapper>
  91. );
  92. }
  93. const Wrapper = styled('div')`
  94. display: flex;
  95. gap: ${space(1)};
  96. align-items: center;
  97. `;
  98. const StyledShortId = styled(ShortId)`
  99. font-family: ${p => p.theme.text.family};
  100. font-size: ${p => p.theme.fontSizeMedium};
  101. line-height: 1;
  102. `;
  103. const ShortIdCopyable = styled('div')`
  104. display: flex;
  105. gap: ${space(0.25)};
  106. align-items: center;
  107. button[aria-haspopup] {
  108. display: block;
  109. opacity: 0;
  110. transition: opacity 50ms linear;
  111. }
  112. &:hover button[aria-haspopup],
  113. button[aria-expanded='true'],
  114. button[aria-haspopup]:focus-visible {
  115. opacity: 1;
  116. }
  117. `;