groupSidebar.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import isObject from 'lodash/isObject';
  4. import type {OnAssignCallback} from 'sentry/components/assigneeSelectorDropdown';
  5. import AvatarList from 'sentry/components/avatar/avatarList';
  6. import DateTime from 'sentry/components/dateTime';
  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 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 ConfigStore from 'sentry/stores/configStore';
  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 {useApiQuery} from 'sentry/utils/queryClient';
  44. import {useLocation} from 'sentry/utils/useLocation';
  45. import {getGroupDetailsQueryData} from 'sentry/views/issueDetails/utils';
  46. import {ParticipantList} from './participantList';
  47. type Props = {
  48. environments: string[];
  49. group: Group;
  50. organization: Organization;
  51. project: Project;
  52. event?: Event;
  53. };
  54. function useFetchAllEnvsGroupData(organization: OrganizationSummary, group: Group) {
  55. return useApiQuery<Group>(
  56. [
  57. `/organizations/${organization.slug}/issues/${group.id}/`,
  58. {query: getGroupDetailsQueryData()},
  59. ],
  60. {
  61. staleTime: 30000,
  62. cacheTime: 30000,
  63. }
  64. );
  65. }
  66. function useFetchCurrentRelease(organization: OrganizationSummary, group: Group) {
  67. return useApiQuery<CurrentRelease>(
  68. [`/organizations/${organization.slug}/issues/${group.id}/current-release/`],
  69. {
  70. staleTime: 30000,
  71. cacheTime: 30000,
  72. }
  73. );
  74. }
  75. export default function GroupSidebar({
  76. event,
  77. group,
  78. project,
  79. organization,
  80. environments,
  81. }: Props) {
  82. const {data: allEnvironmentsGroupData} = useFetchAllEnvsGroupData(organization, group);
  83. const {data: currentRelease} = useFetchCurrentRelease(organization, group);
  84. const location = useLocation();
  85. const trackAssign: OnAssignCallback = (type, _assignee, suggestedAssignee) => {
  86. const {alert_date, alert_rule_id, alert_type} = location.query;
  87. trackAnalytics('issue_details.action_clicked', {
  88. organization,
  89. project_id: parseInt(project.id, 10),
  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. });
  99. };
  100. const renderPluginIssue = () => {
  101. const issues: React.ReactNode[] = [];
  102. (group.pluginIssues || []).forEach(plugin => {
  103. const issue = plugin.issue;
  104. // # TODO(dcramer): remove plugin.title check in Sentry 8.22+
  105. if (issue) {
  106. issues.push(
  107. <Fragment key={plugin.slug}>
  108. <span>{`${plugin.shortName || plugin.name || plugin.title}: `}</span>
  109. <a href={issue.url}>{isObject(issue.label) ? issue.label.id : issue.label}</a>
  110. </Fragment>
  111. );
  112. }
  113. });
  114. if (!issues.length) {
  115. return null;
  116. }
  117. return (
  118. <SidebarSection.Wrap>
  119. <SidebarSection.Title>{t('External Issues')}</SidebarSection.Title>
  120. <SidebarSection.Content>
  121. <ExternalIssues>{issues}</ExternalIssues>
  122. </SidebarSection.Content>
  123. </SidebarSection.Wrap>
  124. );
  125. };
  126. const hasParticipantsFeature = organization.features.includes('participants-purge');
  127. const renderParticipantData = () => {
  128. const {participants} = group;
  129. if (!participants.length) {
  130. return null;
  131. }
  132. const userParticipants = participants.filter(
  133. (p): p is UserParticipant => p.type === 'user'
  134. );
  135. const teamParticipants = participants.filter(
  136. (p): p is TeamParticipant => p.type === 'team'
  137. );
  138. const getParticipantTitle = (): React.ReactNode => {
  139. if (!hasParticipantsFeature) {
  140. return `${group.participants.length}`;
  141. }
  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={hasParticipantsFeature ? 12 : 13}
  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. {hasParticipantsFeature ? (
  183. <ParticipantList
  184. users={userParticipants}
  185. teams={teamParticipants}
  186. description={t('participants')}
  187. >
  188. {avatars}
  189. </ParticipantList>
  190. ) : (
  191. <StyledAvatarList
  192. users={userParticipants}
  193. teams={teamParticipants}
  194. avatarSize={28}
  195. maxVisibleAvatars={13}
  196. typeAvatars="participants"
  197. />
  198. )}
  199. </SidebarSection.Content>
  200. </SmallerSidebarWrap>
  201. );
  202. };
  203. const renderSeenByList = () => {
  204. const {seenBy} = group;
  205. const activeUser = ConfigStore.get('user');
  206. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  207. if (!displayUsers.length) {
  208. return null;
  209. }
  210. const avatars = (
  211. <StyledAvatarList
  212. users={displayUsers}
  213. avatarSize={28}
  214. maxVisibleAvatars={hasParticipantsFeature ? 12 : 13}
  215. renderTooltip={user => (
  216. <Fragment>
  217. {userDisplayName(user)}
  218. <br />
  219. <DateTime date={(user as AvatarUser).lastSeen} />
  220. </Fragment>
  221. )}
  222. />
  223. );
  224. return (
  225. <SmallerSidebarWrap>
  226. <SidebarSection.Title>
  227. {t('Viewers')}
  228. <TitleNumber>({displayUsers.length})</TitleNumber>
  229. <QuestionTooltip
  230. size="xs"
  231. position="top"
  232. title={t('People who have viewed this issue')}
  233. />
  234. </SidebarSection.Title>
  235. <SidebarSection.Content>
  236. {hasParticipantsFeature ? (
  237. <ParticipantList users={displayUsers} teams={[]} description={t('users')}>
  238. {avatars}
  239. </ParticipantList>
  240. ) : (
  241. avatars
  242. )}
  243. </SidebarSection.Content>
  244. </SmallerSidebarWrap>
  245. );
  246. };
  247. const issueTypeConfig = getConfigForIssueType(group);
  248. return (
  249. <Container>
  250. <AssignedTo group={group} event={event} project={project} onAssign={trackAssign} />
  251. {issueTypeConfig.stats.enabled && (
  252. <GroupReleaseStats
  253. organization={organization}
  254. project={project}
  255. environments={environments}
  256. allEnvironments={allEnvironmentsGroupData}
  257. group={group}
  258. currentRelease={currentRelease}
  259. />
  260. )}
  261. {event && (
  262. <ErrorBoundary mini>
  263. <ExternalIssueList project={project} group={group} event={event} />
  264. </ErrorBoundary>
  265. )}
  266. {renderPluginIssue()}
  267. {issueTypeConfig.tags.enabled && (
  268. <TagFacets
  269. environments={environments}
  270. groupId={group.id}
  271. tagKeys={
  272. isMobilePlatform(project?.platform)
  273. ? !organization.features.includes('device-classification')
  274. ? MOBILE_TAGS.filter(tag => tag !== 'device.class')
  275. : MOBILE_TAGS
  276. : frontend.some(val => val === project?.platform)
  277. ? FRONTEND_TAGS
  278. : backend.some(val => val === project?.platform)
  279. ? BACKEND_TAGS
  280. : DEFAULT_TAGS
  281. }
  282. event={event}
  283. tagFormatter={TAGS_FORMATTER}
  284. project={project}
  285. isStatisticalDetector={
  286. group.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION ||
  287. group.issueType === IssueType.PERFORMANCE_ENDPOINT_REGRESSION
  288. }
  289. />
  290. )}
  291. {issueTypeConfig.regression.enabled && event && (
  292. <EventThroughput event={event} group={group} />
  293. )}
  294. {renderParticipantData()}
  295. {renderSeenByList()}
  296. </Container>
  297. );
  298. }
  299. const Container = styled('div')`
  300. font-size: ${p => p.theme.fontSizeMedium};
  301. `;
  302. const ExternalIssues = styled('div')`
  303. display: grid;
  304. grid-template-columns: auto max-content;
  305. gap: ${space(2)};
  306. `;
  307. const StyledAvatarList = styled(AvatarList)`
  308. justify-content: flex-end;
  309. padding-left: ${space(0.75)};
  310. `;
  311. const TitleNumber = styled('span')`
  312. font-weight: normal;
  313. `;
  314. // Using 22px + space(1) = space(4)
  315. const SmallerSidebarWrap = styled(SidebarSection.Wrap)`
  316. margin-bottom: 22px;
  317. `;