index.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import {Component, lazy, Suspense} from 'react';
  2. import type {Client} from 'sentry/api';
  3. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import Placeholder from 'sentry/components/placeholder';
  6. import {DEFAULT_QUERY, NEW_DEFAULT_QUERY} from 'sentry/constants';
  7. import {t} from 'sentry/locale';
  8. import type {Organization} from 'sentry/types/organization';
  9. import type {Project} from 'sentry/types/project';
  10. import NoIssuesMatched from 'sentry/views/issueList/noGroupsHandler/noIssuesMatched';
  11. import {FOR_REVIEW_QUERIES} from 'sentry/views/issueList/utils';
  12. import NoUnresolvedIssues from './noUnresolvedIssues';
  13. type Props = {
  14. api: Client;
  15. groupIds: string[];
  16. organization: Organization;
  17. query: string;
  18. emptyMessage?: React.ReactNode;
  19. selectedProjectIds?: number[];
  20. };
  21. type State = {
  22. fetchingSentFirstEvent: boolean;
  23. firstEventProjects?: Project[] | null;
  24. sentFirstEvent?: boolean;
  25. };
  26. /**
  27. * Component which is rendered when no groups/issues were found. This could
  28. * either be caused by having no first events, having resolved all issues, or
  29. * having no issues be returned from a query. This component will conditionally
  30. * render one of those states.
  31. */
  32. class NoGroupsHandler extends Component<Props, State> {
  33. state: State = {
  34. fetchingSentFirstEvent: true,
  35. sentFirstEvent: false,
  36. firstEventProjects: null,
  37. };
  38. componentDidMount() {
  39. this.fetchSentFirstEvent();
  40. this._isMounted = true;
  41. }
  42. componentWillUnmount() {
  43. this._isMounted = false;
  44. }
  45. /**
  46. * This is a bit hacky, but this is causing flakiness in frontend tests
  47. * `issueList/overview` is being unmounted during tests before the requests
  48. * in `this.fetchSentFirstEvent` are completed and causing this React warning:
  49. *
  50. * Warning: Can't perform a React state update on an unmounted component.
  51. * This is a no-op, but it indicates a memory leak in your application.
  52. * To fix, cancel all subscriptions and asynchronous tasks in the
  53. * componentWillUnmount method.
  54. *
  55. * This is something to revisit if we refactor API client
  56. */
  57. private _isMounted: boolean = false;
  58. async fetchSentFirstEvent() {
  59. this.setState({
  60. fetchingSentFirstEvent: true,
  61. });
  62. const {organization, selectedProjectIds, api} = this.props;
  63. let sentFirstEvent = false;
  64. let projects = [];
  65. // If no projects are selected, then we must check every project the user is a
  66. // member of and make sure there are no first events for all of the projects
  67. // Set project to -1 for all projects
  68. // Do not pass a project id for "my projects"
  69. let firstEventQuery: {project?: number[]} = {};
  70. const projectsQuery: {per_page: number; query?: string} = {per_page: 1};
  71. if (selectedProjectIds?.length) {
  72. firstEventQuery = {project: selectedProjectIds};
  73. projectsQuery.query = selectedProjectIds.map(id => `id:${id}`).join(' ');
  74. }
  75. [{sentFirstEvent}, projects] = await Promise.all([
  76. // checks to see if selection has sent a first event
  77. api.requestPromise(`/organizations/${organization.slug}/sent-first-event/`, {
  78. query: firstEventQuery,
  79. }),
  80. // retrieves a single project to feed to WaitingForEvents from renderStreamBody
  81. api.requestPromise(`/organizations/${organization.slug}/projects/`, {
  82. query: projectsQuery,
  83. }),
  84. ]);
  85. // See comment where this property is initialized
  86. // FIXME
  87. if (!this._isMounted) {
  88. return;
  89. }
  90. this.setState({
  91. fetchingSentFirstEvent: false,
  92. sentFirstEvent,
  93. firstEventProjects: projects,
  94. });
  95. }
  96. renderLoading() {
  97. return <LoadingIndicator />;
  98. }
  99. renderAwaitingEvents(projects: State['firstEventProjects']) {
  100. const {organization, groupIds} = this.props;
  101. const project = projects && projects.length > 0 ? projects[0] : undefined;
  102. const sampleIssueId = groupIds.length > 0 ? groupIds[0] : undefined;
  103. const WaitingForEvents = lazy(() => import('sentry/components/waitingForEvents'));
  104. return (
  105. <Suspense fallback={<Placeholder height="260px" />}>
  106. <WaitingForEvents
  107. org={organization}
  108. project={project}
  109. sampleIssueId={sampleIssueId}
  110. />
  111. </Suspense>
  112. );
  113. }
  114. renderEmpty() {
  115. const {emptyMessage} = this.props;
  116. if (emptyMessage) {
  117. return (
  118. <EmptyStateWarning>
  119. <p>{emptyMessage}</p>
  120. </EmptyStateWarning>
  121. );
  122. }
  123. return <NoIssuesMatched />;
  124. }
  125. render() {
  126. const {fetchingSentFirstEvent, sentFirstEvent, firstEventProjects} = this.state;
  127. const {query} = this.props;
  128. if (fetchingSentFirstEvent) {
  129. return this.renderLoading();
  130. }
  131. if (!sentFirstEvent) {
  132. return this.renderAwaitingEvents(firstEventProjects);
  133. }
  134. if (query === DEFAULT_QUERY || query === NEW_DEFAULT_QUERY) {
  135. return (
  136. <NoUnresolvedIssues
  137. title={t("We couldn't find any issues that matched your filters.")}
  138. subtitle={t('Get out there and write some broken code!')}
  139. />
  140. );
  141. }
  142. if (FOR_REVIEW_QUERIES.includes(query || '')) {
  143. return (
  144. <NoUnresolvedIssues
  145. title={t('Well, would you look at that.')}
  146. subtitle={t(
  147. 'No more issues to review. Better get back out there and write some broken code.'
  148. )}
  149. />
  150. );
  151. }
  152. return this.renderEmpty();
  153. }
  154. }
  155. export default NoGroupsHandler;