groupEvents.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 = ['environment', 'issue', 'issue.id', 'performance.issue_ids'];
  23. class GroupEvents extends Component<Props, State> {
  24. constructor(props: Props) {
  25. super(props);
  26. const queryParams = this.props.location.query;
  27. this.state = {
  28. query: queryParams.query || '',
  29. };
  30. }
  31. UNSAFE_componentWillReceiveProps(nextProps: Props) {
  32. if (this.props.location.search !== nextProps.location.search) {
  33. const queryParams = nextProps.location.query;
  34. this.setState({
  35. query: queryParams.query,
  36. });
  37. }
  38. }
  39. UNSAFE_componentDidMount() {
  40. this._unsubscribeHandleRouteLeave = browserHistory.listen(newLocation =>
  41. handleRouteLeave({
  42. fieldsToClean: ['cursor'],
  43. newLocation,
  44. oldPathname: this.props.location.pathname,
  45. })
  46. );
  47. }
  48. UNSAFE_componentWillUnmount() {
  49. this._unsubscribeHandleRouteLeave?.();
  50. }
  51. _unsubscribeHandleRouteLeave: undefined | ReturnType<typeof browserHistory.listen>;
  52. handleSearch = (query: string) => {
  53. const targetQueryParams = {...this.props.location.query};
  54. targetQueryParams.query = query;
  55. const {organization} = this.props;
  56. const {groupId} = this.props.params;
  57. browserHistory.push(
  58. normalizeUrl({
  59. pathname: `/organizations/${organization.slug}/issues/${groupId}/events/`,
  60. query: targetQueryParams,
  61. })
  62. );
  63. };
  64. render() {
  65. return (
  66. <Layout.Body>
  67. <Layout.Main fullWidth>
  68. <AllEventsFilters>
  69. <EventSearchBar
  70. organization={this.props.organization}
  71. defaultQuery=""
  72. onSearch={this.handleSearch}
  73. excludedTags={excludedTags}
  74. query={this.state.query}
  75. hasRecentSearches={false}
  76. />
  77. </AllEventsFilters>
  78. <AllEventsTable
  79. issueId={this.props.group.id}
  80. location={this.props.location}
  81. organization={this.props.organization}
  82. group={this.props.group}
  83. excludedTags={excludedTags}
  84. />
  85. </Layout.Main>
  86. </Layout.Body>
  87. );
  88. }
  89. }
  90. const AllEventsFilters = styled('div')`
  91. margin-bottom: ${space(2)};
  92. `;
  93. export {GroupEvents};
  94. export default withOrganization(withApi(GroupEvents));