issues.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import ActorAvatar from 'sentry/components/avatar/actorAvatar';
  5. import Count from 'sentry/components/count';
  6. import EventOrGroupExtraDetails from 'sentry/components/eventOrGroupExtraDetails';
  7. import Link from 'sentry/components/links/link';
  8. import LoadingError from 'sentry/components/loadingError';
  9. import LoadingIndicator from 'sentry/components/loadingIndicator';
  10. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  11. import Panel from 'sentry/components/panels/panel';
  12. import PanelHeader from 'sentry/components/panels/panelHeader';
  13. import PanelItem from 'sentry/components/panels/panelItem';
  14. import {IconWrapper} from 'sentry/components/sidebarSection';
  15. import GroupChart from 'sentry/components/stream/groupChart';
  16. import {IconUser} from 'sentry/icons';
  17. import {t, tct, tn} from 'sentry/locale';
  18. import {space} from 'sentry/styles/space';
  19. import type {Group, Organization} from 'sentry/types';
  20. import type {TraceErrorOrIssue} from 'sentry/utils/performance/quickTrace/types';
  21. import {useApiQuery} from 'sentry/utils/queryClient';
  22. import {decodeScalar} from 'sentry/utils/queryString';
  23. import useOrganization from 'sentry/utils/useOrganization';
  24. import {useParams} from 'sentry/utils/useParams';
  25. import type {
  26. TraceTree,
  27. TraceTreeNode,
  28. } from 'sentry/views/performance/newTraceDetails/traceTree';
  29. import {
  30. isAutogroupedNode,
  31. isMissingInstrumentationNode,
  32. isSpanNode,
  33. isTraceErrorNode,
  34. isTransactionNode,
  35. } from '../../../guards';
  36. import {IssueSummary} from './issueSummary';
  37. type IssueProps = {
  38. issue: TraceErrorOrIssue;
  39. organization: Organization;
  40. };
  41. const MAX_DISPLAYED_ISSUES_COUNT = 10;
  42. function Issue(props: IssueProps) {
  43. const {
  44. isLoading,
  45. data: fetchedIssue,
  46. isError,
  47. } = useApiQuery<Group>(
  48. [
  49. `/issues/${props.issue.issue_id}/`,
  50. {
  51. query: {
  52. collapse: 'release',
  53. expand: 'inbox',
  54. },
  55. },
  56. ],
  57. {
  58. staleTime: 2 * 60 * 1000,
  59. }
  60. );
  61. return isLoading ? (
  62. <StyledLoadingIndicatorWrapper>
  63. <LoadingIndicator size={24} mini />
  64. </StyledLoadingIndicatorWrapper>
  65. ) : fetchedIssue ? (
  66. <StyledPanelItem>
  67. <IssueSummaryWrapper>
  68. <IssueSummary
  69. data={fetchedIssue}
  70. organization={props.organization}
  71. event_id={props.issue.event_id}
  72. />
  73. <EventOrGroupExtraDetails data={fetchedIssue} />
  74. </IssueSummaryWrapper>
  75. <ChartWrapper>
  76. <GroupChart
  77. statsPeriod={'24h'}
  78. data={fetchedIssue}
  79. showSecondaryPoints
  80. showMarkLine
  81. />
  82. </ChartWrapper>
  83. <ColumnWrapper>
  84. <PrimaryCount
  85. value={fetchedIssue.filtered ? fetchedIssue.filtered.count : fetchedIssue.count}
  86. />
  87. </ColumnWrapper>
  88. <ColumnWrapper>
  89. <PrimaryCount
  90. value={
  91. fetchedIssue.filtered
  92. ? fetchedIssue.filtered.userCount
  93. : fetchedIssue.userCount
  94. }
  95. />
  96. </ColumnWrapper>
  97. <ColumnWrapper>
  98. {fetchedIssue.assignedTo ? (
  99. <ActorAvatar actor={fetchedIssue.assignedTo} hasTooltip size={24} />
  100. ) : (
  101. <StyledIconWrapper>
  102. <IconUser size="md" />
  103. </StyledIconWrapper>
  104. )}
  105. </ColumnWrapper>
  106. </StyledPanelItem>
  107. ) : isError ? (
  108. <LoadingError message={t('Failed to fetch issue')} />
  109. ) : null;
  110. }
  111. type IssueListProps = {
  112. issues: TraceErrorOrIssue[];
  113. node: TraceTreeNode<TraceTree.NodeValue>;
  114. organization: Organization;
  115. };
  116. export function IssueList({issues, node, organization}: IssueListProps) {
  117. if (!issues.length) {
  118. return null;
  119. }
  120. return (
  121. <StyledPanel>
  122. <IssueListHeader node={node} />
  123. {issues.slice(0, MAX_DISPLAYED_ISSUES_COUNT).map((issue, index) => (
  124. <Issue key={index} issue={issue} organization={organization} />
  125. ))}
  126. </StyledPanel>
  127. );
  128. }
  129. function getSearchParamFromNode(node: TraceTreeNode<TraceTree.NodeValue>) {
  130. if (isTransactionNode(node) || isTraceErrorNode(node)) {
  131. return `id:${node.value.event_id}`;
  132. }
  133. // Issues associated to a span or autogrouped node are not queryable, so we query by
  134. // the parent transaction's id
  135. const parentTransaction = node.parent_transaction;
  136. if ((isSpanNode(node) || isAutogroupedNode(node)) && parentTransaction) {
  137. return `id:${parentTransaction.value.event_id}`;
  138. }
  139. if (isMissingInstrumentationNode(node)) {
  140. throw new Error('Missing instrumentation nodes do not have associated issues');
  141. }
  142. return '';
  143. }
  144. function IssueListHeader({node}: {node: TraceTreeNode<TraceTree.NodeValue>}) {
  145. const {errors, performance_issues} = node;
  146. const organization = useOrganization();
  147. const params = useParams<{traceSlug?: string}>();
  148. const traceSlug = params.traceSlug?.trim() ?? '';
  149. const dateSelection = useMemo(() => {
  150. const normalizedParams = normalizeDateTimeParams(qs.parse(window.location.search), {
  151. allowAbsolutePageDatetime: true,
  152. });
  153. const start = decodeScalar(normalizedParams.start);
  154. const end = decodeScalar(normalizedParams.end);
  155. const statsPeriod = decodeScalar(normalizedParams.statsPeriod);
  156. return {start, end, statsPeriod};
  157. }, []);
  158. return (
  159. <StyledPanelHeader disablePadding>
  160. <IssueHeading>
  161. {errors.size + performance_issues.size > MAX_DISPLAYED_ISSUES_COUNT
  162. ? tct(`[count]+ issues, [link]`, {
  163. count: MAX_DISPLAYED_ISSUES_COUNT,
  164. link: (
  165. <StyledLink
  166. to={{
  167. pathname: `/organizations/${organization.slug}/issues/`,
  168. query: {
  169. query: `trace:${traceSlug} ${getSearchParamFromNode(node)}`,
  170. start: dateSelection.start,
  171. end: dateSelection.end,
  172. statsPeriod: dateSelection.statsPeriod,
  173. },
  174. }}
  175. >
  176. {t('View All')}
  177. </StyledLink>
  178. ),
  179. })
  180. : errors.size > 0 && performance_issues.size === 0
  181. ? tct('[count] [text]', {
  182. count: errors.size,
  183. text: tn('Error', 'Errors', errors.size),
  184. })
  185. : performance_issues.size > 0 && errors.size === 0
  186. ? tct('[count] [text]', {
  187. count: performance_issues.size,
  188. text: tn(
  189. 'Performance issue',
  190. 'Performance Issues',
  191. performance_issues.size
  192. ),
  193. })
  194. : tct(
  195. '[errors] [errorsText] and [performance_issues] [performanceIssuesText]',
  196. {
  197. errors: errors.size,
  198. performance_issues: performance_issues.size,
  199. errorsText: tn('Error', 'Errors', errors.size),
  200. performanceIssuesText: tn(
  201. 'performance issue',
  202. 'performance issues',
  203. performance_issues.size
  204. ),
  205. }
  206. )}
  207. </IssueHeading>
  208. <GraphHeading>{t('Graph')}</GraphHeading>
  209. <Heading>{t('Events')}</Heading>
  210. <UsersHeading>{t('Users')}</UsersHeading>
  211. <Heading>{t('Assignee')}</Heading>
  212. </StyledPanelHeader>
  213. );
  214. }
  215. const StyledLink = styled(Link)`
  216. margin-left: ${space(0.5)};
  217. `;
  218. const Heading = styled('div')`
  219. display: flex;
  220. align-self: center;
  221. margin: 0 ${space(2)};
  222. width: 60px;
  223. color: ${p => p.theme.subText};
  224. `;
  225. const IssueHeading = styled(Heading)`
  226. flex: 1;
  227. width: 66.66%;
  228. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  229. width: 50%;
  230. }
  231. `;
  232. const GraphHeading = styled(Heading)`
  233. width: 160px;
  234. display: flex;
  235. justify-content: center;
  236. `;
  237. const UsersHeading = styled(Heading)`
  238. display: flex;
  239. justify-content: center;
  240. `;
  241. const StyledPanel = styled(Panel)`
  242. margin-bottom: 0;
  243. border: 1px solid ${p => p.theme.red200};
  244. `;
  245. const StyledPanelHeader = styled(PanelHeader)`
  246. padding-top: ${space(1)};
  247. padding-bottom: ${space(1)};
  248. border-bottom: 1px solid ${p => p.theme.red200};
  249. `;
  250. const StyledLoadingIndicatorWrapper = styled('div')`
  251. display: flex;
  252. justify-content: center;
  253. width: 100%;
  254. padding: ${space(2)} 0;
  255. height: 84px;
  256. /* Add a border between two rows of loading issue states */
  257. & + & {
  258. border-top: 1px solid ${p => p.theme.border};
  259. }
  260. `;
  261. const StyledIconWrapper = styled(IconWrapper)`
  262. margin: 0;
  263. `;
  264. const IssueSummaryWrapper = styled('div')`
  265. overflow: hidden;
  266. flex: 1;
  267. width: 66.66%;
  268. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  269. width: 50%;
  270. }
  271. `;
  272. const ChartWrapper = styled('div')`
  273. width: 200px;
  274. align-self: center;
  275. `;
  276. const ColumnWrapper = styled('div')`
  277. display: flex;
  278. justify-content: flex-end;
  279. align-self: center;
  280. width: 60px;
  281. margin: 0 ${space(2)};
  282. `;
  283. const PrimaryCount = styled(Count)`
  284. font-size: ${p => p.theme.fontSizeLarge};
  285. font-variant-numeric: tabular-nums;
  286. `;
  287. const StyledPanelItem = styled(PanelItem)`
  288. padding-top: ${space(1)};
  289. padding-bottom: ${space(1)};
  290. height: 84px;
  291. `;