groupSidebar.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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} 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 {isMobilePlatform} from 'sentry/utils/platform';
  41. import {useApiQuery} from 'sentry/utils/queryClient';
  42. import {useLocation} from 'sentry/utils/useLocation';
  43. import {getGroupDetailsQueryData} from 'sentry/views/issueDetails/utils';
  44. type Props = {
  45. environments: string[];
  46. group: Group;
  47. organization: Organization;
  48. project: Project;
  49. event?: Event;
  50. };
  51. function useFetchAllEnvsGroupData(organization: OrganizationSummary, group: Group) {
  52. return useApiQuery<Group>(
  53. [
  54. `/organizations/${organization.slug}/issues/${group.id}/`,
  55. {query: getGroupDetailsQueryData()},
  56. ],
  57. {
  58. staleTime: 30000,
  59. cacheTime: 30000,
  60. }
  61. );
  62. }
  63. function useFetchCurrentRelease(organization: OrganizationSummary, group: Group) {
  64. return useApiQuery<CurrentRelease>(
  65. [`/organizations/${organization.slug}/issues/${group.id}/current-release/`],
  66. {
  67. staleTime: 30000,
  68. cacheTime: 30000,
  69. }
  70. );
  71. }
  72. export default function GroupSidebar({
  73. event,
  74. group,
  75. project,
  76. organization,
  77. environments,
  78. }: Props) {
  79. const {data: allEnvironmentsGroupData} = useFetchAllEnvsGroupData(organization, group);
  80. const {data: currentRelease} = useFetchCurrentRelease(organization, group);
  81. const location = useLocation();
  82. const trackAssign: OnAssignCallback = (type, _assignee, suggestedAssignee) => {
  83. const {alert_date, alert_rule_id, alert_type} = location.query;
  84. trackAnalytics('issue_details.action_clicked', {
  85. organization,
  86. project_id: parseInt(project.id, 10),
  87. action_type: 'assign',
  88. assigned_type: type,
  89. assigned_suggestion_reason: suggestedAssignee?.suggestedReason,
  90. alert_date:
  91. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  92. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  93. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  94. ...getAnalyticsDataForGroup(group),
  95. });
  96. };
  97. const renderPluginIssue = () => {
  98. const issues: React.ReactNode[] = [];
  99. (group.pluginIssues || []).forEach(plugin => {
  100. const issue = plugin.issue;
  101. // # TODO(dcramer): remove plugin.title check in Sentry 8.22+
  102. if (issue) {
  103. issues.push(
  104. <Fragment key={plugin.slug}>
  105. <span>{`${plugin.shortName || plugin.name || plugin.title}: `}</span>
  106. <a href={issue.url}>{isObject(issue.label) ? issue.label.id : issue.label}</a>
  107. </Fragment>
  108. );
  109. }
  110. });
  111. if (!issues.length) {
  112. return null;
  113. }
  114. return (
  115. <SidebarSection.Wrap>
  116. <SidebarSection.Title>{t('External Issues')}</SidebarSection.Title>
  117. <SidebarSection.Content>
  118. <ExternalIssues>{issues}</ExternalIssues>
  119. </SidebarSection.Content>
  120. </SidebarSection.Wrap>
  121. );
  122. };
  123. const renderParticipantData = () => {
  124. const {participants} = group;
  125. if (!participants.length) {
  126. return null;
  127. }
  128. const userParticipants = participants.filter(
  129. (p): p is UserParticipant => p.type === 'user'
  130. );
  131. const teamParticipants = participants.filter(
  132. (p): p is TeamParticipant => p.type === 'team'
  133. );
  134. return (
  135. <SidebarSection.Wrap>
  136. <SidebarSection.Title>
  137. {t('Participants (%s)', participants.length)}
  138. <QuestionTooltip
  139. size="xs"
  140. position="top"
  141. title={t('People who have resolved, ignored, or added a comment')}
  142. />
  143. </SidebarSection.Title>
  144. <SidebarSection.Content>
  145. <StyledAvatarList
  146. users={userParticipants}
  147. teams={teamParticipants}
  148. avatarSize={28}
  149. maxVisibleAvatars={13}
  150. typeAvatars="participants"
  151. />
  152. </SidebarSection.Content>
  153. </SidebarSection.Wrap>
  154. );
  155. };
  156. const renderSeenByList = () => {
  157. const {seenBy} = group;
  158. const activeUser = ConfigStore.get('user');
  159. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  160. if (!displayUsers.length) {
  161. return null;
  162. }
  163. return (
  164. <SidebarSection.Wrap>
  165. <SidebarSection.Title>
  166. {t('Viewers (%s)', displayUsers.length)}{' '}
  167. <QuestionTooltip
  168. size="xs"
  169. position="top"
  170. title={t('People who have viewed this issue')}
  171. />
  172. </SidebarSection.Title>
  173. <SidebarSection.Content>
  174. <StyledAvatarList
  175. users={displayUsers}
  176. avatarSize={28}
  177. maxVisibleAvatars={13}
  178. renderTooltip={user => (
  179. <Fragment>
  180. {userDisplayName(user)}
  181. <br />
  182. <DateTime date={(user as AvatarUser).lastSeen} />
  183. </Fragment>
  184. )}
  185. />
  186. </SidebarSection.Content>
  187. </SidebarSection.Wrap>
  188. );
  189. };
  190. return (
  191. <Container>
  192. <AssignedTo group={group} event={event} project={project} onAssign={trackAssign} />
  193. {group.issueType !== IssueType.PERFORMANCE_DURATION_REGRESSION && (
  194. <GroupReleaseStats
  195. organization={organization}
  196. project={project}
  197. environments={environments}
  198. allEnvironments={allEnvironmentsGroupData}
  199. group={group}
  200. currentRelease={currentRelease}
  201. />
  202. )}
  203. {event && (
  204. <ErrorBoundary mini>
  205. <ExternalIssueList project={project} group={group} event={event} />
  206. </ErrorBoundary>
  207. )}
  208. {renderPluginIssue()}
  209. <TagFacets
  210. environments={environments}
  211. groupId={group.id}
  212. tagKeys={
  213. isMobilePlatform(project?.platform)
  214. ? !organization.features.includes('device-classification')
  215. ? MOBILE_TAGS.filter(tag => tag !== 'device.class')
  216. : MOBILE_TAGS
  217. : frontend.some(val => val === project?.platform)
  218. ? FRONTEND_TAGS
  219. : backend.some(val => val === project?.platform)
  220. ? BACKEND_TAGS
  221. : DEFAULT_TAGS
  222. }
  223. event={event}
  224. tagFormatter={TAGS_FORMATTER}
  225. project={project}
  226. isStatisticalDetector={
  227. group.issueType === IssueType.PERFORMANCE_DURATION_REGRESSION
  228. }
  229. />
  230. {renderParticipantData()}
  231. {renderSeenByList()}
  232. </Container>
  233. );
  234. }
  235. const Container = styled('div')`
  236. font-size: ${p => p.theme.fontSizeMedium};
  237. `;
  238. const ExternalIssues = styled('div')`
  239. display: grid;
  240. grid-template-columns: auto max-content;
  241. gap: ${space(2)};
  242. `;
  243. const StyledAvatarList = styled(AvatarList)`
  244. justify-content: flex-end;
  245. padding-left: ${space(0.75)};
  246. `;