groupSidebar.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import AvatarList from 'sentry/components/avatar/avatarList';
  4. import {DateTime} from 'sentry/components/dateTime';
  5. import type {OnAssignCallback} from 'sentry/components/deprecatedAssigneeSelectorDropdown';
  6. import ErrorBoundary from 'sentry/components/errorBoundary';
  7. import {EventThroughput} from 'sentry/components/events/eventStatisticalDetector/eventThroughput';
  8. import AssignedTo from 'sentry/components/group/assignedTo';
  9. import ExternalIssueList from 'sentry/components/group/externalIssuesList';
  10. import {StreamlinedExternalIssueList} from 'sentry/components/group/externalIssuesList/streamlinedExternalIssueList';
  11. import GroupReleaseStats from 'sentry/components/group/releaseStats';
  12. import TagFacets, {
  13. BACKEND_TAGS,
  14. DEFAULT_TAGS,
  15. FRONTEND_TAGS,
  16. MOBILE_TAGS,
  17. TAGS_FORMATTER,
  18. } from 'sentry/components/group/tagFacets';
  19. import QuestionTooltip from 'sentry/components/questionTooltip';
  20. import * as SidebarSection from 'sentry/components/sidebarSection';
  21. import {backend, frontend} from 'sentry/data/platformCategories';
  22. import {t, tn} from 'sentry/locale';
  23. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  24. import {space} from 'sentry/styles/space';
  25. import type {Event} from 'sentry/types/event';
  26. import type {Group, TeamParticipant, UserParticipant} from 'sentry/types/group';
  27. import type {Organization, OrganizationSummary} from 'sentry/types/organization';
  28. import type {Project} from 'sentry/types/project';
  29. import type {CurrentRelease} from 'sentry/types/release';
  30. import type {AvatarUser} from 'sentry/types/user';
  31. import {trackAnalytics} from 'sentry/utils/analytics';
  32. import {getUtcDateString} from 'sentry/utils/dates';
  33. import {getAnalyticsDataForGroup} from 'sentry/utils/events';
  34. import {userDisplayName} from 'sentry/utils/formatters';
  35. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  36. import {isMobilePlatform} from 'sentry/utils/platform';
  37. import {getAnalyicsDataForProject} from 'sentry/utils/projects';
  38. import {useApiQuery} from 'sentry/utils/queryClient';
  39. import {useLocation} from 'sentry/utils/useLocation';
  40. import {useUser} from 'sentry/utils/useUser';
  41. import {ParticipantList} from 'sentry/views/issueDetails/participantList';
  42. import {makeFetchGroupQueryKey} from 'sentry/views/issueDetails/useGroup';
  43. import {useHasStreamlinedUI} from 'sentry/views/issueDetails/utils';
  44. type Props = {
  45. environments: string[];
  46. group: Group;
  47. organization: Organization;
  48. project: Project;
  49. event?: Event;
  50. };
  51. function useFetchAllEnvsGroupData(organization: OrganizationSummary, group: Group) {
  52. return useApiQuery<Group>(
  53. makeFetchGroupQueryKey({
  54. organizationSlug: organization.slug,
  55. groupId: group.id,
  56. environments: [],
  57. }),
  58. {
  59. staleTime: 30000,
  60. gcTime: 30000,
  61. }
  62. );
  63. }
  64. function useFetchCurrentRelease(organization: OrganizationSummary, group: Group) {
  65. return useApiQuery<CurrentRelease>(
  66. [`/organizations/${organization.slug}/issues/${group.id}/current-release/`],
  67. {
  68. staleTime: 30000,
  69. gcTime: 30000,
  70. }
  71. );
  72. }
  73. export default function GroupSidebar({
  74. event,
  75. group,
  76. project,
  77. organization,
  78. environments,
  79. }: Props) {
  80. const activeUser = useUser();
  81. const {data: allEnvironmentsGroupData} = useFetchAllEnvsGroupData(organization, group);
  82. const {data: currentRelease} = useFetchCurrentRelease(organization, group);
  83. const hasStreamlinedUI = useHasStreamlinedUI();
  84. const location = useLocation();
  85. const onAssign: OnAssignCallback = (type, _assignee, suggestedAssignee) => {
  86. const {alert_date, alert_rule_id, alert_type} = location.query;
  87. trackAnalytics('issue_details.action_clicked', {
  88. organization,
  89. action_type: 'assign',
  90. assigned_type: type,
  91. assigned_suggestion_reason: suggestedAssignee?.suggestedReason,
  92. alert_date:
  93. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  94. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  95. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  96. ...getAnalyticsDataForGroup(group),
  97. ...getAnalyicsDataForProject(project),
  98. });
  99. IssueListCacheStore.reset();
  100. };
  101. const renderPluginIssue = () => {
  102. const issues: React.ReactNode[] = [];
  103. (group.pluginIssues || []).forEach(plugin => {
  104. const issue = plugin.issue;
  105. // # TODO(dcramer): remove plugin.title check in Sentry 8.22+
  106. if (issue) {
  107. issues.push(
  108. <Fragment key={plugin.slug}>
  109. <span>{`${plugin.shortName || plugin.name || plugin.title}: `}</span>
  110. <a href={issue.url}>
  111. {typeof issue.label === 'object' ? issue.label.id : issue.label}
  112. </a>
  113. </Fragment>
  114. );
  115. }
  116. });
  117. if (!issues.length) {
  118. return null;
  119. }
  120. return (
  121. <SidebarSection.Wrap>
  122. <SidebarSection.Title>{t('External Issues')}</SidebarSection.Title>
  123. <SidebarSection.Content>
  124. <ExternalIssues>{issues}</ExternalIssues>
  125. </SidebarSection.Content>
  126. </SidebarSection.Wrap>
  127. );
  128. };
  129. const renderParticipantData = () => {
  130. const {participants} = group;
  131. if (!participants.length) {
  132. return null;
  133. }
  134. const userParticipants = participants.filter(
  135. (p): p is UserParticipant => p.type === 'user'
  136. );
  137. const teamParticipants = participants.filter(
  138. (p): p is TeamParticipant => p.type === 'team'
  139. );
  140. const getParticipantTitle = (): React.ReactNode => {
  141. const individualText = tn(
  142. '%s Individual',
  143. '%s Individuals',
  144. userParticipants.length
  145. );
  146. const teamText = tn('%s Team', '%s Teams', teamParticipants.length);
  147. if (teamParticipants.length === 0) {
  148. return individualText;
  149. }
  150. if (userParticipants.length === 0) {
  151. return teamText;
  152. }
  153. return (
  154. <Fragment>
  155. {teamText}, {individualText}
  156. </Fragment>
  157. );
  158. };
  159. const avatars = (
  160. <StyledAvatarList
  161. users={userParticipants}
  162. teams={teamParticipants}
  163. avatarSize={28}
  164. maxVisibleAvatars={12}
  165. typeAvatars="participants"
  166. />
  167. );
  168. return (
  169. <SmallerSidebarWrap>
  170. <SidebarSection.Title>
  171. {t('Participants')} <TitleNumber>({getParticipantTitle()})</TitleNumber>
  172. <QuestionTooltip
  173. size="xs"
  174. position="top"
  175. title={t(
  176. 'People who have been assigned, resolved, unresolved, archived, bookmarked, subscribed, or added a comment'
  177. )}
  178. />
  179. </SidebarSection.Title>
  180. <SidebarSection.Content>
  181. <ParticipantList
  182. users={userParticipants}
  183. teams={teamParticipants}
  184. description={t('participants')}
  185. >
  186. {avatars}
  187. </ParticipantList>
  188. </SidebarSection.Content>
  189. </SmallerSidebarWrap>
  190. );
  191. };
  192. const renderSeenByList = () => {
  193. const {seenBy} = group;
  194. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  195. if (!displayUsers.length) {
  196. return null;
  197. }
  198. const avatars = (
  199. <StyledAvatarList
  200. users={displayUsers}
  201. avatarSize={28}
  202. maxVisibleAvatars={12}
  203. renderTooltip={user => (
  204. <Fragment>
  205. {userDisplayName(user)}
  206. <br />
  207. <DateTime date={(user as AvatarUser).lastSeen} />
  208. </Fragment>
  209. )}
  210. />
  211. );
  212. return (
  213. <SmallerSidebarWrap>
  214. <SidebarSection.Title>
  215. {t('Viewers')}
  216. <TitleNumber>({displayUsers.length})</TitleNumber>
  217. <QuestionTooltip
  218. size="xs"
  219. position="top"
  220. title={t('People who have viewed this issue')}
  221. />
  222. </SidebarSection.Title>
  223. <SidebarSection.Content>
  224. <ParticipantList users={displayUsers} teams={[]} description={t('users')}>
  225. {avatars}
  226. </ParticipantList>
  227. </SidebarSection.Content>
  228. </SmallerSidebarWrap>
  229. );
  230. };
  231. const issueTypeConfig = getConfigForIssueType(group, project);
  232. return (
  233. <Container>
  234. {hasStreamlinedUI && event && (
  235. <ErrorBoundary mini>
  236. <StreamlinedExternalIssueList group={group} event={event} project={project} />
  237. </ErrorBoundary>
  238. )}
  239. {!hasStreamlinedUI && (
  240. <AssignedTo group={group} event={event} project={project} onAssign={onAssign} />
  241. )}
  242. {issueTypeConfig.stats.enabled && (
  243. <GroupReleaseStats
  244. organization={organization}
  245. project={project}
  246. environments={environments}
  247. allEnvironments={allEnvironmentsGroupData}
  248. group={group}
  249. currentRelease={currentRelease}
  250. />
  251. )}
  252. {!hasStreamlinedUI && event && (
  253. <ErrorBoundary mini>
  254. <ExternalIssueList project={project} group={group} event={event} />
  255. </ErrorBoundary>
  256. )}
  257. {!hasStreamlinedUI && renderPluginIssue()}
  258. {issueTypeConfig.tags.enabled && (
  259. <TagFacets
  260. environments={environments}
  261. groupId={group.id}
  262. tagKeys={
  263. isMobilePlatform(project?.platform)
  264. ? MOBILE_TAGS
  265. : frontend.some(val => val === project?.platform)
  266. ? FRONTEND_TAGS
  267. : backend.some(val => val === project?.platform)
  268. ? BACKEND_TAGS
  269. : DEFAULT_TAGS
  270. }
  271. tagFormatter={TAGS_FORMATTER}
  272. project={project}
  273. />
  274. )}
  275. {issueTypeConfig.regression.enabled && event && (
  276. <EventThroughput event={event} group={group} />
  277. )}
  278. {!hasStreamlinedUI && renderParticipantData()}
  279. {!hasStreamlinedUI && renderSeenByList()}
  280. </Container>
  281. );
  282. }
  283. const Container = styled('div')`
  284. font-size: ${p => p.theme.fontSizeMedium};
  285. `;
  286. const ExternalIssues = styled('div')`
  287. display: grid;
  288. grid-template-columns: auto max-content;
  289. gap: ${space(2)};
  290. `;
  291. const StyledAvatarList = styled(AvatarList)`
  292. justify-content: flex-end;
  293. padding-left: ${space(0.75)};
  294. `;
  295. const TitleNumber = styled('span')`
  296. font-weight: ${p => p.theme.fontWeightNormal};
  297. `;
  298. // Using 22px + space(1) = space(4)
  299. const SmallerSidebarWrap = styled(SidebarSection.Wrap)`
  300. margin-bottom: 22px;
  301. `;