eventOrGroupExtraDetails.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import React from 'react';
  2. import {Link, withRouter, WithRouterProps} from 'react-router';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import GuideAnchor from 'app/components/assistant/guideAnchor';
  6. import EventAnnotation from 'app/components/events/eventAnnotation';
  7. import InboxReason from 'app/components/group/inboxBadges/inboxReason';
  8. import InboxShortId from 'app/components/group/inboxBadges/shortId';
  9. import TimesTag from 'app/components/group/inboxBadges/timesTag';
  10. import UnhandledTag from 'app/components/group/inboxBadges/unhandledTag';
  11. import Times from 'app/components/group/times';
  12. import ProjectBadge from 'app/components/idBadge/projectBadge';
  13. import Placeholder from 'app/components/placeholder';
  14. import ShortId from 'app/components/shortId';
  15. import {IconChat} from 'app/icons';
  16. import {tct} from 'app/locale';
  17. import space from 'app/styles/space';
  18. import {Group, Organization} from 'app/types';
  19. import {Event} from 'app/types/event';
  20. import withOrganization from 'app/utils/withOrganization';
  21. type Props = WithRouterProps<{orgId: string}> & {
  22. data: Event | Group;
  23. showAssignee?: boolean;
  24. organization: Organization;
  25. hasGuideAnchor?: boolean;
  26. showInboxTime?: boolean;
  27. };
  28. function EventOrGroupExtraDetails({
  29. data,
  30. showAssignee,
  31. params,
  32. organization,
  33. hasGuideAnchor,
  34. showInboxTime,
  35. }: Props) {
  36. const {
  37. id,
  38. lastSeen,
  39. firstSeen,
  40. subscriptionDetails,
  41. numComments,
  42. logger,
  43. assignedTo,
  44. annotations,
  45. shortId,
  46. project,
  47. lifetime,
  48. isUnhandled,
  49. inbox,
  50. } = data as Group;
  51. const issuesPath = `/organizations/${params.orgId}/issues/`;
  52. const hasInbox = organization.features.includes('inbox');
  53. const inboxReason = inbox && (
  54. <InboxReason inbox={inbox} showDateAdded={showInboxTime} />
  55. );
  56. return (
  57. <GroupExtra hasInbox={hasInbox}>
  58. {hasInbox && inbox && (
  59. <GuideAnchor target="inbox_guide_reason" disabled={!hasGuideAnchor}>
  60. {inboxReason}
  61. </GuideAnchor>
  62. )}
  63. {shortId &&
  64. (hasInbox ? (
  65. <InboxShortId
  66. shortId={shortId}
  67. avatar={
  68. project && (
  69. <ShadowlessProjectBadge project={project} avatarSize={12} hideName />
  70. )
  71. }
  72. />
  73. ) : (
  74. <GroupShortId
  75. shortId={shortId}
  76. avatar={
  77. project && <ProjectBadge project={project} avatarSize={14} hideName />
  78. }
  79. onClick={e => {
  80. // prevent the clicks from propagating so that the short id can be selected
  81. e.stopPropagation();
  82. }}
  83. />
  84. ))}
  85. {isUnhandled && hasInbox && <UnhandledTag />}
  86. {!lifetime && !firstSeen && !lastSeen ? (
  87. <Placeholder height="14px" width="100px" />
  88. ) : hasInbox ? (
  89. <TimesTag
  90. lastSeen={lifetime?.lastSeen || lastSeen}
  91. firstSeen={lifetime?.firstSeen || firstSeen}
  92. />
  93. ) : (
  94. <StyledTimes
  95. lastSeen={lifetime?.lastSeen || lastSeen}
  96. firstSeen={lifetime?.firstSeen || firstSeen}
  97. />
  98. )}
  99. {/* Always display comment count on inbox */}
  100. {numComments > 0 && (
  101. <CommentsLink to={`${issuesPath}${id}/activity/`} className="comments">
  102. <IconChat
  103. size="xs"
  104. color={subscriptionDetails?.reason === 'mentioned' ? 'green300' : undefined}
  105. />
  106. <span>{numComments}</span>
  107. </CommentsLink>
  108. )}
  109. {logger && (
  110. <LoggerAnnotation hasInbox={hasInbox}>
  111. <Link
  112. to={{
  113. pathname: issuesPath,
  114. query: {
  115. query: `logger:${logger}`,
  116. },
  117. }}
  118. >
  119. {logger}
  120. </Link>
  121. </LoggerAnnotation>
  122. )}
  123. {annotations?.map((annotation, key) => (
  124. <AnnotationNoMargin
  125. hasInbox={hasInbox}
  126. dangerouslySetInnerHTML={{
  127. __html: annotation,
  128. }}
  129. key={key}
  130. />
  131. ))}
  132. {showAssignee && assignedTo && (
  133. <div>{tct('Assigned to [name]', {name: assignedTo.name})}</div>
  134. )}
  135. </GroupExtra>
  136. );
  137. }
  138. const GroupExtra = styled('div')<{hasInbox: boolean}>`
  139. display: inline-grid;
  140. grid-auto-flow: column dense;
  141. grid-gap: ${p => (p.hasInbox ? space(1.5) : space(2))};
  142. justify-content: start;
  143. align-items: center;
  144. color: ${p => (p.hasInbox ? p.theme.textColor : p.theme.subText)};
  145. font-size: ${p => p.theme.fontSizeSmall};
  146. position: relative;
  147. min-width: 500px;
  148. white-space: nowrap;
  149. a {
  150. color: inherit;
  151. }
  152. `;
  153. const ShadowlessProjectBadge = styled(ProjectBadge)`
  154. * > img {
  155. box-shadow: none;
  156. }
  157. `;
  158. const StyledTimes = styled(Times)`
  159. margin-right: 0;
  160. `;
  161. const CommentsLink = styled(Link)`
  162. display: inline-grid;
  163. grid-gap: ${space(0.5)};
  164. align-items: center;
  165. grid-auto-flow: column;
  166. color: ${p => p.theme.textColor};
  167. `;
  168. const GroupShortId = styled(ShortId)`
  169. flex-shrink: 0;
  170. font-size: ${p => p.theme.fontSizeSmall};
  171. color: ${p => p.theme.subText};
  172. `;
  173. const AnnotationNoMargin = styled(EventAnnotation)<{hasInbox: boolean}>`
  174. margin-left: 0;
  175. padding-left: ${p => (p.hasInbox ? 0 : space(2))};
  176. ${p => p.hasInbox && `border-left: none;`};
  177. ${p =>
  178. p.hasInbox &&
  179. css`
  180. & > a {
  181. color: ${p.theme.textColor};
  182. }
  183. `}
  184. `;
  185. const LoggerAnnotation = styled(AnnotationNoMargin)`
  186. color: ${p => p.theme.textColor};
  187. `;
  188. export default withRouter(withOrganization(EventOrGroupExtraDetails));