issues.tsx 8.3 KB

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