monitorQuickStartGuide.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import partition from 'lodash/partition';
  4. import {CompactSelect} from 'sentry/components/compactSelect';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {PlatformKey} from 'sentry/types';
  8. import {ProjectKey} from 'sentry/types';
  9. import {useApiQuery} from 'sentry/utils/queryClient';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import {
  12. CLICronQuickStart,
  13. CurlCronQuickStart,
  14. GoCronQuickStart,
  15. JavaCronQuickStart,
  16. JavaQuartzCronQuickStart,
  17. JavaSpringBootCronQuickStart,
  18. NodeJSCronQuickStart,
  19. PHPCronQuickStart,
  20. PHPLaravelCronQuickStart,
  21. PythonCeleryCronQuickStart,
  22. PythonCronQuickStart,
  23. QuickStartProps,
  24. RubyCronQuickStart,
  25. RubyRailsCronQuickStart,
  26. RubySidekiqCronQuickStart,
  27. } from 'sentry/views/monitors/components/quickStartEntries';
  28. import {Monitor} from '../types';
  29. interface Props {
  30. monitor: Monitor;
  31. }
  32. interface OnboardingGuide {
  33. Guide: React.ComponentType<QuickStartProps>;
  34. label: string;
  35. platforms?: Set<PlatformKey>;
  36. }
  37. const onboardingGuides: Record<string, OnboardingGuide> = {
  38. cli: {
  39. label: 'Sentry CLI',
  40. Guide: CLICronQuickStart,
  41. },
  42. curl: {
  43. label: 'cURL',
  44. Guide: CurlCronQuickStart,
  45. },
  46. python: {
  47. label: 'Python',
  48. Guide: PythonCronQuickStart,
  49. platforms: new Set([
  50. 'python',
  51. 'python-django',
  52. 'python-flask',
  53. 'python-fastapi',
  54. 'python-starlette',
  55. 'python-sanic',
  56. 'python-bottle',
  57. 'python-pylons',
  58. 'python-pyramid',
  59. 'python-tornado',
  60. 'python-rq',
  61. ]),
  62. },
  63. pythonCelery: {
  64. label: 'Celery',
  65. Guide: PythonCeleryCronQuickStart,
  66. platforms: new Set(['python-celery']),
  67. },
  68. php: {
  69. label: 'PHP',
  70. Guide: PHPCronQuickStart,
  71. platforms: new Set(['php', 'php-monolog', 'php-symfony']),
  72. },
  73. phpLaravel: {
  74. label: 'Laravel',
  75. Guide: PHPLaravelCronQuickStart,
  76. platforms: new Set(['php-laravel']),
  77. },
  78. nodeJs: {
  79. label: 'Node',
  80. Guide: NodeJSCronQuickStart,
  81. platforms: new Set(['node']),
  82. },
  83. go: {
  84. label: 'Go',
  85. Guide: GoCronQuickStart,
  86. platforms: new Set(['go']),
  87. },
  88. java: {
  89. label: 'Java',
  90. Guide: JavaCronQuickStart,
  91. platforms: new Set(['java', 'java-log4j2', 'java-logback']),
  92. },
  93. javaSpringBoot: {
  94. label: 'Spring',
  95. Guide: JavaSpringBootCronQuickStart,
  96. platforms: new Set(['java-spring-boot', 'java-spring']),
  97. },
  98. javaQuartz: {
  99. label: 'Quartz',
  100. Guide: JavaQuartzCronQuickStart,
  101. platforms: new Set([
  102. 'java',
  103. 'java-log4j2',
  104. 'java-logback',
  105. 'java-spring-boot',
  106. 'java-spring',
  107. ]),
  108. },
  109. ruby: {
  110. label: 'Ruby',
  111. Guide: RubyCronQuickStart,
  112. platforms: new Set(['ruby']),
  113. },
  114. rubyRails: {
  115. label: 'Rails',
  116. Guide: RubyRailsCronQuickStart,
  117. platforms: new Set(['ruby', 'ruby-rails']),
  118. },
  119. rubySidekiq: {
  120. label: 'Sidekiq',
  121. Guide: RubySidekiqCronQuickStart,
  122. platforms: new Set(['ruby', 'ruby-rails']),
  123. },
  124. };
  125. const guideToSelectOption = ({key, label}) => ({label, value: key});
  126. export default function MonitorQuickStartGuide({monitor}: Props) {
  127. const org = useOrganization();
  128. const {data: projectKeys} = useApiQuery<Array<ProjectKey>>(
  129. [`/projects/${org.slug}/${monitor.project.slug}/keys/`],
  130. {staleTime: Infinity}
  131. );
  132. const guideList = Object.entries(onboardingGuides).map(([key, guide]) => ({
  133. ...guide,
  134. key,
  135. }));
  136. const [genericGuides, platformGuides] = partition(
  137. guideList,
  138. guide => guide.platforms === undefined
  139. );
  140. const exampleOptions = [
  141. {label: t('Platform Specfiic'), options: platformGuides.map(guideToSelectOption)},
  142. {label: t('Generic'), options: genericGuides.map(guideToSelectOption)},
  143. ];
  144. const platformSpecific = platformGuides.filter(
  145. guide => guide.platforms?.has(monitor.project.platform ?? 'other')
  146. );
  147. const defaultExample = platformSpecific.length > 0 ? platformSpecific[0].key : 'cli';
  148. const [selectedGuide, setSelectedGuide] = useState(defaultExample);
  149. const {Guide} = onboardingGuides[selectedGuide];
  150. return (
  151. <Container>
  152. <CompactSelect
  153. options={exampleOptions}
  154. value={selectedGuide}
  155. onChange={({value}) => setSelectedGuide(value)}
  156. />
  157. <Guide
  158. slug={monitor.slug}
  159. orgSlug={org.slug}
  160. orgId={org.id}
  161. projectId={monitor.project.id}
  162. publicKey={projectKeys?.[0].public}
  163. dsnKey={projectKeys?.[0].dsn.public}
  164. />
  165. </Container>
  166. );
  167. }
  168. const Container = styled('div')`
  169. display: flex;
  170. flex-direction: column;
  171. gap: ${space(2)};
  172. `;