resolutionBox.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import UserAvatar from 'app/components/avatar/userAvatar';
  4. import CommitLink from 'app/components/commitLink';
  5. import {BannerContainer, BannerSummary} from 'app/components/events/styles';
  6. import TimeSince from 'app/components/timeSince';
  7. import Version from 'app/components/version';
  8. import {IconCheckmark} from 'app/icons';
  9. import {t, tct} from 'app/locale';
  10. import space from 'app/styles/space';
  11. import {ResolutionStatusDetails} from 'app/types';
  12. type Props = {
  13. statusDetails: ResolutionStatusDetails;
  14. projectId: string;
  15. };
  16. function renderReason(statusDetails: ResolutionStatusDetails, projectId: string) {
  17. const actor = statusDetails.actor ? (
  18. <strong>
  19. <UserAvatar user={statusDetails.actor} size={20} className="avatar" />
  20. <span style={{marginLeft: 5}}>{statusDetails.actor.name}</span>
  21. </strong>
  22. ) : null;
  23. if (statusDetails.inNextRelease && statusDetails.actor) {
  24. return tct('[actor] marked this issue as resolved in the upcoming release.', {
  25. actor,
  26. });
  27. } else if (statusDetails.inNextRelease) {
  28. return t('This issue has been marked as resolved in the upcoming release.');
  29. } else if (statusDetails.inRelease && statusDetails.actor) {
  30. return tct('[actor] marked this issue as resolved in version [version].', {
  31. actor,
  32. version: (
  33. <Version
  34. version={statusDetails.inRelease}
  35. projectId={projectId}
  36. tooltipRawVersion
  37. />
  38. ),
  39. });
  40. } else if (statusDetails.inRelease) {
  41. return tct('This issue has been marked as resolved in version [version].', {
  42. version: (
  43. <Version
  44. version={statusDetails.inRelease}
  45. projectId={projectId}
  46. tooltipRawVersion
  47. />
  48. ),
  49. });
  50. } else if (!!statusDetails.inCommit) {
  51. return tct('This issue has been marked as resolved by [commit]', {
  52. commit: (
  53. <React.Fragment>
  54. <CommitLink
  55. commitId={statusDetails.inCommit.id}
  56. repository={statusDetails.inCommit.repository}
  57. />
  58. <StyledTimeSince date={statusDetails.inCommit.dateCreated} />
  59. </React.Fragment>
  60. ),
  61. });
  62. }
  63. return t('This issue has been marked as resolved.');
  64. }
  65. function ResolutionBox({statusDetails, projectId}: Props) {
  66. return (
  67. <BannerContainer priority="default">
  68. <BannerSummary>
  69. <StyledIconCheckmark color="green300" />
  70. <span>{renderReason(statusDetails, projectId)}</span>
  71. </BannerSummary>
  72. </BannerContainer>
  73. );
  74. }
  75. const StyledTimeSince = styled(TimeSince)`
  76. color: ${p => p.theme.gray300};
  77. margin-left: ${space(0.5)};
  78. font-size: ${p => p.theme.fontSizeSmall};
  79. `;
  80. const StyledIconCheckmark = styled(IconCheckmark)`
  81. /* override margin defined in BannerSummary */
  82. margin-top: 0 !important;
  83. align-self: center;
  84. @media (max-width: ${p => p.theme.breakpoints[0]}) {
  85. margin-top: ${space(0.5)} !important;
  86. align-self: flex-start;
  87. }
  88. `;
  89. export default ResolutionBox;