groupSidebar.tsx 10.0 KB

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