groupSidebar.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 {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 trackAssign: 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. };
  101. const renderPluginIssue = () => {
  102. const issues: React.ReactNode[] = [];
  103. (group.pluginIssues || []).forEach(plugin => {
  104. const issue = plugin.issue;
  105. // # TODO(dcramer): remove plugin.title check in Sentry 8.22+
  106. if (issue) {
  107. issues.push(
  108. <Fragment key={plugin.slug}>
  109. <span>{`${plugin.shortName || plugin.name || plugin.title}: `}</span>
  110. <a href={issue.url}>{isObject(issue.label) ? issue.label.id : issue.label}</a>
  111. </Fragment>
  112. );
  113. }
  114. });
  115. if (!issues.length) {
  116. return null;
  117. }
  118. return (
  119. <SidebarSection.Wrap>
  120. <SidebarSection.Title>{t('External Issues')}</SidebarSection.Title>
  121. <SidebarSection.Content>
  122. <ExternalIssues>{issues}</ExternalIssues>
  123. </SidebarSection.Content>
  124. </SidebarSection.Wrap>
  125. );
  126. };
  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. const individualText = tn(
  140. '%s Individual',
  141. '%s Individuals',
  142. userParticipants.length
  143. );
  144. const teamText = tn('%s Team', '%s Teams', teamParticipants.length);
  145. if (teamParticipants.length === 0) {
  146. return individualText;
  147. }
  148. if (userParticipants.length === 0) {
  149. return teamText;
  150. }
  151. return (
  152. <Fragment>
  153. {teamText}, {individualText}
  154. </Fragment>
  155. );
  156. };
  157. const avatars = (
  158. <StyledAvatarList
  159. users={userParticipants}
  160. teams={teamParticipants}
  161. avatarSize={28}
  162. maxVisibleAvatars={12}
  163. typeAvatars="participants"
  164. />
  165. );
  166. return (
  167. <SmallerSidebarWrap>
  168. <SidebarSection.Title>
  169. {t('Participants')} <TitleNumber>({getParticipantTitle()})</TitleNumber>
  170. <QuestionTooltip
  171. size="xs"
  172. position="top"
  173. title={t(
  174. 'People who have been assigned, resolved, unresolved, archived, bookmarked, subscribed, or added a comment'
  175. )}
  176. />
  177. </SidebarSection.Title>
  178. <SidebarSection.Content>
  179. <ParticipantList
  180. users={userParticipants}
  181. teams={teamParticipants}
  182. description={t('participants')}
  183. >
  184. {avatars}
  185. </ParticipantList>
  186. </SidebarSection.Content>
  187. </SmallerSidebarWrap>
  188. );
  189. };
  190. const renderSeenByList = () => {
  191. const {seenBy} = group;
  192. const activeUser = ConfigStore.get('user');
  193. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  194. if (!displayUsers.length) {
  195. return null;
  196. }
  197. const avatars = (
  198. <StyledAvatarList
  199. users={displayUsers}
  200. avatarSize={28}
  201. maxVisibleAvatars={12}
  202. renderTooltip={user => (
  203. <Fragment>
  204. {userDisplayName(user)}
  205. <br />
  206. <DateTime date={(user as AvatarUser).lastSeen} />
  207. </Fragment>
  208. )}
  209. />
  210. );
  211. return (
  212. <SmallerSidebarWrap>
  213. <SidebarSection.Title>
  214. {t('Viewers')}
  215. <TitleNumber>({displayUsers.length})</TitleNumber>
  216. <QuestionTooltip
  217. size="xs"
  218. position="top"
  219. title={t('People who have viewed this issue')}
  220. />
  221. </SidebarSection.Title>
  222. <SidebarSection.Content>
  223. <ParticipantList users={displayUsers} teams={[]} description={t('users')}>
  224. {avatars}
  225. </ParticipantList>
  226. </SidebarSection.Content>
  227. </SmallerSidebarWrap>
  228. );
  229. };
  230. const issueTypeConfig = getConfigForIssueType(group);
  231. return (
  232. <Container>
  233. <AssignedTo group={group} event={event} project={project} onAssign={trackAssign} />
  234. {issueTypeConfig.stats.enabled && (
  235. <GroupReleaseStats
  236. organization={organization}
  237. project={project}
  238. environments={environments}
  239. allEnvironments={allEnvironmentsGroupData}
  240. group={group}
  241. currentRelease={currentRelease}
  242. />
  243. )}
  244. {event && (
  245. <ErrorBoundary mini>
  246. <ExternalIssueList project={project} group={group} event={event} />
  247. </ErrorBoundary>
  248. )}
  249. {renderPluginIssue()}
  250. {issueTypeConfig.tags.enabled && (
  251. <TagFacets
  252. environments={environments}
  253. groupId={group.id}
  254. tagKeys={
  255. isMobilePlatform(project?.platform)
  256. ? !organization.features.includes('device-classification')
  257. ? MOBILE_TAGS.filter(tag => tag !== 'device.class')
  258. : MOBILE_TAGS
  259. : frontend.some(val => val === project?.platform)
  260. ? FRONTEND_TAGS
  261. : backend.some(val => val === project?.platform)
  262. ? BACKEND_TAGS
  263. : DEFAULT_TAGS
  264. }
  265. event={event}
  266. tagFormatter={TAGS_FORMATTER}
  267. project={project}
  268. isStatisticalDetector={
  269. group.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION ||
  270. group.issueType === IssueType.PERFORMANCE_ENDPOINT_REGRESSION
  271. }
  272. />
  273. )}
  274. {issueTypeConfig.regression.enabled && event && (
  275. <EventThroughput event={event} group={group} />
  276. )}
  277. {renderParticipantData()}
  278. {renderSeenByList()}
  279. </Container>
  280. );
  281. }
  282. const Container = styled('div')`
  283. font-size: ${p => p.theme.fontSizeMedium};
  284. `;
  285. const ExternalIssues = styled('div')`
  286. display: grid;
  287. grid-template-columns: auto max-content;
  288. gap: ${space(2)};
  289. `;
  290. const StyledAvatarList = styled(AvatarList)`
  291. justify-content: flex-end;
  292. padding-left: ${space(0.75)};
  293. `;
  294. const TitleNumber = styled('span')`
  295. font-weight: normal;
  296. `;
  297. // Using 22px + space(1) = space(4)
  298. const SmallerSidebarWrap = styled(SidebarSection.Wrap)`
  299. margin-bottom: 22px;
  300. `;