sidebar.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import {Component, Fragment} from 'react';
  2. // eslint-disable-next-line no-restricted-imports
  3. import {withRouter, WithRouterProps} from 'react-router';
  4. import styled from '@emotion/styled';
  5. import isEqual from 'lodash/isEqual';
  6. import isObject from 'lodash/isObject';
  7. import keyBy from 'lodash/keyBy';
  8. import pickBy from 'lodash/pickBy';
  9. import {Client} from 'sentry/api';
  10. import Feature from 'sentry/components/acl/feature';
  11. import AvatarList from 'sentry/components/avatar/avatarList';
  12. import DateTime from 'sentry/components/dateTime';
  13. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  14. import ErrorBoundary from 'sentry/components/errorBoundary';
  15. import AssignedTo from 'sentry/components/group/assignedTo';
  16. import ExternalIssueList from 'sentry/components/group/externalIssuesList';
  17. import OwnedBy from 'sentry/components/group/ownedBy';
  18. import GroupReleaseStats from 'sentry/components/group/releaseStats';
  19. import SuggestedOwners from 'sentry/components/group/suggestedOwners/suggestedOwners';
  20. import SuspectReleases from 'sentry/components/group/suspectReleases';
  21. import GroupTagDistributionMeter from 'sentry/components/group/tagDistributionMeter';
  22. import Placeholder from 'sentry/components/placeholder';
  23. import QuestionTooltip from 'sentry/components/questionTooltip';
  24. import * as SidebarSection from 'sentry/components/sidebarSection';
  25. import {t} from 'sentry/locale';
  26. import ConfigStore from 'sentry/stores/configStore';
  27. import space from 'sentry/styles/space';
  28. import {
  29. AvatarUser,
  30. CurrentRelease,
  31. Environment,
  32. Group,
  33. Organization,
  34. Project,
  35. TagWithTopValues,
  36. } from 'sentry/types';
  37. import {Event} from 'sentry/types/event';
  38. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  39. import {getUtcDateString} from 'sentry/utils/dates';
  40. import {userDisplayName} from 'sentry/utils/formatters';
  41. import {isMobilePlatform} from 'sentry/utils/platform';
  42. import withApi from 'sentry/utils/withApi';
  43. import FeatureBadge from '../featureBadge';
  44. import {MOBILE_TAGS, MOBILE_TAGS_FORMATTER, TagFacets} from './tagFacets';
  45. type Props = WithRouterProps & {
  46. api: Client;
  47. environments: Environment[];
  48. group: Group;
  49. organization: Organization;
  50. project: Project;
  51. event?: Event;
  52. };
  53. type State = {
  54. allEnvironmentsGroupData?: Group;
  55. currentRelease?: CurrentRelease;
  56. error?: boolean;
  57. tagsWithTopValues?: Record<string, TagWithTopValues>;
  58. };
  59. class BaseGroupSidebar extends Component<Props, State> {
  60. state: State = {};
  61. componentDidMount() {
  62. this.fetchAllEnvironmentsGroupData();
  63. this.fetchCurrentRelease();
  64. this.fetchTagData();
  65. }
  66. componentDidUpdate(prevProps: Props) {
  67. if (!isEqual(prevProps.environments, this.props.environments)) {
  68. this.fetchTagData();
  69. }
  70. }
  71. trackAssign: React.ComponentProps<typeof AssignedTo>['onAssign'] = () => {
  72. const {group, project, organization, location} = this.props;
  73. const {alert_date, alert_rule_id, alert_type} = location.query;
  74. trackAdvancedAnalyticsEvent('issue_details.action_clicked', {
  75. organization,
  76. project_id: parseInt(project.id, 10),
  77. group_id: parseInt(group.id, 10),
  78. issue_category: group.issueCategory,
  79. action_type: 'assign',
  80. alert_date:
  81. typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined,
  82. alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined,
  83. alert_type: typeof alert_type === 'string' ? alert_type : undefined,
  84. });
  85. };
  86. async fetchAllEnvironmentsGroupData() {
  87. const {group, api} = this.props;
  88. // Fetch group data for all environments since the one passed in props is filtered for the selected environment
  89. // The charts rely on having all environment data as well as the data for the selected env
  90. try {
  91. const query = {collapse: 'release'};
  92. const allEnvironmentsGroupData = await api.requestPromise(`/issues/${group.id}/`, {
  93. query,
  94. });
  95. // eslint-disable-next-line react/no-did-mount-set-state
  96. this.setState({allEnvironmentsGroupData});
  97. } catch {
  98. // eslint-disable-next-line react/no-did-mount-set-state
  99. this.setState({error: true});
  100. }
  101. }
  102. async fetchCurrentRelease() {
  103. const {group, api} = this.props;
  104. try {
  105. const {currentRelease} = await api.requestPromise(
  106. `/issues/${group.id}/current-release/`
  107. );
  108. this.setState({currentRelease});
  109. } catch {
  110. this.setState({error: true});
  111. }
  112. }
  113. async fetchTagData() {
  114. const {api, group} = this.props;
  115. try {
  116. // Fetch the top values for the current group's top tags.
  117. const data = await api.requestPromise(`/issues/${group.id}/tags/`, {
  118. query: pickBy({
  119. key: group.tags.map(tag => tag.key),
  120. environment: this.props.environments.map(env => env.name),
  121. }),
  122. });
  123. this.setState({tagsWithTopValues: keyBy(data, 'key')});
  124. } catch {
  125. this.setState({
  126. tagsWithTopValues: {},
  127. error: true,
  128. });
  129. }
  130. }
  131. renderPluginIssue() {
  132. const issues: React.ReactNode[] = [];
  133. (this.props.group.pluginIssues || []).forEach(plugin => {
  134. const issue = plugin.issue;
  135. // # TODO(dcramer): remove plugin.title check in Sentry 8.22+
  136. if (issue) {
  137. issues.push(
  138. <Fragment key={plugin.slug}>
  139. <span>{`${plugin.shortName || plugin.name || plugin.title}: `}</span>
  140. <a href={issue.url}>{isObject(issue.label) ? issue.label.id : issue.label}</a>
  141. </Fragment>
  142. );
  143. }
  144. });
  145. if (!issues.length) {
  146. return null;
  147. }
  148. return (
  149. <SidebarSection.Wrap>
  150. <SidebarSection.Title>{t('External Issues')}</SidebarSection.Title>
  151. <SidebarSection.Content>
  152. <ExternalIssues>{issues}</ExternalIssues>
  153. </SidebarSection.Content>
  154. </SidebarSection.Wrap>
  155. );
  156. }
  157. renderParticipantData() {
  158. const {participants} = this.props.group;
  159. if (!participants.length) {
  160. return null;
  161. }
  162. return (
  163. <SidebarSection.Wrap>
  164. <StyledSidebarSectionTitle>
  165. {t('Participants (%s)', participants.length)}
  166. <QuestionTooltip
  167. size="sm"
  168. position="top"
  169. color="gray200"
  170. title={t('People who have resolved, ignored, or added a comment')}
  171. />
  172. </StyledSidebarSectionTitle>
  173. <SidebarSection.Content>
  174. <StyledAvatarList users={participants} avatarSize={28} maxVisibleAvatars={13} />
  175. </SidebarSection.Content>
  176. </SidebarSection.Wrap>
  177. );
  178. }
  179. renderSeenByList() {
  180. const {seenBy} = this.props.group;
  181. const activeUser = ConfigStore.get('user');
  182. const displayUsers = seenBy.filter(user => activeUser.id !== user.id);
  183. if (!displayUsers.length) {
  184. return null;
  185. }
  186. return (
  187. <SidebarSection.Wrap>
  188. <StyledSidebarSectionTitle>
  189. {t('Viewers (%s)', displayUsers.length)}{' '}
  190. <QuestionTooltip
  191. size="sm"
  192. position="top"
  193. color="gray200"
  194. title={t('People who have viewed this issue')}
  195. />
  196. </StyledSidebarSectionTitle>
  197. <SidebarSection.Content>
  198. <StyledAvatarList
  199. users={displayUsers}
  200. avatarSize={28}
  201. maxVisibleAvatars={13}
  202. renderTooltip={user => (
  203. <Fragment>
  204. {userDisplayName(user)}
  205. <br />
  206. <DateTime date={(user as AvatarUser).lastSeen} />
  207. </Fragment>
  208. )}
  209. />
  210. </SidebarSection.Content>
  211. </SidebarSection.Wrap>
  212. );
  213. }
  214. render() {
  215. const {event, group, organization, project, environments} = this.props;
  216. const {allEnvironmentsGroupData, currentRelease, tagsWithTopValues} = this.state;
  217. const projectId = project.slug;
  218. const hasIssueActionsV2 = organization.features.includes('issue-actions-v2');
  219. return (
  220. <Container>
  221. {!hasIssueActionsV2 && (
  222. <PageFiltersContainer>
  223. <EnvironmentPageFilter alignDropdown="right" />
  224. </PageFiltersContainer>
  225. )}
  226. <Feature
  227. organization={organization}
  228. features={['issue-details-tag-improvements']}
  229. >
  230. {isMobilePlatform(project.platform) && (
  231. <TagFacets
  232. environments={environments}
  233. groupId={group.id}
  234. tagKeys={MOBILE_TAGS}
  235. event={event}
  236. title={
  237. <Fragment>
  238. {t('Mobile Tag Breakdown')} <FeatureBadge type="alpha" />
  239. </Fragment>
  240. }
  241. tagFormatter={MOBILE_TAGS_FORMATTER}
  242. />
  243. )}
  244. </Feature>
  245. <Feature organization={organization} features={['issue-details-owners']}>
  246. <OwnedBy group={group} project={project} organization={organization} />
  247. <AssignedTo group={group} projectId={project.id} onAssign={this.trackAssign} />
  248. </Feature>
  249. {event && <SuggestedOwners project={project} group={group} event={event} />}
  250. <GroupReleaseStats
  251. organization={organization}
  252. project={project}
  253. environments={environments}
  254. allEnvironments={allEnvironmentsGroupData}
  255. group={group}
  256. currentRelease={currentRelease}
  257. />
  258. <Feature organization={organization} features={['active-release-monitor-alpha']}>
  259. <SuspectReleases group={group} />
  260. </Feature>
  261. {event && (
  262. <ErrorBoundary mini>
  263. <ExternalIssueList project={project} group={group} event={event} />
  264. </ErrorBoundary>
  265. )}
  266. {this.renderPluginIssue()}
  267. <SidebarSection.Wrap>
  268. <SidebarSection.Title>{t('Tag Summary')}</SidebarSection.Title>
  269. <SidebarSection.Content>
  270. {!tagsWithTopValues ? (
  271. <TagPlaceholders>
  272. <Placeholder height="40px" />
  273. <Placeholder height="40px" />
  274. <Placeholder height="40px" />
  275. <Placeholder height="40px" />
  276. </TagPlaceholders>
  277. ) : (
  278. group.tags.map(tag => {
  279. const tagWithTopValues = tagsWithTopValues[tag.key];
  280. const topValues = tagWithTopValues ? tagWithTopValues.topValues : [];
  281. const topValuesTotal = tagWithTopValues
  282. ? tagWithTopValues.totalValues
  283. : 0;
  284. return (
  285. <GroupTagDistributionMeter
  286. key={tag.key}
  287. tag={tag.key}
  288. totalValues={topValuesTotal}
  289. topValues={topValues}
  290. name={tag.name}
  291. organization={organization}
  292. projectId={projectId}
  293. group={group}
  294. />
  295. );
  296. })
  297. )}
  298. {group.tags.length === 0 && (
  299. <p data-test-id="no-tags">
  300. {environments.length
  301. ? t('No tags found in the selected environments')
  302. : t('No tags found')}
  303. </p>
  304. )}
  305. </SidebarSection.Content>
  306. </SidebarSection.Wrap>
  307. {this.renderParticipantData()}
  308. {hasIssueActionsV2 && this.renderSeenByList()}
  309. </Container>
  310. );
  311. }
  312. }
  313. const PageFiltersContainer = styled('div')`
  314. margin-bottom: ${space(2)};
  315. `;
  316. const Container = styled('div')`
  317. font-size: ${p => p.theme.fontSizeMedium};
  318. `;
  319. const TagPlaceholders = styled('div')`
  320. display: grid;
  321. gap: ${space(1)};
  322. grid-auto-flow: row;
  323. `;
  324. const ExternalIssues = styled('div')`
  325. display: grid;
  326. grid-template-columns: auto max-content;
  327. gap: ${space(2)};
  328. `;
  329. const StyledAvatarList = styled(AvatarList)`
  330. justify-content: flex-end;
  331. padding-left: ${space(0.75)};
  332. `;
  333. const StyledSidebarSectionTitle = styled(SidebarSection.Title)`
  334. gap: ${space(1)};
  335. `;
  336. const GroupSidebar = withApi(withRouter(BaseGroupSidebar));
  337. export default GroupSidebar;