groupEvents.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {Component} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Client} from 'sentry/api';
  5. import EventSearchBar from 'sentry/components/events/searchBar';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import {space} from 'sentry/styles/space';
  8. import {Group, Organization} from 'sentry/types';
  9. import {handleRouteLeave} from 'sentry/utils/useCleanQueryParamsOnRouteLeave';
  10. import withApi from 'sentry/utils/withApi';
  11. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  12. import withOrganization from 'sentry/utils/withOrganization';
  13. import AllEventsTable from './allEventsTable';
  14. type Props = {
  15. api: Client;
  16. group: Group;
  17. organization: Organization;
  18. } & RouteComponentProps<{groupId: string}, {}>;
  19. interface State {
  20. query: string;
  21. }
  22. const excludedTags = [
  23. 'environment',
  24. 'issue',
  25. 'issue.id',
  26. 'performance.issue_ids',
  27. 'transaction.op',
  28. 'transaction.status',
  29. ];
  30. class GroupEvents extends Component<Props, State> {
  31. constructor(props: Props) {
  32. super(props);
  33. const queryParams = this.props.location.query;
  34. this.state = {
  35. query: queryParams.query || '',
  36. };
  37. }
  38. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  39. if (this.props.location.search !== nextProps.location.search) {
  40. const queryParams = nextProps.location.query;
  41. this.setState({
  42. query: queryParams.query,
  43. });
  44. }
  45. }
  46. UNSAFE_componentDidMount() {
  47. this._unsubscribeHandleRouteLeave = browserHistory.listen(newLocation =>
  48. handleRouteLeave({
  49. fieldsToClean: ['cursor'],
  50. newLocation,
  51. oldPathname: this.props.location.pathname,
  52. })
  53. );
  54. }
  55. UNSAFE_componentWillUnmount() {
  56. this._unsubscribeHandleRouteLeave?.();
  57. }
  58. _unsubscribeHandleRouteLeave: undefined | ReturnType<typeof browserHistory.listen>;
  59. handleSearch = (query: string) => {
  60. const targetQueryParams = {...this.props.location.query};
  61. targetQueryParams.query = query;
  62. const {organization} = this.props;
  63. const {groupId} = this.props.params;
  64. browserHistory.push(
  65. normalizeUrl({
  66. pathname: `/organizations/${organization.slug}/issues/${groupId}/events/`,
  67. query: targetQueryParams,
  68. })
  69. );
  70. };
  71. render() {
  72. return (
  73. <Layout.Body>
  74. <Layout.Main fullWidth>
  75. <AllEventsFilters>
  76. <EventSearchBar
  77. organization={this.props.organization}
  78. defaultQuery=""
  79. onSearch={this.handleSearch}
  80. excludedTags={excludedTags}
  81. query={this.state.query}
  82. hasRecentSearches={false}
  83. />
  84. </AllEventsFilters>
  85. <AllEventsTable
  86. issueId={this.props.group.id}
  87. location={this.props.location}
  88. organization={this.props.organization}
  89. group={this.props.group}
  90. excludedTags={excludedTags}
  91. />
  92. </Layout.Main>
  93. </Layout.Body>
  94. );
  95. }
  96. }
  97. const AllEventsFilters = styled('div')`
  98. margin-bottom: ${space(2)};
  99. `;
  100. export {GroupEvents};
  101. export default withOrganization(withApi(GroupEvents));