shortIdBreadcrumb.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import styled from '@emotion/styled';
  2. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  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 {IconChevron} from 'sentry/icons';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import {Group, Organization, Project} from 'sentry/types';
  11. import useCopyToClipboard from 'sentry/utils/useCopyToClipboard';
  12. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  13. interface ShortIdBreadrcumbProps {
  14. group: Group;
  15. organization: Organization;
  16. project: Project;
  17. }
  18. export function ShortIdBreadrcumb({
  19. organization,
  20. project,
  21. group,
  22. }: ShortIdBreadrcumbProps) {
  23. const {onClick: handleCopyShortId} = useCopyToClipboard({
  24. text: group.shortId,
  25. successMessage: t('Copied Short-ID to clipboard'),
  26. });
  27. const issueUrl =
  28. window.location.origin +
  29. normalizeUrl(`/organizations/${organization.slug}/issues/${group.id}/`);
  30. const {onClick: handleCopyUrl} = useCopyToClipboard({
  31. text: issueUrl,
  32. successMessage: t('Copied Issue URL to clipboard'),
  33. });
  34. const {onClick: handleCopyMarkdown} = useCopyToClipboard({
  35. text: `[${group.shortId}](${issueUrl})`,
  36. successMessage: t('Copied Markdown Issue Link to clipboard'),
  37. });
  38. if (!group.shortId) {
  39. return null;
  40. }
  41. return (
  42. <GuideAnchor target="issue_number" position="bottom">
  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: <IconChevron direction="down" size="xs" />,
  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. </GuideAnchor>
  92. );
  93. }
  94. const Wrapper = styled('div')`
  95. display: flex;
  96. gap: ${space(1)};
  97. align-items: center;
  98. `;
  99. const StyledShortId = styled(ShortId)`
  100. font-family: ${p => p.theme.text.family};
  101. font-size: ${p => p.theme.fontSizeMedium};
  102. line-height: 1;
  103. `;
  104. const ShortIdCopyable = styled('div')`
  105. display: flex;
  106. gap: ${space(0.25)};
  107. align-items: center;
  108. button[aria-haspopup] {
  109. display: block;
  110. opacity: 0;
  111. transition: opacity 50ms linear;
  112. }
  113. &:hover button[aria-haspopup],
  114. button[aria-expanded='true'],
  115. button[aria-haspopup].focus-visible {
  116. opacity: 1;
  117. }
  118. `;