index.tsx 5.9 KB

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