issueList.tsx 6.0 KB

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