groupEvents.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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.id}
  130. projectSlug={this.props.group.project.slug}
  131. totalEventCount={this.props.group.count}
  132. excludedTags={excludedTags}
  133. />
  134. );
  135. }
  136. renderSearchBar() {
  137. const {renderNewAllEventsTab: renderPerfIssueEvents} = this.state;
  138. if (renderPerfIssueEvents) {
  139. return (
  140. <EventSearchBar
  141. organization={this.props.organization}
  142. defaultQuery=""
  143. onSearch={this.handleSearch}
  144. excludedTags={excludedTags}
  145. query={this.state.query}
  146. hasRecentSearches={false}
  147. />
  148. );
  149. }
  150. return (
  151. <SearchBar
  152. defaultQuery=""
  153. placeholder={t('Search events by id, message, or tags')}
  154. query={this.state.query}
  155. onSearch={this.handleSearch}
  156. />
  157. );
  158. }
  159. renderResults() {
  160. const {group, params, organization} = this.props;
  161. const tagList = group.tags.filter(tag => tag.key !== 'user') || [];
  162. return (
  163. <EventsTable
  164. tagList={tagList}
  165. events={this.state.eventList}
  166. orgId={params.orgId}
  167. projectId={group.project.slug}
  168. groupId={params.groupId}
  169. orgFeatures={organization.features}
  170. />
  171. );
  172. }
  173. renderBody() {
  174. const {renderNewAllEventsTab} = this.state;
  175. let body: React.ReactNode;
  176. if (renderNewAllEventsTab) {
  177. return this.renderNewAllEventsTab();
  178. }
  179. if (this.state.loading) {
  180. body = <LoadingIndicator />;
  181. } else if (this.state.error) {
  182. body = <LoadingError message={this.state.error} onRetry={this.fetchData} />;
  183. } else if (this.state.eventList.length > 0) {
  184. body = this.renderResults();
  185. } else if (this.state.query && this.state.query !== '') {
  186. body = this.renderNoQueryResults();
  187. } else {
  188. body = this.renderEmpty();
  189. }
  190. return (
  191. <Fragment>
  192. <Panel className="event-list">
  193. <PanelBody>{body}</PanelBody>
  194. </Panel>
  195. <Pagination pageLinks={this.state.pageLinks} />
  196. </Fragment>
  197. );
  198. }
  199. render() {
  200. // New issue actions moves the environment picker to the header
  201. const hasIssueActionsV2 =
  202. this.props.organization.features.includes('issue-actions-v2');
  203. return (
  204. <Layout.Body>
  205. <Layout.Main fullWidth>
  206. <Wrapper>
  207. {hasIssueActionsV2 ? (
  208. this.renderSearchBar()
  209. ) : (
  210. <FilterSection>
  211. <EnvironmentPageFilter />
  212. {this.renderSearchBar()}
  213. </FilterSection>
  214. )}
  215. {this.renderBody()}
  216. </Wrapper>
  217. </Layout.Main>
  218. </Layout.Body>
  219. );
  220. }
  221. }
  222. const FilterSection = styled('div')`
  223. display: grid;
  224. gap: ${space(1)};
  225. grid-template-columns: max-content 1fr;
  226. `;
  227. const Wrapper = styled('div')`
  228. display: grid;
  229. gap: ${space(2)};
  230. `;
  231. export {GroupEvents};
  232. export default withOrganization(withApi(GroupEvents));