groupSidebar.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Feature from 'sentry/components/acl/feature';
  4. import AvatarList from 'sentry/components/avatar/avatarList';
  5. import {DateTime} from 'sentry/components/dateTime';
  6. import type {OnAssignCallback} from 'sentry/components/deprecatedAssigneeSelectorDropdown';
  7. import ErrorBoundary from 'sentry/components/errorBoundary';
  8. import {EventThroughput} from 'sentry/components/events/eventStatisticalDetector/eventThroughput';
  9. import AssignedTo from 'sentry/components/group/assignedTo';
  10. import ExternalIssueList from 'sentry/components/group/externalIssuesList';
  11. import {StreamlinedExternalIssueList} from 'sentry/components/group/externalIssuesList/streamlinedExternalIssueList';
  12. import {GroupSummary} from 'sentry/components/group/groupSummary';
  13. import GroupReleaseStats from 'sentry/components/group/releaseStats';
  14. import TagFacets, {
  15. BACKEND_TAGS,
  16. DEFAULT_TAGS,
  17. FRONTEND_TAGS,
  18. MOBILE_TAGS,
  19. TAGS_FORMATTER,
  20. } from 'sentry/components/group/tagFacets';
  21. import QuestionTooltip from 'sentry/components/questionTooltip';
  22. import * as SidebarSection from 'sentry/components/sidebarSection';
  23. import {backend, frontend} from 'sentry/data/platformCategories';
  24. import {t, tn} from 'sentry/locale';
  25. import ConfigStore from 'sentry/stores/configStore';
  26. import IssueListCacheStore from 'sentry/stores/IssueListCacheStore';
  27. import {space} from 'sentry/styles/space';
  28. import type {Event} from 'sentry/types/event';
  29. import type {Group, TeamParticipant, UserParticipant} from 'sentry/types/group';
  30. import {IssueType} from 'sentry/types/group';
  31. import type {Organization, OrganizationSummary} from 'sentry/types/organization';
  32. import type {Project} from 'sentry/types/project';
  33. import type {CurrentRelease} from 'sentry/types/release';
  34. import type {AvatarUser} from 'sentry/types/user';
  35. import {trackAnalytics} from 'sentry/utils/analytics';
  36. import {getUtcDateString} from 'sentry/utils/dates';
  37. import {getAnalyticsDataForGroup} from 'sentry/utils/events';
  38. import {userDisplayName} from 'sentry/utils/formatters';
  39. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  40. import {isMobilePlatform} from 'sentry/utils/platform';
  41. import {getAnalyicsDataForProject} from 'sentry/utils/projects';
  42. import {useApiQuery} from 'sentry/utils/queryClient';
  43. import {useLocation} from 'sentry/utils/useLocation';
  44. import {ParticipantList} from 'sentry/views/issueDetails/participantList';
  45. import {
  46. getGroupDetailsQueryData,
  47. useHasStreamlinedUI,
  48. } from 'sentry/views/issueDetails/utils';
  49. type Props = {
  50. environments: string[];
  51. group: Group;
  52. organization: Organization;
  53. project: Project;
  54. event?: Event;
  55. };
  56. function useFetchAllEnvsGroupData(organization: OrganizationSummary, group: Group) {
  57. return useApiQuery<Group>(
  58. [
  59. `/organizations/${organization.slug}/issues/${group.id}/`,
  60. {query: getGroupDetailsQueryData()},
  61. ],
  62. {
  63. staleTime: 30000,
  64. cacheTime: 30000,
  65. }
  66. );
  67. }
  68. function useFetchCurrentRelease(organization: OrganizationSummary, group: Group) {
  69. return useApiQuery<CurrentRelease>(
  70. [`/organizations/${organization.slug}/issues/${group.id}/current-release/`],
  71. {
  72. staleTime: 30000,
  73. cacheTime: 30000,
  74. }
  75. );
  76. }
  77. export default function GroupSidebar({
  78. event,
  79. group,
  80. project,
  81. organization,
  82. environments,
  83. }: Props) {
  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 activeUser = ConfigStore.get('user');
  198. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  199. if (!displayUsers.length) {
  200. return null;
  201. }
  202. const avatars = (
  203. <StyledAvatarList
  204. users={displayUsers}
  205. avatarSize={28}
  206. maxVisibleAvatars={12}
  207. renderTooltip={user => (
  208. <Fragment>
  209. {userDisplayName(user)}
  210. <br />
  211. <DateTime date={(user as AvatarUser).lastSeen} />
  212. </Fragment>
  213. )}
  214. />
  215. );
  216. return (
  217. <SmallerSidebarWrap>
  218. <SidebarSection.Title>
  219. {t('Viewers')}
  220. <TitleNumber>({displayUsers.length})</TitleNumber>
  221. <QuestionTooltip
  222. size="xs"
  223. position="top"
  224. title={t('People who have viewed this issue')}
  225. />
  226. </SidebarSection.Title>
  227. <SidebarSection.Content>
  228. <ParticipantList users={displayUsers} teams={[]} description={t('users')}>
  229. {avatars}
  230. </ParticipantList>
  231. </SidebarSection.Content>
  232. </SmallerSidebarWrap>
  233. );
  234. };
  235. const issueTypeConfig = getConfigForIssueType(group, project);
  236. return (
  237. <Container>
  238. <Feature features={['organizations:ai-summary']}>
  239. <GroupSummary groupId={group.id} />
  240. </Feature>
  241. {hasStreamlinedUI && event && (
  242. <ErrorBoundary mini>
  243. <StreamlinedExternalIssueList group={group} event={event} project={project} />
  244. </ErrorBoundary>
  245. )}
  246. {!hasStreamlinedUI && (
  247. <AssignedTo group={group} event={event} project={project} onAssign={onAssign} />
  248. )}
  249. {issueTypeConfig.stats.enabled && (
  250. <GroupReleaseStats
  251. organization={organization}
  252. project={project}
  253. environments={environments}
  254. allEnvironments={allEnvironmentsGroupData}
  255. group={group}
  256. currentRelease={currentRelease}
  257. />
  258. )}
  259. {!hasStreamlinedUI && event && (
  260. <ErrorBoundary mini>
  261. <ExternalIssueList project={project} group={group} event={event} />
  262. </ErrorBoundary>
  263. )}
  264. {!hasStreamlinedUI && renderPluginIssue()}
  265. {issueTypeConfig.tags.enabled && (
  266. <TagFacets
  267. environments={environments}
  268. groupId={group.id}
  269. tagKeys={
  270. isMobilePlatform(project?.platform)
  271. ? MOBILE_TAGS
  272. : frontend.some(val => val === project?.platform)
  273. ? FRONTEND_TAGS
  274. : backend.some(val => val === project?.platform)
  275. ? BACKEND_TAGS
  276. : DEFAULT_TAGS
  277. }
  278. event={event}
  279. tagFormatter={TAGS_FORMATTER}
  280. project={project}
  281. isStatisticalDetector={
  282. group.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION ||
  283. group.issueType === IssueType.PERFORMANCE_ENDPOINT_REGRESSION
  284. }
  285. />
  286. )}
  287. {issueTypeConfig.regression.enabled && event && (
  288. <EventThroughput event={event} group={group} />
  289. )}
  290. {!hasStreamlinedUI && renderParticipantData()}
  291. {!hasStreamlinedUI && renderSeenByList()}
  292. </Container>
  293. );
  294. }
  295. const Container = styled('div')`
  296. font-size: ${p => p.theme.fontSizeMedium};
  297. `;
  298. const ExternalIssues = styled('div')`
  299. display: grid;
  300. grid-template-columns: auto max-content;
  301. gap: ${space(2)};
  302. `;
  303. const StyledAvatarList = styled(AvatarList)`
  304. justify-content: flex-end;
  305. padding-left: ${space(0.75)};
  306. `;
  307. const TitleNumber = styled('span')`
  308. font-weight: ${p => p.theme.fontWeightNormal};
  309. `;
  310. // Using 22px + space(1) = space(4)
  311. const SmallerSidebarWrap = styled(SidebarSection.Wrap)`
  312. margin-bottom: 22px;
  313. `;