index.tsx 6.1 KB

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