quickContextCommitRow.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import styled from '@emotion/styled';
  2. import UserAvatar from 'sentry/components/avatar/userAvatar';
  3. import CommitLink from 'sentry/components/commitLink';
  4. import type {CommitRowProps} from 'sentry/components/commitRow';
  5. import {formatCommitMessage} from 'sentry/components/commitRow';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import PanelItem from 'sentry/components/panels/panelItem';
  8. import TextOverflow from 'sentry/components/textOverflow';
  9. import {Tooltip} from 'sentry/components/tooltip';
  10. import {t, tct} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {useUser} from 'sentry/utils/useUser';
  13. function QuickContextCommitRow({commit}: CommitRowProps) {
  14. const user = useUser();
  15. const isUser = user?.id === commit.author?.id;
  16. const hasPullRequestURL = commit.pullRequest?.externalUrl;
  17. const commitMessage = formatCommitMessage(commit.message);
  18. return (
  19. <StyledPanelItem key={commit.id} data-test-id="quick-context-commit-row">
  20. <UserAvatar size={24} user={commit.author} />
  21. <CommitLinks>
  22. {hasPullRequestURL && commit.message && (
  23. <Tooltip containerDisplayMode="inline" showOnlyOnOverflow title={commitMessage}>
  24. <LinkToPullRequest data-test-id="quick-context-commit-row-pr-link">
  25. <ExternalLink href={commit.pullRequest?.externalUrl}>
  26. {commitMessage}
  27. </ExternalLink>
  28. </LinkToPullRequest>
  29. </Tooltip>
  30. )}
  31. <LinkToCommit
  32. hasPrTitle={hasPullRequestURL && commit.message}
  33. data-test-id="quick-context-commit-row-commit-link"
  34. >
  35. {tct('View commit [commitLink] by [author]', {
  36. author: isUser ? t('You') : commit.author?.name ?? t('Unknown author'),
  37. commitLink: (
  38. <CommitLink
  39. inline
  40. showIcon={false}
  41. commitId={commit.id}
  42. repository={commit.repository}
  43. />
  44. ),
  45. })}
  46. </LinkToCommit>
  47. </CommitLinks>
  48. </StyledPanelItem>
  49. );
  50. }
  51. const StyledPanelItem = styled(PanelItem)`
  52. display: flex;
  53. align-items: center;
  54. gap: ${space(1)};
  55. padding: 0;
  56. border: none;
  57. & + & {
  58. margin-top: ${space(1)};
  59. }
  60. `;
  61. const CommitLinks = styled('div')`
  62. flex: 1;
  63. flex-direction: column;
  64. min-width: 0;
  65. `;
  66. const LinkToPullRequest = styled(TextOverflow)`
  67. font-size: ${p => p.theme.fontSizeLarge};
  68. line-height: 1.2;
  69. `;
  70. const LinkToCommit = styled(TextOverflow)<{hasPrTitle: string | null | undefined}>`
  71. font-size: ${p => (p.hasPrTitle ? p.theme.fontSizeSmall : p.theme.fontSizeLarge)};
  72. color: ${p => (p.hasPrTitle ? p.theme.subText : p.theme.textColor)};
  73. line-height: 1.5;
  74. margin: 0;
  75. `;
  76. export {QuickContextCommitRow};