monitorQuickStartGuide.tsx 4.1 KB

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