monitorQuickStartGuide.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 {PlatformKey} from 'sentry/data/platformCategories';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  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. NodeJSCronQuickStart,
  15. PHPCronQuickStart,
  16. PHPLaravelCronQuickStart,
  17. PythonCeleryCronQuickStart,
  18. PythonCronQuickStart,
  19. QuickStartProps,
  20. } from 'sentry/views/monitors/components/quickStartEntries';
  21. import {Monitor} from '../types';
  22. interface Props {
  23. monitor: Monitor;
  24. }
  25. interface OnboardingGuide {
  26. Guide: React.ComponentType<QuickStartProps>;
  27. label: string;
  28. platforms?: Set<PlatformKey>;
  29. }
  30. const onboardingGuides: Record<string, OnboardingGuide> = {
  31. cli: {
  32. label: 'Sentry CLI',
  33. Guide: CLICronQuickStart,
  34. },
  35. curl: {
  36. label: 'cURL',
  37. Guide: CurlCronQuickStart,
  38. },
  39. python: {
  40. label: 'Python',
  41. Guide: PythonCronQuickStart,
  42. platforms: new Set([
  43. 'python',
  44. 'python-django',
  45. 'python-flask',
  46. 'python-fastapi',
  47. 'python-starlette',
  48. 'python-sanic',
  49. 'python-bottle',
  50. 'python-pylons',
  51. 'python-pyramid',
  52. 'python-tornado',
  53. 'python-rq',
  54. ]),
  55. },
  56. pythonCelery: {
  57. label: 'Celery',
  58. Guide: PythonCeleryCronQuickStart,
  59. platforms: new Set(['python-celery']),
  60. },
  61. php: {
  62. label: 'PHP',
  63. Guide: PHPCronQuickStart,
  64. platforms: new Set(['php', 'php-monolog', 'php-symfony2']),
  65. },
  66. phpLaravel: {
  67. label: 'Laravel',
  68. Guide: PHPLaravelCronQuickStart,
  69. platforms: new Set(['php-laravel']),
  70. },
  71. nodeJs: {
  72. label: 'Node',
  73. Guide: NodeJSCronQuickStart,
  74. platforms: new Set(['node']),
  75. },
  76. };
  77. const guideToSelectOption = ({key, label}) => ({label, value: key});
  78. export default function MonitorQuickStartGuide({monitor}: Props) {
  79. const org = useOrganization();
  80. const {data: projectKeys} = useApiQuery<Array<ProjectKey>>(
  81. [`/projects/${org.slug}/${monitor.project.slug}/keys/`],
  82. {staleTime: Infinity}
  83. );
  84. const guideList = Object.entries(onboardingGuides).map(([key, guide]) => ({
  85. ...guide,
  86. key,
  87. }));
  88. const [genericGuides, platformGuides] = partition(
  89. guideList,
  90. guide => guide.platforms === undefined
  91. );
  92. const exampleOptions = [
  93. {label: t('Platform Specfiic'), options: platformGuides.map(guideToSelectOption)},
  94. {label: t('Generic'), options: genericGuides.map(guideToSelectOption)},
  95. ];
  96. const platformSpecific = platformGuides.filter(guide =>
  97. guide.platforms?.has(monitor.project.platform ?? 'other')
  98. );
  99. const defaultExample = platformSpecific.length > 0 ? platformSpecific[0].key : 'cli';
  100. const [selectedGuide, setSelectedGuide] = useState(defaultExample);
  101. const {Guide} = onboardingGuides[selectedGuide];
  102. return (
  103. <Container>
  104. <CompactSelect
  105. options={exampleOptions}
  106. value={selectedGuide}
  107. onChange={({value}) => setSelectedGuide(value)}
  108. />
  109. <Guide
  110. slug={monitor.slug}
  111. orgSlug={org.slug}
  112. orgId={org.id}
  113. projectId={monitor.project.id}
  114. publicKey={projectKeys?.[0].public}
  115. dsnKey={projectKeys?.[0].dsn.public}
  116. />
  117. </Container>
  118. );
  119. }
  120. const Container = styled('div')`
  121. display: flex;
  122. flex-direction: column;
  123. gap: ${space(2)};
  124. `;