groupSidebar.tsx 7.3 KB

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