index.tsx 6.5 KB

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