overview.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import onboardingImg from 'sentry-images/spot/onboarding-preview.svg';
  5. import Alert from 'sentry/components/alert';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  8. import HookOrDefault from 'sentry/components/hookOrDefault';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import LoadingIndicator from 'sentry/components/loadingIndicator';
  11. import OnboardingPanel from 'sentry/components/onboardingPanel';
  12. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  13. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  14. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  15. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  16. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  17. import Pagination from 'sentry/components/pagination';
  18. import SearchBar from 'sentry/components/searchBar';
  19. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  20. import {IconAdd} from 'sentry/icons';
  21. import {t} from 'sentry/locale';
  22. import {space} from 'sentry/styles/space';
  23. import {useApiQuery} from 'sentry/utils/queryClient';
  24. import {decodeScalar} from 'sentry/utils/queryString';
  25. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  26. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  27. import useOrganization from 'sentry/utils/useOrganization';
  28. import useRouter from 'sentry/utils/useRouter';
  29. import {
  30. CronsLandingPanel,
  31. isValidGuide,
  32. isValidPlatform,
  33. } from './components/cronsLandingPanel';
  34. import {NewMonitorButton} from './components/newMonitorButton';
  35. import {OverviewTimeline} from './components/overviewTimeline';
  36. import {Monitor} from './types';
  37. import {makeMonitorListQueryKey} from './utils';
  38. function DisabledMonitorCreationPanel() {
  39. return (
  40. <OnboardingPanel image={<img src={onboardingImg} />}>
  41. <h3>{t('Monitor Your Cron Jobs')}</h3>
  42. <Alert type="warning" showIcon>
  43. {t(
  44. 'The Crons beta is over. Adding new monitors for projects without existing ones is temporarily disabled until our launch preparations are complete. Please try again after January 11th, 2024.'
  45. )}
  46. </Alert>
  47. </OnboardingPanel>
  48. );
  49. }
  50. const CronsListPageHeader = HookOrDefault({
  51. hookName: 'component:crons-list-page-header',
  52. });
  53. export default function Monitors() {
  54. const organization = useOrganization();
  55. const router = useRouter();
  56. const platform = decodeScalar(router.location.query?.platform) ?? null;
  57. const guide = decodeScalar(router.location.query?.guide);
  58. const queryKey = makeMonitorListQueryKey(organization, router.location);
  59. const {
  60. data: monitorList,
  61. getResponseHeader: monitorListHeaders,
  62. isLoading,
  63. } = useApiQuery<Monitor[]>(queryKey, {
  64. staleTime: 0,
  65. });
  66. useRouteAnalyticsEventNames('monitors.page_viewed', 'Monitors: Page Viewed');
  67. useRouteAnalyticsParams({empty_state: !monitorList || monitorList.length === 0});
  68. const monitorListPageLinks = monitorListHeaders?.('Link');
  69. const handleSearch = (query: string) => {
  70. const currentQuery = {...(router.location.query ?? {}), cursor: undefined};
  71. router.push({
  72. pathname: location.pathname,
  73. query: normalizeDateTimeParams({...currentQuery, query}),
  74. });
  75. };
  76. const disableNewMonitors =
  77. organization.features.includes('crons-disable-new-projects') &&
  78. (isLoading || monitorList?.length === 0);
  79. const showAddMonitor = !isValidPlatform(platform) || !isValidGuide(guide);
  80. return (
  81. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  82. <CronsListPageHeader organization={organization} />
  83. <Layout.Page>
  84. <Layout.Header>
  85. <Layout.HeaderContent>
  86. <Layout.Title>
  87. {t('Cron Monitors')}
  88. <PageHeadingQuestionTooltip
  89. title={t(
  90. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  91. )}
  92. docsUrl="https://docs.sentry.io/product/crons/"
  93. />
  94. </Layout.Title>
  95. </Layout.HeaderContent>
  96. <Layout.HeaderActions>
  97. <ButtonBar gap={1}>
  98. <FeedbackWidgetButton />
  99. {showAddMonitor && (
  100. <NewMonitorButton
  101. size="sm"
  102. icon={<IconAdd isCircled />}
  103. disabled={disableNewMonitors}
  104. title={
  105. disableNewMonitors &&
  106. t(
  107. 'Adding new monitors for projects without existing ones is temporarily disabled until our launch preparations are complete.'
  108. )
  109. }
  110. >
  111. {t('Add Monitor')}
  112. </NewMonitorButton>
  113. )}
  114. </ButtonBar>
  115. </Layout.HeaderActions>
  116. </Layout.Header>
  117. <Layout.Body>
  118. <Layout.Main fullWidth>
  119. <Filters>
  120. <PageFilterBar>
  121. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  122. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  123. </PageFilterBar>
  124. <SearchBar
  125. query={decodeScalar(qs.parse(location.search)?.query, '')}
  126. placeholder={t('Search by name or slug')}
  127. onSearch={handleSearch}
  128. />
  129. </Filters>
  130. {isLoading ? (
  131. <LoadingIndicator />
  132. ) : monitorList?.length ? (
  133. <Fragment>
  134. <OverviewTimeline monitorList={monitorList} />
  135. {monitorListPageLinks && <Pagination pageLinks={monitorListPageLinks} />}
  136. </Fragment>
  137. ) : disableNewMonitors ? (
  138. <DisabledMonitorCreationPanel />
  139. ) : (
  140. <CronsLandingPanel />
  141. )}
  142. </Layout.Main>
  143. </Layout.Body>
  144. </Layout.Page>
  145. </SentryDocumentTitle>
  146. );
  147. }
  148. const Filters = styled('div')`
  149. display: grid;
  150. grid-template-columns: max-content 1fr;
  151. gap: ${space(1.5)};
  152. margin-bottom: ${space(2)};
  153. `;