groupSidebar.tsx 9.8 KB

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