groupSidebar.tsx 9.9 KB

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