errorRobot.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import robotBackground from 'sentry-images/spot/sentry-robot.png';
  4. import {Client} from 'sentry/api';
  5. import Button from 'sentry/components/button';
  6. import Link from 'sentry/components/links/link';
  7. import {t, tct} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import {Organization, Project} from 'sentry/types';
  10. import {defined} from 'sentry/utils';
  11. import withApi from 'sentry/utils/withApi';
  12. import CreateSampleEventButton from 'sentry/views/onboarding/createSampleEventButton';
  13. type Props = {
  14. api: Client;
  15. gradient: boolean;
  16. org: Organization;
  17. project?: Project;
  18. /**
  19. * sampleIssueId can have 3 values:
  20. * - empty string to indicate it doesn't exist (render "create sample event")
  21. * - non-empty string to indicate it exists (render "see sample event")
  22. * - undefined to indicate the project API should be consulted to find out
  23. */
  24. sampleIssueId?: string;
  25. };
  26. type State = {
  27. error: boolean;
  28. loading: boolean;
  29. sampleIssueId?: string;
  30. };
  31. class ErrorRobot extends Component<Props, State> {
  32. state: State = {
  33. error: false,
  34. loading: false,
  35. sampleIssueId: this.props.sampleIssueId,
  36. };
  37. componentDidMount() {
  38. this.fetchData();
  39. }
  40. async fetchData() {
  41. const {org, project} = this.props;
  42. const {sampleIssueId} = this.state;
  43. if (!project) {
  44. return;
  45. }
  46. if (defined(sampleIssueId)) {
  47. return;
  48. }
  49. const url = `/projects/${org.slug}/${project.slug}/issues/`;
  50. this.setState({loading: true});
  51. try {
  52. const data = await this.props.api.requestPromise(url, {
  53. method: 'GET',
  54. data: {limit: 1},
  55. });
  56. this.setState({sampleIssueId: (data.length > 0 && data[0].id) || ''});
  57. } catch (err) {
  58. const error = err?.responseJSON?.detail ?? true;
  59. this.setState({error});
  60. }
  61. this.setState({loading: false});
  62. }
  63. render() {
  64. const {loading, error, sampleIssueId} = this.state;
  65. const {org, project, gradient} = this.props;
  66. const sampleLink =
  67. project && (loading || error ? null : sampleIssueId) ? (
  68. <p>
  69. <Link to={`/${org.slug}/${project.slug}/issues/${sampleIssueId}/?sample`}>
  70. {t('Or see your sample event')}
  71. </Link>
  72. </p>
  73. ) : (
  74. <p>
  75. <CreateSampleEventButton
  76. priority="link"
  77. project={project}
  78. source="issues_list"
  79. disabled={!project}
  80. title={!project ? t('Select a project to create a sample event') : undefined}
  81. >
  82. {t('Create a sample event')}
  83. </CreateSampleEventButton>
  84. </p>
  85. );
  86. return (
  87. <ErrorRobotWrapper
  88. data-test-id="awaiting-events"
  89. className="awaiting-events"
  90. gradient={gradient}
  91. >
  92. <Robot aria-hidden>
  93. <Eye />
  94. </Robot>
  95. <MessageContainer>
  96. <h3>{t('Waiting for events…')}</h3>
  97. <p>
  98. {tct(
  99. 'Our error robot is waiting to [strike:devour] receive your first event.',
  100. {
  101. strike: <Strikethrough />,
  102. }
  103. )}
  104. </p>
  105. <p>
  106. {project && (
  107. <Button
  108. data-test-id="install-instructions"
  109. priority="primary"
  110. to={`/${org.slug}/${project.slug}/getting-started/${
  111. project.platform || ''
  112. }`}
  113. >
  114. {t('Installation Instructions')}
  115. </Button>
  116. )}
  117. </p>
  118. {sampleLink}
  119. </MessageContainer>
  120. </ErrorRobotWrapper>
  121. );
  122. }
  123. }
  124. export {ErrorRobot};
  125. export default withApi(ErrorRobot);
  126. const ErrorRobotWrapper = styled('div')<{gradient: boolean}>`
  127. display: flex;
  128. justify-content: center;
  129. font-size: ${p => p.theme.fontSizeExtraLarge};
  130. box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
  131. border-radius: 0 0 3px 3px;
  132. padding: 40px ${space(3)} ${space(3)};
  133. min-height: 260px;
  134. @media (max-width: ${p => p.theme.breakpoints.small}) {
  135. flex-direction: column;
  136. align-items: center;
  137. padding: ${space(3)};
  138. text-align: center;
  139. }
  140. `;
  141. const Robot = styled('div')`
  142. display: block;
  143. position: relative;
  144. width: 220px;
  145. height: 260px;
  146. background: url(${robotBackground});
  147. background-size: cover;
  148. @media (max-width: ${p => p.theme.breakpoints.small}) {
  149. width: 110px;
  150. height: 130px;
  151. }
  152. `;
  153. const Eye = styled('span')`
  154. width: 12px;
  155. height: 12px;
  156. border-radius: 50%;
  157. position: absolute;
  158. top: 70px;
  159. left: 81px;
  160. transform: translateZ(0);
  161. animation: blink-eye 0.6s infinite;
  162. @media (max-width: ${p => p.theme.breakpoints.small}) {
  163. width: 6px;
  164. height: 6px;
  165. top: 35px;
  166. left: 41px;
  167. }
  168. @keyframes blink-eye {
  169. 0% {
  170. background: #e03e2f;
  171. box-shadow: 0 0 10px #e03e2f;
  172. }
  173. 50% {
  174. background: #4a4d67;
  175. box-shadow: none;
  176. }
  177. 100% {
  178. background: #e03e2f;
  179. box-shadow: 0 0 10px #e03e2f;
  180. }
  181. }
  182. `;
  183. const MessageContainer = styled('div')`
  184. align-self: center;
  185. max-width: 480px;
  186. margin-left: 40px;
  187. @media (max-width: ${p => p.theme.breakpoints.small}) {
  188. margin: 0;
  189. }
  190. `;
  191. const Strikethrough = styled('span')`
  192. text-decoration: line-through;
  193. `;