groupEvents.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import {Component} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import pick from 'lodash/pick';
  5. import {Client} from 'sentry/api';
  6. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  7. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  8. import EventSearchBar from 'sentry/components/events/searchBar';
  9. import EventsTable from 'sentry/components/eventsTable/eventsTable';
  10. import * as Layout from 'sentry/components/layouts/thirds';
  11. import LoadingError from 'sentry/components/loadingError';
  12. import LoadingIndicator from 'sentry/components/loadingIndicator';
  13. import Pagination from 'sentry/components/pagination';
  14. import {Panel, PanelBody} from 'sentry/components/panels';
  15. import SearchBar from 'sentry/components/searchBar';
  16. import {t} from 'sentry/locale';
  17. import space from 'sentry/styles/space';
  18. import {Group, IssueCategory, Organization} from 'sentry/types';
  19. import {Event} from 'sentry/types/event';
  20. import parseApiError from 'sentry/utils/parseApiError';
  21. import withApi from 'sentry/utils/withApi';
  22. import withOrganization from 'sentry/utils/withOrganization';
  23. import AllEventsTable from './allEventsTable';
  24. type Props = {
  25. api: Client;
  26. group: Group;
  27. organization: Organization;
  28. } & RouteComponentProps<{groupId: string; orgId: string}, {}>;
  29. type State = {
  30. error: string | false;
  31. eventList: Event[];
  32. loading: boolean;
  33. pageLinks: string;
  34. query: string;
  35. renderNewAllEventsTab: boolean;
  36. };
  37. const excludedTags = ['environment', 'issue', 'issue.id', 'performance.issues_ids'];
  38. class GroupEvents extends Component<Props, State> {
  39. constructor(props: Props) {
  40. super(props);
  41. const queryParams = this.props.location.query;
  42. const renderNewAllEventsTab =
  43. !!this.props.group.id &&
  44. this.props.organization.features.includes('performance-issues-all-events-tab');
  45. this.state = {
  46. eventList: [],
  47. loading: true,
  48. error: false,
  49. pageLinks: '',
  50. query: queryParams.query || '',
  51. renderNewAllEventsTab,
  52. };
  53. }
  54. UNSAFE_componentWillMount() {
  55. this.fetchData();
  56. }
  57. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  58. if (this.props.location.search !== nextProps.location.search) {
  59. const queryParams = nextProps.location.query;
  60. this.setState(
  61. {
  62. query: queryParams.query,
  63. },
  64. this.fetchData
  65. );
  66. }
  67. }
  68. handleSearch = (query: string) => {
  69. const targetQueryParams = {...this.props.location.query};
  70. targetQueryParams.query = query;
  71. const {groupId, orgId} = this.props.params;
  72. browserHistory.push({
  73. pathname: `/organizations/${orgId}/issues/${groupId}/events/`,
  74. query: targetQueryParams,
  75. });
  76. };
  77. fetchData = () => {
  78. this.setState({
  79. loading: true,
  80. error: false,
  81. });
  82. const query = {
  83. ...pick(this.props.location.query, ['cursor', 'environment']),
  84. limit: 50,
  85. query: this.state.query,
  86. };
  87. this.props.api.request(`/issues/${this.props.params.groupId}/events/`, {
  88. query,
  89. method: 'GET',
  90. success: (data, _, resp) => {
  91. this.setState({
  92. eventList: data,
  93. error: false,
  94. loading: false,
  95. pageLinks: resp?.getResponseHeader('Link') ?? '',
  96. });
  97. },
  98. error: err => {
  99. this.setState({
  100. error: parseApiError(err),
  101. loading: false,
  102. });
  103. },
  104. });
  105. };
  106. renderNoQueryResults() {
  107. return (
  108. <EmptyStateWarning>
  109. <p>{t('Sorry, no events match your search query.')}</p>
  110. </EmptyStateWarning>
  111. );
  112. }
  113. renderEmpty() {
  114. return (
  115. <EmptyStateWarning>
  116. <p>{t("There don't seem to be any events yet.")}</p>
  117. </EmptyStateWarning>
  118. );
  119. }
  120. renderNewAllEventsTab() {
  121. return (
  122. <AllEventsTable
  123. issueId={this.props.group.id}
  124. isPerfIssue={this.props.group.issueCategory === IssueCategory.PERFORMANCE}
  125. location={this.props.location}
  126. organization={this.props.organization}
  127. excludedTags={excludedTags}
  128. />
  129. );
  130. }
  131. renderSearchBar() {
  132. const {renderNewAllEventsTab: renderPerfIssueEvents} = this.state;
  133. if (renderPerfIssueEvents) {
  134. return (
  135. <EventSearchBar
  136. organization={this.props.organization}
  137. defaultQuery=""
  138. onSearch={this.handleSearch}
  139. excludedTags={excludedTags}
  140. query={this.state.query}
  141. hasRecentSearches={false}
  142. />
  143. );
  144. }
  145. return (
  146. <SearchBar
  147. defaultQuery=""
  148. placeholder={t('Search events by id, message, or tags')}
  149. query={this.state.query}
  150. onSearch={this.handleSearch}
  151. />
  152. );
  153. }
  154. renderResults() {
  155. const {group, params} = this.props;
  156. const tagList = group.tags.filter(tag => tag.key !== 'user') || [];
  157. return (
  158. <EventsTable
  159. tagList={tagList}
  160. events={this.state.eventList}
  161. orgId={params.orgId}
  162. projectId={group.project.slug}
  163. groupId={params.groupId}
  164. />
  165. );
  166. }
  167. renderBody() {
  168. const {renderNewAllEventsTab} = this.state;
  169. let body: React.ReactNode;
  170. if (renderNewAllEventsTab) {
  171. return this.renderNewAllEventsTab();
  172. }
  173. if (this.state.loading) {
  174. body = <LoadingIndicator />;
  175. } else if (this.state.error) {
  176. body = <LoadingError message={this.state.error} onRetry={this.fetchData} />;
  177. } else if (this.state.eventList.length > 0) {
  178. body = this.renderResults();
  179. } else if (this.state.query && this.state.query !== '') {
  180. body = this.renderNoQueryResults();
  181. } else {
  182. body = this.renderEmpty();
  183. }
  184. return (
  185. <Panel className="event-list">
  186. <PanelBody>{body}</PanelBody>
  187. </Panel>
  188. );
  189. }
  190. render() {
  191. return (
  192. <Layout.Body>
  193. <Layout.Main fullWidth>
  194. <Wrapper>
  195. <FilterSection>
  196. <EnvironmentPageFilter />
  197. {this.renderSearchBar()}
  198. </FilterSection>
  199. {this.renderBody()}
  200. <Pagination pageLinks={this.state.pageLinks} />
  201. </Wrapper>
  202. </Layout.Main>
  203. </Layout.Body>
  204. );
  205. }
  206. }
  207. const FilterSection = styled('div')`
  208. display: grid;
  209. gap: ${space(1)};
  210. grid-template-columns: max-content 1fr;
  211. `;
  212. const Wrapper = styled('div')`
  213. display: grid;
  214. gap: ${space(2)};
  215. `;
  216. export {GroupEvents};
  217. export default withOrganization(withApi(GroupEvents));