groupSidebar.tsx 7.9 KB

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