groupEvents.tsx 3.6 KB

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