issues.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import ActorAvatar from 'sentry/components/avatar/actorAvatar';
  4. import Count from 'sentry/components/count';
  5. import EventOrGroupExtraDetails from 'sentry/components/eventOrGroupExtraDetails';
  6. import LoadingError from 'sentry/components/loadingError';
  7. import LoadingIndicator from 'sentry/components/loadingIndicator';
  8. import Panel from 'sentry/components/panels/panel';
  9. import PanelHeader from 'sentry/components/panels/panelHeader';
  10. import PanelItem from 'sentry/components/panels/panelItem';
  11. import {IconWrapper} from 'sentry/components/sidebarSection';
  12. import GroupChart from 'sentry/components/stream/groupChart';
  13. import {IconUser} from 'sentry/icons';
  14. import {t, tct, tn} from 'sentry/locale';
  15. import {space} from 'sentry/styles/space';
  16. import type {Group, Organization} from 'sentry/types';
  17. import type {
  18. TraceError,
  19. TraceErrorOrIssue,
  20. TracePerformanceIssue,
  21. } from 'sentry/utils/performance/quickTrace/types';
  22. import {useApiQuery} from 'sentry/utils/queryClient';
  23. import type {
  24. TraceTree,
  25. TraceTreeNode,
  26. } from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  27. import {TraceDrawerComponents} from '../styles';
  28. import {IssueSummary} from './issueSummary';
  29. type IssueProps = {
  30. issue: TraceErrorOrIssue;
  31. organization: Organization;
  32. };
  33. const MAX_DISPLAYED_ISSUES_COUNT = 3;
  34. const TABLE_WIDTH_BREAKPOINTS = {
  35. FIRST: 800,
  36. SECOND: 600,
  37. THIRD: 500,
  38. FOURTH: 400,
  39. };
  40. function Issue(props: IssueProps) {
  41. const {
  42. isLoading,
  43. data: fetchedIssue,
  44. isError,
  45. } = useApiQuery<Group>(
  46. [
  47. `/issues/${props.issue.issue_id}/`,
  48. {
  49. query: {
  50. collapse: 'release',
  51. expand: 'inbox',
  52. },
  53. },
  54. ],
  55. {
  56. staleTime: 2 * 60 * 1000,
  57. }
  58. );
  59. return isLoading ? (
  60. <StyledLoadingIndicatorWrapper>
  61. <LoadingIndicator size={24} mini />
  62. </StyledLoadingIndicatorWrapper>
  63. ) : fetchedIssue ? (
  64. <StyledPanelItem>
  65. <IssueSummaryWrapper>
  66. <IssueSummary
  67. data={fetchedIssue}
  68. organization={props.organization}
  69. event_id={props.issue.event_id}
  70. />
  71. <EventOrGroupExtraDetails data={fetchedIssue} />
  72. </IssueSummaryWrapper>
  73. <ChartWrapper>
  74. <GroupChart
  75. stats={
  76. fetchedIssue.filtered
  77. ? fetchedIssue.filtered.stats?.['24h']
  78. : fetchedIssue.stats?.['24h']
  79. }
  80. secondaryStats={fetchedIssue.filtered ? fetchedIssue.stats?.['24h'] : []}
  81. showSecondaryPoints
  82. showMarkLine
  83. />
  84. </ChartWrapper>
  85. <EventsWrapper>
  86. <PrimaryCount
  87. value={fetchedIssue.filtered ? fetchedIssue.filtered.count : fetchedIssue.count}
  88. />
  89. </EventsWrapper>
  90. <UserCountWrapper>
  91. <PrimaryCount
  92. value={
  93. fetchedIssue.filtered
  94. ? fetchedIssue.filtered.userCount
  95. : fetchedIssue.userCount
  96. }
  97. />
  98. </UserCountWrapper>
  99. <AssineeWrapper>
  100. {fetchedIssue.assignedTo ? (
  101. <ActorAvatar actor={fetchedIssue.assignedTo} hasTooltip size={24} />
  102. ) : (
  103. <StyledIconWrapper>
  104. <IconUser size="md" />
  105. </StyledIconWrapper>
  106. )}
  107. </AssineeWrapper>
  108. </StyledPanelItem>
  109. ) : isError ? (
  110. <LoadingError message={t('Failed to fetch issue')} />
  111. ) : null;
  112. }
  113. type IssueListProps = {
  114. issues: TraceErrorOrIssue[];
  115. node: TraceTreeNode<TraceTree.NodeValue>;
  116. organization: Organization;
  117. };
  118. export function IssueList({issues, node, organization}: IssueListProps) {
  119. const uniqueErrorIssues = useMemo(() => {
  120. const unique: TraceError[] = [];
  121. const seenIssues: Set<number> = new Set();
  122. for (const issue of node.errors) {
  123. if (seenIssues.has(issue.issue_id)) {
  124. continue;
  125. }
  126. seenIssues.add(issue.issue_id);
  127. unique.push(issue);
  128. }
  129. return unique;
  130. // eslint-disable-next-line react-hooks/exhaustive-deps
  131. }, [node, node.errors.size]);
  132. const uniquePerformanceIssues = useMemo(() => {
  133. const unique: TracePerformanceIssue[] = [];
  134. const seenIssues: Set<number> = new Set();
  135. for (const issue of node.performance_issues) {
  136. if (seenIssues.has(issue.issue_id)) {
  137. continue;
  138. }
  139. seenIssues.add(issue.issue_id);
  140. unique.push(issue);
  141. }
  142. return unique;
  143. // eslint-disable-next-line react-hooks/exhaustive-deps
  144. }, [node, node.performance_issues.size]);
  145. const uniqueIssues = useMemo(() => {
  146. return [...uniqueErrorIssues, ...uniquePerformanceIssues];
  147. }, [uniqueErrorIssues, uniquePerformanceIssues]);
  148. if (!issues.length) {
  149. return null;
  150. }
  151. return (
  152. <StyledPanel>
  153. <IssueListHeader
  154. node={node}
  155. errorIssues={uniqueErrorIssues}
  156. performanceIssues={uniquePerformanceIssues}
  157. />
  158. {uniqueIssues.slice(0, MAX_DISPLAYED_ISSUES_COUNT).map((issue, index) => (
  159. <Issue key={index} issue={issue} organization={organization} />
  160. ))}
  161. </StyledPanel>
  162. );
  163. }
  164. function IssueListHeader({
  165. node,
  166. errorIssues,
  167. performanceIssues,
  168. }: {
  169. errorIssues: TraceError[];
  170. node: TraceTreeNode<TraceTree.NodeValue>;
  171. performanceIssues: TracePerformanceIssue[];
  172. }) {
  173. const [singular, plural] = useMemo((): [string, string] => {
  174. const label = [t('Issue'), t('Issues')] as [string, string];
  175. for (const event of errorIssues) {
  176. if (event.level === 'error' || event.level === 'fatal') {
  177. return [t('Error'), t('Errors')];
  178. }
  179. }
  180. return label;
  181. }, [errorIssues]);
  182. return (
  183. <StyledPanelHeader disablePadding>
  184. <IssueHeading>
  185. {errorIssues.length + performanceIssues.length > MAX_DISPLAYED_ISSUES_COUNT
  186. ? tct(`[count]+ issues, [link]`, {
  187. count: MAX_DISPLAYED_ISSUES_COUNT,
  188. link: <StyledIssuesLink node={node}>{t('View All')}</StyledIssuesLink>,
  189. })
  190. : errorIssues.length > 0 && performanceIssues.length === 0
  191. ? tct('[count] [text]', {
  192. count: errorIssues.length,
  193. text: errorIssues.length > 1 ? plural : singular,
  194. })
  195. : performanceIssues.length > 0 && errorIssues.length === 0
  196. ? tct('[count] [text]', {
  197. count: performanceIssues.length,
  198. text: tn(
  199. 'Performance issue',
  200. 'Performance Issues',
  201. performanceIssues.length
  202. ),
  203. })
  204. : tct(
  205. '[errors] [errorsText] and [performance_issues] [performanceIssuesText]',
  206. {
  207. errors: errorIssues.length,
  208. performance_issues: performanceIssues.length,
  209. errorsText: errorIssues.length > 1 ? plural : singular,
  210. performanceIssuesText: tn(
  211. 'performance issue',
  212. 'performance issues',
  213. performanceIssues.length
  214. ),
  215. }
  216. )}
  217. </IssueHeading>
  218. <GraphHeading>{t('Graph')}</GraphHeading>
  219. <EventsHeading>{t('Events')}</EventsHeading>
  220. <UsersHeading>{t('Users')}</UsersHeading>
  221. <AssigneeHeading>{t('Assignee')}</AssigneeHeading>
  222. </StyledPanelHeader>
  223. );
  224. }
  225. const StyledIssuesLink = styled(TraceDrawerComponents.IssuesLink)`
  226. margin-left: ${space(0.5)};
  227. `;
  228. const Heading = styled('div')`
  229. display: flex;
  230. align-self: center;
  231. margin: 0 ${space(2)};
  232. width: 60px;
  233. color: ${p => p.theme.subText};
  234. `;
  235. const IssueHeading = styled(Heading)`
  236. flex: 1;
  237. width: 66.66%;
  238. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  239. width: 50%;
  240. }
  241. `;
  242. const GraphHeading = styled(Heading)`
  243. width: 160px;
  244. display: flex;
  245. justify-content: center;
  246. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FIRST}px) {
  247. display: none;
  248. }
  249. `;
  250. const EventsHeading = styled(Heading)`
  251. @container (width < ${TABLE_WIDTH_BREAKPOINTS.SECOND}px) {
  252. display: none;
  253. }
  254. `;
  255. const UsersHeading = styled(Heading)`
  256. display: flex;
  257. justify-content: center;
  258. @container (width < ${TABLE_WIDTH_BREAKPOINTS.THIRD}px) {
  259. display: none;
  260. }
  261. `;
  262. const AssigneeHeading = styled(Heading)`
  263. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FOURTH}px) {
  264. display: none;
  265. }
  266. `;
  267. const StyledPanel = styled(Panel)`
  268. container-type: inline-size;
  269. `;
  270. const StyledPanelHeader = styled(PanelHeader)`
  271. padding-top: ${space(1)};
  272. padding-bottom: ${space(1)};
  273. `;
  274. const StyledLoadingIndicatorWrapper = styled('div')`
  275. display: flex;
  276. justify-content: center;
  277. width: 100%;
  278. padding: ${space(2)} 0;
  279. height: 84px;
  280. /* Add a border between two rows of loading issue states */
  281. & + & {
  282. border-top: 1px solid ${p => p.theme.border};
  283. }
  284. `;
  285. const StyledIconWrapper = styled(IconWrapper)`
  286. margin: 0;
  287. `;
  288. const IssueSummaryWrapper = styled('div')`
  289. overflow: hidden;
  290. flex: 1;
  291. width: 66.66%;
  292. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  293. width: 50%;
  294. }
  295. `;
  296. const ColumnWrapper = styled('div')`
  297. display: flex;
  298. justify-content: flex-end;
  299. align-self: center;
  300. width: 60px;
  301. margin: 0 ${space(2)};
  302. `;
  303. const EventsWrapper = styled(ColumnWrapper)`
  304. @container (width < ${TABLE_WIDTH_BREAKPOINTS.SECOND}px) {
  305. display: none;
  306. }
  307. `;
  308. const UserCountWrapper = styled(ColumnWrapper)`
  309. @container (width < ${TABLE_WIDTH_BREAKPOINTS.THIRD}px) {
  310. display: none;
  311. }
  312. `;
  313. const AssineeWrapper = styled(ColumnWrapper)`
  314. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FOURTH}px) {
  315. display: none;
  316. }
  317. `;
  318. const ChartWrapper = styled('div')`
  319. width: 200px;
  320. align-self: center;
  321. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FIRST}px) {
  322. display: none;
  323. }
  324. `;
  325. const PrimaryCount = styled(Count)`
  326. font-size: ${p => p.theme.fontSizeLarge};
  327. font-variant-numeric: tabular-nums;
  328. `;
  329. const StyledPanelItem = styled(PanelItem)`
  330. padding-top: ${space(1)};
  331. padding-bottom: ${space(1)};
  332. height: 84px;
  333. `;