cronsLandingPanel.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {useState} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import onboardingImg from 'sentry-images/spot/onboarding-preview.svg';
  5. import {Button, LinkButton} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import OnboardingPanel from 'sentry/components/onboardingPanel';
  8. import Panel from 'sentry/components/panels/panel';
  9. import PanelBody from 'sentry/components/panels/panelBody';
  10. import {TabList, TabPanels, Tabs} from 'sentry/components/tabs';
  11. import {PlatformKey} from 'sentry/data/platformCategories';
  12. import {IconChevron} from 'sentry/icons';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  17. import MonitorForm from 'sentry/views/monitors/components/monitorForm';
  18. import {Monitor} from 'sentry/views/monitors/types';
  19. import {NewMonitorButton} from './newMonitorButton';
  20. import {
  21. CRON_SDK_PLATFORMS,
  22. PlatformPickerPanel,
  23. SupportedPlatform,
  24. } from './platformPickerPanel';
  25. import {
  26. CeleryBeatAutoDiscovery,
  27. LaravelUpsertPlatformGuide,
  28. NodeJsUpsertPlatformGuide,
  29. PHPUpsertPlatformGuide,
  30. QuickStartProps,
  31. } from './quickStartEntries';
  32. interface PlatformGuide {
  33. Guide: React.ComponentType<QuickStartProps>;
  34. title: string;
  35. }
  36. const platformGuides: Record<SupportedPlatform, PlatformGuide[]> = {
  37. 'python-celery': [
  38. {
  39. Guide: CeleryBeatAutoDiscovery,
  40. title: 'Beat Auto Discovery',
  41. },
  42. ],
  43. php: [
  44. {
  45. Guide: PHPUpsertPlatformGuide,
  46. title: 'Upsert',
  47. },
  48. ],
  49. 'php-laravel': [
  50. {
  51. Guide: LaravelUpsertPlatformGuide,
  52. title: 'Upsert',
  53. },
  54. ],
  55. python: [],
  56. node: [
  57. {
  58. Guide: NodeJsUpsertPlatformGuide,
  59. title: 'Upsert',
  60. },
  61. ],
  62. };
  63. export function CronsLandingPanel() {
  64. const organization = useOrganization();
  65. const [platform, setPlatform] = useState<PlatformKey | null>(null);
  66. if (!platform) {
  67. return <PlatformPickerPanel onSelect={setPlatform} />;
  68. }
  69. const platformText = CRON_SDK_PLATFORMS.find(
  70. ({platform: sdkPlatform}) => sdkPlatform === platform
  71. )?.label;
  72. const guides = platformGuides[platform];
  73. function onCreateMonitor(data: Monitor) {
  74. const url = normalizeUrl(`/organizations/${organization.slug}/crons/${data.slug}/`);
  75. browserHistory.push(url);
  76. }
  77. return (
  78. <Panel>
  79. <BackButton
  80. icon={<IconChevron size="sm" direction="left" />}
  81. onClick={() => setPlatform(null)}
  82. borderless
  83. >
  84. {t('Back to Platforms')}
  85. </BackButton>
  86. <PanelBody withPadding>
  87. <h3>{t('Get Started with %s', platformText)}</h3>
  88. <Tabs>
  89. <TabList>
  90. {[
  91. ...guides.map(({title}) => (
  92. <TabList.Item key={title}>{title}</TabList.Item>
  93. )),
  94. <TabList.Item key="manual">{t('Manual')}</TabList.Item>,
  95. ]}
  96. </TabList>
  97. <TabPanels>
  98. {[
  99. ...guides.map(({title, Guide}) => (
  100. <TabPanels.Item key={title}>
  101. <GuideContainer>
  102. <Guide />
  103. </GuideContainer>
  104. </TabPanels.Item>
  105. )),
  106. <TabPanels.Item key="manual">
  107. <GuideContainer>
  108. <MonitorForm
  109. apiMethod="POST"
  110. apiEndpoint={`/organizations/${organization.slug}/monitors/`}
  111. onSubmitSuccess={onCreateMonitor}
  112. submitLabel={t('Next')}
  113. />
  114. </GuideContainer>
  115. </TabPanels.Item>,
  116. ]}
  117. </TabPanels>
  118. </Tabs>
  119. </PanelBody>
  120. </Panel>
  121. );
  122. }
  123. const BackButton = styled(Button)`
  124. font-weight: normal;
  125. color: ${p => p.theme.subText};
  126. margin: ${space(1)} 0 0 ${space(1)};
  127. padding-left: ${space(0.5)};
  128. padding-right: ${space(0.5)};
  129. `;
  130. const GuideContainer = styled('div')`
  131. display: flex;
  132. flex-direction: column;
  133. gap: ${space(2)};
  134. padding-top: ${space(2)};
  135. `;
  136. export function OldCronsLandingPanel() {
  137. return (
  138. <OnboardingPanel image={<img src={onboardingImg} />}>
  139. <h3>{t('Let Sentry monitor your recurring jobs')}</h3>
  140. <p>
  141. {t(
  142. "We'll tell you if your recurring jobs are running on schedule, failing, or succeeding."
  143. )}
  144. </p>
  145. <OnboardingActions gap={1}>
  146. <NewMonitorButton>{t('Set up first cron monitor')}</NewMonitorButton>
  147. <LinkButton href="https://docs.sentry.io/product/crons" external>
  148. {t('Read docs')}
  149. </LinkButton>
  150. </OnboardingActions>
  151. </OnboardingPanel>
  152. );
  153. }
  154. const OnboardingActions = styled(ButtonBar)`
  155. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  156. `;