quickContextCommitRow.tsx 2.5 KB

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