index.tsx 5.3 KB

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