issues.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. }, [node]);
  131. const uniquePerformanceIssues = useMemo(() => {
  132. const unique: TracePerformanceIssue[] = [];
  133. const seenIssues: Set<number> = new Set();
  134. for (const issue of node.performance_issues) {
  135. if (seenIssues.has(issue.issue_id)) {
  136. continue;
  137. }
  138. seenIssues.add(issue.issue_id);
  139. unique.push(issue);
  140. }
  141. return unique;
  142. }, [node]);
  143. const uniqueIssues = useMemo(() => {
  144. return [...uniqueErrorIssues, ...uniquePerformanceIssues];
  145. }, [uniqueErrorIssues, uniquePerformanceIssues]);
  146. if (!issues.length) {
  147. return null;
  148. }
  149. return (
  150. <StyledPanel>
  151. <IssueListHeader
  152. node={node}
  153. errorIssues={uniqueErrorIssues}
  154. performanceIssues={uniquePerformanceIssues}
  155. />
  156. {uniqueIssues.slice(0, MAX_DISPLAYED_ISSUES_COUNT).map((issue, index) => (
  157. <Issue key={index} issue={issue} organization={organization} />
  158. ))}
  159. </StyledPanel>
  160. );
  161. }
  162. function IssueListHeader({
  163. node,
  164. errorIssues,
  165. performanceIssues,
  166. }: {
  167. errorIssues: TraceError[];
  168. node: TraceTreeNode<TraceTree.NodeValue>;
  169. performanceIssues: TracePerformanceIssue[];
  170. }) {
  171. const [singular, plural] = useMemo((): [string, string] => {
  172. const label = [t('Issue'), t('Issues')] as [string, string];
  173. for (const event of errorIssues) {
  174. if (event.level === 'error' || event.level === 'fatal') {
  175. return [t('Error'), t('Errors')];
  176. }
  177. }
  178. return label;
  179. }, [errorIssues]);
  180. return (
  181. <StyledPanelHeader disablePadding>
  182. <IssueHeading>
  183. {errorIssues.length + performanceIssues.length > MAX_DISPLAYED_ISSUES_COUNT
  184. ? tct(`[count]+ issues, [link]`, {
  185. count: MAX_DISPLAYED_ISSUES_COUNT,
  186. link: <StyledIssuesLink node={node}>{t('View All')}</StyledIssuesLink>,
  187. })
  188. : errorIssues.length > 0 && performanceIssues.length === 0
  189. ? tct('[count] [text]', {
  190. count: errorIssues.length,
  191. text: errorIssues.length > 1 ? plural : singular,
  192. })
  193. : performanceIssues.length > 0 && errorIssues.length === 0
  194. ? tct('[count] [text]', {
  195. count: performanceIssues.length,
  196. text: tn(
  197. 'Performance issue',
  198. 'Performance Issues',
  199. performanceIssues.length
  200. ),
  201. })
  202. : tct(
  203. '[errors] [errorsText] and [performance_issues] [performanceIssuesText]',
  204. {
  205. errors: errorIssues.length,
  206. performance_issues: performanceIssues.length,
  207. errorsText: errorIssues.length > 1 ? plural : singular,
  208. performanceIssuesText: tn(
  209. 'performance issue',
  210. 'performance issues',
  211. performanceIssues.length
  212. ),
  213. }
  214. )}
  215. </IssueHeading>
  216. <GraphHeading>{t('Graph')}</GraphHeading>
  217. <EventsHeading>{t('Events')}</EventsHeading>
  218. <UsersHeading>{t('Users')}</UsersHeading>
  219. <AssigneeHeading>{t('Assignee')}</AssigneeHeading>
  220. </StyledPanelHeader>
  221. );
  222. }
  223. const StyledIssuesLink = styled(TraceDrawerComponents.IssuesLink)`
  224. margin-left: ${space(0.5)};
  225. `;
  226. const Heading = styled('div')`
  227. display: flex;
  228. align-self: center;
  229. margin: 0 ${space(2)};
  230. width: 60px;
  231. color: ${p => p.theme.subText};
  232. `;
  233. const IssueHeading = styled(Heading)`
  234. flex: 1;
  235. width: 66.66%;
  236. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  237. width: 50%;
  238. }
  239. `;
  240. const GraphHeading = styled(Heading)`
  241. width: 160px;
  242. display: flex;
  243. justify-content: center;
  244. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FIRST}px) {
  245. display: none;
  246. }
  247. `;
  248. const EventsHeading = styled(Heading)`
  249. @container (width < ${TABLE_WIDTH_BREAKPOINTS.SECOND}px) {
  250. display: none;
  251. }
  252. `;
  253. const UsersHeading = styled(Heading)`
  254. display: flex;
  255. justify-content: center;
  256. @container (width < ${TABLE_WIDTH_BREAKPOINTS.THIRD}px) {
  257. display: none;
  258. }
  259. `;
  260. const AssigneeHeading = styled(Heading)`
  261. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FOURTH}px) {
  262. display: none;
  263. }
  264. `;
  265. const StyledPanel = styled(Panel)`
  266. container-type: inline-size;
  267. `;
  268. const StyledPanelHeader = styled(PanelHeader)`
  269. padding-top: ${space(1)};
  270. padding-bottom: ${space(1)};
  271. `;
  272. const StyledLoadingIndicatorWrapper = styled('div')`
  273. display: flex;
  274. justify-content: center;
  275. width: 100%;
  276. padding: ${space(2)} 0;
  277. height: 84px;
  278. /* Add a border between two rows of loading issue states */
  279. & + & {
  280. border-top: 1px solid ${p => p.theme.border};
  281. }
  282. `;
  283. const StyledIconWrapper = styled(IconWrapper)`
  284. margin: 0;
  285. `;
  286. const IssueSummaryWrapper = styled('div')`
  287. overflow: hidden;
  288. flex: 1;
  289. width: 66.66%;
  290. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  291. width: 50%;
  292. }
  293. `;
  294. const ColumnWrapper = styled('div')`
  295. display: flex;
  296. justify-content: flex-end;
  297. align-self: center;
  298. width: 60px;
  299. margin: 0 ${space(2)};
  300. `;
  301. const EventsWrapper = styled(ColumnWrapper)`
  302. @container (width < ${TABLE_WIDTH_BREAKPOINTS.SECOND}px) {
  303. display: none;
  304. }
  305. `;
  306. const UserCountWrapper = styled(ColumnWrapper)`
  307. @container (width < ${TABLE_WIDTH_BREAKPOINTS.THIRD}px) {
  308. display: none;
  309. }
  310. `;
  311. const AssineeWrapper = styled(ColumnWrapper)`
  312. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FOURTH}px) {
  313. display: none;
  314. }
  315. `;
  316. const ChartWrapper = styled('div')`
  317. width: 200px;
  318. align-self: center;
  319. @container (width < ${TABLE_WIDTH_BREAKPOINTS.FIRST}px) {
  320. display: none;
  321. }
  322. `;
  323. const PrimaryCount = styled(Count)`
  324. font-size: ${p => p.theme.fontSizeLarge};
  325. font-variant-numeric: tabular-nums;
  326. `;
  327. const StyledPanelItem = styled(PanelItem)`
  328. padding-top: ${space(1)};
  329. padding-bottom: ${space(1)};
  330. height: 84px;
  331. `;