groupSidebar.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 hasParticipantsFeature = organization.features.includes('participants-purge');
  128. const renderParticipantData = () => {
  129. const {participants} = group;
  130. if (!participants.length) {
  131. return null;
  132. }
  133. const userParticipants = participants.filter(
  134. (p): p is UserParticipant => p.type === 'user'
  135. );
  136. const teamParticipants = participants.filter(
  137. (p): p is TeamParticipant => p.type === 'team'
  138. );
  139. const getParticipantTitle = (): React.ReactNode => {
  140. if (!hasParticipantsFeature) {
  141. return `${group.participants.length}`;
  142. }
  143. const individualText = tn(
  144. '%s Individual',
  145. '%s Individuals',
  146. userParticipants.length
  147. );
  148. const teamText = tn('%s Team', '%s Teams', teamParticipants.length);
  149. if (teamParticipants.length === 0) {
  150. return individualText;
  151. }
  152. if (userParticipants.length === 0) {
  153. return teamText;
  154. }
  155. return (
  156. <Fragment>
  157. {teamText}, {individualText}
  158. </Fragment>
  159. );
  160. };
  161. const avatars = (
  162. <StyledAvatarList
  163. users={userParticipants}
  164. teams={teamParticipants}
  165. avatarSize={28}
  166. maxVisibleAvatars={hasParticipantsFeature ? 12 : 13}
  167. typeAvatars="participants"
  168. />
  169. );
  170. return (
  171. <SmallerSidebarWrap>
  172. <SidebarSection.Title>
  173. {t('Participants')} <TitleNumber>({getParticipantTitle()})</TitleNumber>
  174. <QuestionTooltip
  175. size="xs"
  176. position="top"
  177. title={t(
  178. 'People who have been assigned, resolved, unresolved, archived, bookmarked, subscribed, or added a comment'
  179. )}
  180. />
  181. </SidebarSection.Title>
  182. <SidebarSection.Content>
  183. {hasParticipantsFeature ? (
  184. <ParticipantList
  185. users={userParticipants}
  186. teams={teamParticipants}
  187. description={t('participants')}
  188. >
  189. {avatars}
  190. </ParticipantList>
  191. ) : (
  192. <StyledAvatarList
  193. users={userParticipants}
  194. teams={teamParticipants}
  195. avatarSize={28}
  196. maxVisibleAvatars={13}
  197. typeAvatars="participants"
  198. />
  199. )}
  200. </SidebarSection.Content>
  201. </SmallerSidebarWrap>
  202. );
  203. };
  204. const renderSeenByList = () => {
  205. const {seenBy} = group;
  206. const activeUser = ConfigStore.get('user');
  207. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  208. if (!displayUsers.length) {
  209. return null;
  210. }
  211. const avatars = (
  212. <StyledAvatarList
  213. users={displayUsers}
  214. avatarSize={28}
  215. maxVisibleAvatars={hasParticipantsFeature ? 12 : 13}
  216. renderTooltip={user => (
  217. <Fragment>
  218. {userDisplayName(user)}
  219. <br />
  220. <DateTime date={(user as AvatarUser).lastSeen} />
  221. </Fragment>
  222. )}
  223. />
  224. );
  225. return (
  226. <SmallerSidebarWrap>
  227. <SidebarSection.Title>
  228. {t('Viewers')}
  229. <TitleNumber>({displayUsers.length})</TitleNumber>
  230. <QuestionTooltip
  231. size="xs"
  232. position="top"
  233. title={t('People who have viewed this issue')}
  234. />
  235. </SidebarSection.Title>
  236. <SidebarSection.Content>
  237. {hasParticipantsFeature ? (
  238. <ParticipantList users={displayUsers} teams={[]} description={t('users')}>
  239. {avatars}
  240. </ParticipantList>
  241. ) : (
  242. avatars
  243. )}
  244. </SidebarSection.Content>
  245. </SmallerSidebarWrap>
  246. );
  247. };
  248. const issueTypeConfig = getConfigForIssueType(group);
  249. return (
  250. <Container>
  251. <AssignedTo group={group} event={event} project={project} onAssign={trackAssign} />
  252. {issueTypeConfig.stats.enabled && (
  253. <GroupReleaseStats
  254. organization={organization}
  255. project={project}
  256. environments={environments}
  257. allEnvironments={allEnvironmentsGroupData}
  258. group={group}
  259. currentRelease={currentRelease}
  260. />
  261. )}
  262. {event && (
  263. <ErrorBoundary mini>
  264. <ExternalIssueList project={project} group={group} event={event} />
  265. </ErrorBoundary>
  266. )}
  267. {renderPluginIssue()}
  268. {issueTypeConfig.tags.enabled && (
  269. <TagFacets
  270. environments={environments}
  271. groupId={group.id}
  272. tagKeys={
  273. isMobilePlatform(project?.platform)
  274. ? !organization.features.includes('device-classification')
  275. ? MOBILE_TAGS.filter(tag => tag !== 'device.class')
  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. {renderParticipantData()}
  296. {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: normal;
  314. `;
  315. // Using 22px + space(1) = space(4)
  316. const SmallerSidebarWrap = styled(SidebarSection.Wrap)`
  317. margin-bottom: 22px;
  318. `;