groupEvents.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import {Component, Fragment} 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.issue_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. if (!this.state.renderNewAllEventsTab) {
  88. this.props.api.request(`/issues/${this.props.params.groupId}/events/`, {
  89. query,
  90. method: 'GET',
  91. success: (data, _, resp) => {
  92. this.setState({
  93. eventList: data,
  94. error: false,
  95. loading: false,
  96. pageLinks: resp?.getResponseHeader('Link') ?? '',
  97. });
  98. },
  99. error: err => {
  100. this.setState({
  101. error: parseApiError(err),
  102. loading: false,
  103. });
  104. },
  105. });
  106. }
  107. };
  108. renderNoQueryResults() {
  109. return (
  110. <EmptyStateWarning>
  111. <p>{t('Sorry, no events match your search query.')}</p>
  112. </EmptyStateWarning>
  113. );
  114. }
  115. renderEmpty() {
  116. return (
  117. <EmptyStateWarning>
  118. <p>{t("There don't seem to be any events yet.")}</p>
  119. </EmptyStateWarning>
  120. );
  121. }
  122. renderNewAllEventsTab() {
  123. return (
  124. <AllEventsTable
  125. issueId={this.props.group.id}
  126. isPerfIssue={this.props.group.issueCategory === IssueCategory.PERFORMANCE}
  127. location={this.props.location}
  128. organization={this.props.organization}
  129. projectId={this.props.group.project.slug}
  130. totalEventCount={this.props.group.count}
  131. excludedTags={excludedTags}
  132. />
  133. );
  134. }
  135. renderSearchBar() {
  136. const {renderNewAllEventsTab: renderPerfIssueEvents} = this.state;
  137. if (renderPerfIssueEvents) {
  138. return (
  139. <EventSearchBar
  140. organization={this.props.organization}
  141. defaultQuery=""
  142. onSearch={this.handleSearch}
  143. excludedTags={excludedTags}
  144. query={this.state.query}
  145. hasRecentSearches={false}
  146. />
  147. );
  148. }
  149. return (
  150. <SearchBar
  151. defaultQuery=""
  152. placeholder={t('Search events by id, message, or tags')}
  153. query={this.state.query}
  154. onSearch={this.handleSearch}
  155. />
  156. );
  157. }
  158. renderResults() {
  159. const {group, params, organization} = this.props;
  160. const tagList = group.tags.filter(tag => tag.key !== 'user') || [];
  161. return (
  162. <EventsTable
  163. tagList={tagList}
  164. events={this.state.eventList}
  165. orgId={params.orgId}
  166. projectId={group.project.slug}
  167. groupId={params.groupId}
  168. orgFeatures={organization.features}
  169. />
  170. );
  171. }
  172. renderBody() {
  173. const {renderNewAllEventsTab} = this.state;
  174. let body: React.ReactNode;
  175. if (renderNewAllEventsTab) {
  176. return this.renderNewAllEventsTab();
  177. }
  178. if (this.state.loading) {
  179. body = <LoadingIndicator />;
  180. } else if (this.state.error) {
  181. body = <LoadingError message={this.state.error} onRetry={this.fetchData} />;
  182. } else if (this.state.eventList.length > 0) {
  183. body = this.renderResults();
  184. } else if (this.state.query && this.state.query !== '') {
  185. body = this.renderNoQueryResults();
  186. } else {
  187. body = this.renderEmpty();
  188. }
  189. return (
  190. <Fragment>
  191. <Panel className="event-list">
  192. <PanelBody>{body}</PanelBody>
  193. </Panel>
  194. <Pagination pageLinks={this.state.pageLinks} />
  195. </Fragment>
  196. );
  197. }
  198. render() {
  199. return (
  200. <Layout.Body>
  201. <Layout.Main fullWidth>
  202. <Wrapper>
  203. <FilterSection>
  204. <EnvironmentPageFilter />
  205. {this.renderSearchBar()}
  206. </FilterSection>
  207. {this.renderBody()}
  208. </Wrapper>
  209. </Layout.Main>
  210. </Layout.Body>
  211. );
  212. }
  213. }
  214. const FilterSection = styled('div')`
  215. display: grid;
  216. gap: ${space(1)};
  217. grid-template-columns: max-content 1fr;
  218. `;
  219. const Wrapper = styled('div')`
  220. display: grid;
  221. gap: ${space(2)};
  222. `;
  223. export {GroupEvents};
  224. export default withOrganization(withApi(GroupEvents));