groupSidebar.tsx 9.8 KB

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