overview.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import styled from '@emotion/styled';
  2. import * as qs from 'query-string';
  3. import onboardingImg from 'sentry-images/spot/onboarding-preview.svg';
  4. import {Button, ButtonProps} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  7. import FeatureBadge from 'sentry/components/featureBadge';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import LoadingIndicator from 'sentry/components/loadingIndicator';
  10. import OnboardingPanel from 'sentry/components/onboardingPanel';
  11. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  12. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  13. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  14. import ProjectPageFilter from 'sentry/components/projectPageFilter';
  15. import SearchBar from 'sentry/components/searchBar';
  16. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  17. import {IconAdd} from 'sentry/icons';
  18. import {t} from 'sentry/locale';
  19. import {space} from 'sentry/styles/space';
  20. import {useApiQuery} from 'sentry/utils/queryClient';
  21. import {decodeScalar} from 'sentry/utils/queryString';
  22. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  23. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import usePageFilters from 'sentry/utils/usePageFilters';
  26. import useRouter from 'sentry/utils/useRouter';
  27. import CronsFeedbackButton from './components/cronsFeedbackButton';
  28. import {OverviewTable} from './components/overviewTable';
  29. import {OverviewTimeline} from './components/overviewTimeline';
  30. import {Monitor} from './types';
  31. import {makeMonitorListQueryKey} from './utils';
  32. function NewMonitorButton(props: ButtonProps) {
  33. const organization = useOrganization();
  34. const {selection} = usePageFilters();
  35. return (
  36. <Button
  37. to={{
  38. pathname: `/organizations/${organization.slug}/crons/create/`,
  39. query: {project: selection.projects},
  40. }}
  41. priority="primary"
  42. {...props}
  43. >
  44. {props.children}
  45. </Button>
  46. );
  47. }
  48. export default function Monitors() {
  49. const organization = useOrganization();
  50. const router = useRouter();
  51. const queryKey = makeMonitorListQueryKey(organization, router.location);
  52. const {
  53. data: monitorList,
  54. getResponseHeader: monitorListHeaders,
  55. isLoading,
  56. } = useApiQuery<Monitor[]>(queryKey, {
  57. staleTime: 0,
  58. });
  59. useRouteAnalyticsEventNames('monitors.page_viewed', 'Monitors: Page Viewed');
  60. useRouteAnalyticsParams({empty_state: !monitorList || monitorList.length === 0});
  61. const monitorListPageLinks = monitorListHeaders?.('Link');
  62. const handleSearch = (query: string) => {
  63. const currentQuery = router.location.query ?? {};
  64. router.push({
  65. pathname: location.pathname,
  66. query: normalizeDateTimeParams({...currentQuery, query}),
  67. });
  68. };
  69. const monitorsTimelineView = organization.features.includes(
  70. 'crons-timeline-listing-page'
  71. );
  72. return (
  73. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  74. <Layout.Page>
  75. <Layout.Header>
  76. <Layout.HeaderContent>
  77. <Layout.Title>
  78. {t('Cron Monitors')}
  79. <PageHeadingQuestionTooltip
  80. title={t(
  81. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  82. )}
  83. docsUrl="https://docs.sentry.io/product/crons/"
  84. />
  85. <FeatureBadge type="beta" />
  86. </Layout.Title>
  87. </Layout.HeaderContent>
  88. <Layout.HeaderActions>
  89. <ButtonBar gap={1}>
  90. <CronsFeedbackButton />
  91. <NewMonitorButton size="sm" icon={<IconAdd isCircled size="xs" />}>
  92. {t('Add Monitor')}
  93. </NewMonitorButton>
  94. </ButtonBar>
  95. </Layout.HeaderActions>
  96. </Layout.Header>
  97. <Layout.Body>
  98. <Layout.Main fullWidth>
  99. <Filters>
  100. <PageFilterBar>
  101. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  102. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  103. </PageFilterBar>
  104. <SearchBar
  105. query={decodeScalar(qs.parse(location.search)?.query, '')}
  106. placeholder={t('Search by name or slug')}
  107. onSearch={handleSearch}
  108. />
  109. </Filters>
  110. {isLoading ? (
  111. <LoadingIndicator />
  112. ) : monitorList?.length ? (
  113. monitorsTimelineView ? (
  114. <OverviewTimeline
  115. monitorList={monitorList}
  116. monitorListPageLinks={monitorListPageLinks}
  117. />
  118. ) : (
  119. <OverviewTable
  120. monitorList={monitorList}
  121. monitorListPageLinks={monitorListPageLinks}
  122. />
  123. )
  124. ) : (
  125. <OnboardingPanel image={<img src={onboardingImg} />}>
  126. <h3>{t('Let Sentry monitor your recurring jobs')}</h3>
  127. <p>
  128. {t(
  129. "We'll tell you if your recurring jobs are running on schedule, failing, or succeeding."
  130. )}
  131. </p>
  132. <OnboardingActions gap={1}>
  133. <NewMonitorButton>{t('Set up first cron monitor')}</NewMonitorButton>
  134. <Button href="https://docs.sentry.io/product/crons" external>
  135. {t('Read docs')}
  136. </Button>
  137. </OnboardingActions>
  138. </OnboardingPanel>
  139. )}
  140. </Layout.Main>
  141. </Layout.Body>
  142. </Layout.Page>
  143. </SentryDocumentTitle>
  144. );
  145. }
  146. const Filters = styled('div')`
  147. display: grid;
  148. grid-template-columns: max-content 1fr;
  149. gap: ${space(1.5)};
  150. margin-bottom: ${space(2)};
  151. `;
  152. const OnboardingActions = styled(ButtonBar)`
  153. grid-template-columns: repeat(auto-fit, minmax(130px, max-content));
  154. `;