groupSidebar.tsx 10 KB

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