groupEvents.tsx 7.3 KB

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