monitorQuickStartGuide.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 {
  11. CLICronQuickStart,
  12. CurlCronQuickStart,
  13. NodeJSCronQuickStart,
  14. PHPCronQuickStart,
  15. PHPLaravelCronQuickStart,
  16. PythonCeleryCronQuickStart,
  17. PythonCronQuickStart,
  18. QuickStartProps,
  19. } from 'sentry/views/monitors/components/quickStartEntries';
  20. import {Monitor} from '../types';
  21. interface Props {
  22. monitor: Monitor;
  23. orgId: string;
  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, orgId}: Props) {
  79. const {data: projectKeys} = useApiQuery<Array<ProjectKey>>(
  80. [`/projects/${orgId}/${monitor.project.slug}/keys/`],
  81. {staleTime: Infinity}
  82. );
  83. const guideList = Object.entries(onboardingGuides).map(([key, guide]) => ({
  84. ...guide,
  85. key,
  86. }));
  87. const [genericGuides, platformGuides] = partition(
  88. guideList,
  89. guide => guide.platforms === undefined
  90. );
  91. const exampleOptions = [
  92. {label: t('Platform Specfiic'), options: platformGuides.map(guideToSelectOption)},
  93. {label: t('Generic'), options: genericGuides.map(guideToSelectOption)},
  94. ];
  95. const platformSpecific = platformGuides.filter(guide =>
  96. guide.platforms?.has(monitor.project.platform ?? 'other')
  97. );
  98. const defaultExample = platformSpecific.length > 0 ? platformSpecific[0].key : 'cli';
  99. const [selectedGuide, setSelectedGuide] = useState(defaultExample);
  100. const {Guide} = onboardingGuides[selectedGuide];
  101. return (
  102. <Container>
  103. <CompactSelect
  104. options={exampleOptions}
  105. value={selectedGuide}
  106. onChange={({value}) => setSelectedGuide(value)}
  107. />
  108. <Guide slug={monitor.slug} orgSlug={orgId} dsnKey={projectKeys?.[0].dsn.public} />
  109. </Container>
  110. );
  111. }
  112. const Container = styled('div')`
  113. display: flex;
  114. flex-direction: column;
  115. gap: ${space(2)};
  116. `;