issueList.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {Fragment, useCallback, useEffect, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import keyBy from 'lodash/keyBy';
  4. import EventOrGroupExtraDetails from 'sentry/components/eventOrGroupExtraDetails';
  5. import EventOrGroupHeader from 'sentry/components/eventOrGroupHeader';
  6. import {PanelTable} from 'sentry/components/panels';
  7. import Placeholder from 'sentry/components/placeholder';
  8. import {DEFAULT_STREAM_GROUP_STATS_PERIOD} from 'sentry/components/stream/group';
  9. import GroupChart from 'sentry/components/stream/groupChart';
  10. import {t} from 'sentry/locale';
  11. import space from 'sentry/styles/space';
  12. import {Group, NewQuery} from 'sentry/types';
  13. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  14. import EventView from 'sentry/utils/discover/eventView';
  15. import theme from 'sentry/utils/theme';
  16. import useApi from 'sentry/utils/useApi';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useMedia from 'sentry/utils/useMedia';
  19. import useOrganization from 'sentry/utils/useOrganization';
  20. import usePageFilters from 'sentry/utils/usePageFilters';
  21. type Props = {
  22. projectId: string;
  23. replayId: string;
  24. };
  25. const columns = [t('Issue'), t('Graph'), t('Events'), t('Users')];
  26. function IssueList(props: Props) {
  27. const organization = useOrganization();
  28. const location = useLocation();
  29. const api = useApi();
  30. const {selection} = usePageFilters();
  31. const isScreenLarge = useMedia(`(min-width: ${theme.breakpoints.large})`);
  32. const [issuesById, setIssuesById] = useState<Record<string, Group>>({});
  33. const [issueStatsById, setIssuesStatsById] = useState<Record<string, Group>>({});
  34. const getEventView = () => {
  35. const eventQueryParams: NewQuery = {
  36. id: '',
  37. name: '',
  38. version: 2,
  39. fields: ['count(issue)', 'issue'],
  40. environment: selection.environments,
  41. projects: selection.projects,
  42. query: `replayId:${props.replayId} AND event.type:error`,
  43. };
  44. const result = EventView.fromNewQueryWithLocation(eventQueryParams, location);
  45. return result;
  46. };
  47. const fetchIssueData = useCallback(async () => {
  48. let issues;
  49. try {
  50. issues = await api.requestPromise(`/organizations/${organization.slug}/issues/`, {
  51. includeAllArgs: true,
  52. query: {
  53. project: props.projectId,
  54. query: `replayId:${props.replayId}`,
  55. },
  56. });
  57. setIssuesById(keyBy(issues[0], 'id'));
  58. } catch (error) {
  59. setIssuesById({});
  60. return;
  61. }
  62. try {
  63. const issuesResults = await api.requestPromise(
  64. `/organizations/${organization.slug}/issues-stats/`,
  65. {
  66. includeAllArgs: true,
  67. query: {
  68. project: props.projectId,
  69. groups: issues[0]?.map(issue => issue.id),
  70. query: `replayId:${props.replayId}`,
  71. },
  72. }
  73. );
  74. setIssuesStatsById(keyBy(issuesResults[0], 'id'));
  75. } catch (error) {
  76. setIssuesStatsById({});
  77. }
  78. }, [api, organization.slug, props.replayId, props.projectId]);
  79. useEffect(() => {
  80. fetchIssueData();
  81. }, [fetchIssueData]);
  82. const renderTableRow = error => {
  83. const matchedIssue = issuesById[error['issue.id']];
  84. const matchedIssueStats = issueStatsById[error['issue.id']];
  85. if (!matchedIssue) {
  86. return null;
  87. }
  88. return (
  89. <Fragment key={matchedIssue.id}>
  90. <IssueDetailsWrapper>
  91. <EventOrGroupHeader
  92. includeLink
  93. data={matchedIssue}
  94. organization={organization}
  95. size="normal"
  96. />
  97. <EventOrGroupExtraDetails
  98. data={{
  99. ...matchedIssue,
  100. firstSeen: matchedIssueStats?.firstSeen || '',
  101. lastSeen: matchedIssueStats?.lastSeen || '',
  102. }}
  103. />
  104. </IssueDetailsWrapper>
  105. {isScreenLarge && (
  106. <ChartWrapper>
  107. {matchedIssueStats?.stats ? (
  108. <GroupChart
  109. statsPeriod={DEFAULT_STREAM_GROUP_STATS_PERIOD}
  110. data={matchedIssueStats}
  111. showSecondaryPoints
  112. showMarkLine
  113. />
  114. ) : (
  115. <Placeholder height="44px" />
  116. )}
  117. </ChartWrapper>
  118. )}
  119. <Item>
  120. {matchedIssueStats?.count ? (
  121. matchedIssueStats?.count
  122. ) : (
  123. <Placeholder height="24px" />
  124. )}
  125. </Item>
  126. <Item>
  127. {matchedIssueStats?.userCount ? (
  128. matchedIssueStats?.userCount
  129. ) : (
  130. <Placeholder height="24px" />
  131. )}
  132. </Item>
  133. </Fragment>
  134. );
  135. };
  136. return (
  137. <DiscoverQuery
  138. eventView={getEventView()}
  139. location={location}
  140. orgSlug={organization.slug}
  141. limit={15}
  142. >
  143. {data => {
  144. return (
  145. <StyledPanelTable
  146. isEmpty={data.tableData?.data.length === 0}
  147. emptyMessage={t('No related Issues found.')}
  148. isLoading={data.isLoading}
  149. headers={
  150. isScreenLarge ? columns : columns.filter(column => column !== t('Graph'))
  151. }
  152. >
  153. {data.tableData?.data.map(renderTableRow) || null}
  154. </StyledPanelTable>
  155. );
  156. }}
  157. </DiscoverQuery>
  158. );
  159. }
  160. const ChartWrapper = styled('div')`
  161. width: 200px;
  162. margin-left: -${space(2)};
  163. padding-left: ${space(0)};
  164. `;
  165. const Item = styled('div')`
  166. display: flex;
  167. align-items: center;
  168. `;
  169. const IssueDetailsWrapper = styled('div')`
  170. overflow: hidden;
  171. line-height: normal;
  172. `;
  173. const StyledPanelTable = styled(PanelTable)`
  174. /* overflow: visible allows the tooltip to be completely shown */
  175. overflow: visible;
  176. grid-template-columns: minmax(1fr, max-content) repeat(3, max-content);
  177. @media (max-width: ${p => p.theme.breakpoints.large}) {
  178. grid-template-columns: minmax(0, 1fr) repeat(2, max-content);
  179. }
  180. `;
  181. export default IssueList;