groupSidebar.tsx 10 KB

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