monitorQuickStartGuide.tsx 3.2 KB

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