groupSidebar.tsx 7.5 KB

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