monitorQuickStartGuide.tsx 4.4 KB

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