index.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. 'apple-ios',
  122. 'dotnet',
  123. 'dotnet-aspnetcore',
  124. 'flutter',
  125. 'go',
  126. 'java',
  127. 'java-spring-boot',
  128. 'javascript',
  129. 'javascript-angular',
  130. 'javascript-react',
  131. 'javascript-vue',
  132. 'node-express',
  133. 'node-nestjs',
  134. 'php',
  135. 'php-laravel',
  136. 'python',
  137. 'python-fastapi',
  138. 'python-flask',
  139. 'react-native',
  140. 'ruby',
  141. 'ruby-rails',
  142. 'unity',
  143. ]
  144. : []),
  145. ];
  146. const hasUpdatedEmptyState =
  147. organization.features.includes('issue-stream-empty-state') &&
  148. project?.platform &&
  149. updatedEmptyStatePlatforms.includes(project.platform);
  150. return (
  151. <Suspense fallback={<Placeholder height="260px" />}>
  152. {!hasUpdatedEmptyState && (
  153. <WaitingForEvents
  154. org={organization}
  155. project={project}
  156. sampleIssueId={sampleIssueId}
  157. />
  158. )}
  159. {hasUpdatedEmptyState && <UpdatedEmptyState project={project} />}
  160. </Suspense>
  161. );
  162. }
  163. renderEmpty() {
  164. const {emptyMessage} = this.props;
  165. if (emptyMessage) {
  166. return (
  167. <EmptyStateWarning>
  168. <p>{emptyMessage}</p>
  169. </EmptyStateWarning>
  170. );
  171. }
  172. return <NoIssuesMatched />;
  173. }
  174. render() {
  175. const {fetchingSentFirstEvent, sentFirstEvent, firstEventProjects} = this.state;
  176. const {query} = this.props;
  177. if (fetchingSentFirstEvent) {
  178. return this.renderLoading();
  179. }
  180. if (!sentFirstEvent) {
  181. return this.renderAwaitingEvents(firstEventProjects);
  182. }
  183. if (query === DEFAULT_QUERY) {
  184. return (
  185. <NoUnresolvedIssues
  186. title={t("We couldn't find any issues that matched your filters.")}
  187. subtitle={t('Get out there and write some broken code!')}
  188. />
  189. );
  190. }
  191. if (FOR_REVIEW_QUERIES.includes(query || '')) {
  192. return (
  193. <NoUnresolvedIssues
  194. title={t('Well, would you look at that.')}
  195. subtitle={t(
  196. 'No more issues to review. Better get back out there and write some broken code.'
  197. )}
  198. />
  199. );
  200. }
  201. return this.renderEmpty();
  202. }
  203. }
  204. export default NoGroupsHandler;