monitorQuickStartGuide.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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, ProjectKey} from 'sentry/types';
  8. import {useApiQuery} from 'sentry/utils/queryClient';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import type {QuickStartProps} from 'sentry/views/monitors/components/quickStartEntries';
  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. RubyCronQuickStart,
  24. RubyRailsCronQuickStart,
  25. RubySidekiqCronQuickStart,
  26. } from 'sentry/views/monitors/components/quickStartEntries';
  27. import type {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. rubySidekiq: {
  119. label: 'Sidekiq',
  120. Guide: RubySidekiqCronQuickStart,
  121. platforms: new Set(['ruby', 'ruby-rails']),
  122. },
  123. };
  124. const guideToSelectOption = ({key, label}) => ({label, value: key});
  125. export default function MonitorQuickStartGuide({monitor}: Props) {
  126. const org = useOrganization();
  127. const {data: projectKeys} = useApiQuery<Array<ProjectKey>>(
  128. [`/projects/${org.slug}/${monitor.project.slug}/keys/`],
  129. {staleTime: Infinity}
  130. );
  131. const guideList = Object.entries(onboardingGuides).map(([key, guide]) => ({
  132. ...guide,
  133. key,
  134. }));
  135. const [genericGuides, platformGuides] = partition(
  136. guideList,
  137. guide => guide.platforms === undefined
  138. );
  139. const exampleOptions = [
  140. {label: t('Platform Specfiic'), options: platformGuides.map(guideToSelectOption)},
  141. {label: t('Generic'), options: genericGuides.map(guideToSelectOption)},
  142. ];
  143. const platformSpecific = platformGuides.filter(guide =>
  144. guide.platforms?.has(monitor.project.platform ?? 'other')
  145. );
  146. const defaultExample = platformSpecific.length > 0 ? platformSpecific[0].key : 'cli';
  147. const [selectedGuide, setSelectedGuide] = useState(defaultExample);
  148. const {Guide} = onboardingGuides[selectedGuide];
  149. return (
  150. <Container>
  151. <CompactSelect
  152. options={exampleOptions}
  153. value={selectedGuide}
  154. onChange={({value}) => setSelectedGuide(value)}
  155. />
  156. <Guide
  157. slug={monitor.slug}
  158. orgSlug={org.slug}
  159. orgId={org.id}
  160. projectId={monitor.project.id}
  161. publicKey={projectKeys?.[0].public}
  162. dsnKey={projectKeys?.[0].dsn.public}
  163. />
  164. </Container>
  165. );
  166. }
  167. const Container = styled('div')`
  168. display: flex;
  169. flex-direction: column;
  170. gap: ${space(2)};
  171. `;