overview.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import EnvironmentPageFilter from 'sentry/components/environmentPageFilter';
  6. import FeatureBadge from 'sentry/components/featureBadge';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import LoadingIndicator from 'sentry/components/loadingIndicator';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  11. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  12. import Pagination from 'sentry/components/pagination';
  13. import ProjectPageFilter from 'sentry/components/projectPageFilter';
  14. import SearchBar from 'sentry/components/searchBar';
  15. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  16. import {IconAdd} from 'sentry/icons';
  17. import {t} from 'sentry/locale';
  18. import {space} from 'sentry/styles/space';
  19. import {useApiQuery} from 'sentry/utils/queryClient';
  20. import {decodeScalar} from 'sentry/utils/queryString';
  21. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  22. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  23. import useOrganization from 'sentry/utils/useOrganization';
  24. import useRouter from 'sentry/utils/useRouter';
  25. import CronsFeedbackButton from './components/cronsFeedbackButton';
  26. import {CronsLandingPanel, OldCronsLandingPanel} from './components/cronsLandingPanel';
  27. import {NewMonitorButton} from './components/newMonitorButton';
  28. import {OverviewTimeline} from './components/overviewTimeline';
  29. import {Monitor} from './types';
  30. import {makeMonitorListQueryKey} from './utils';
  31. export default function Monitors() {
  32. const organization = useOrganization();
  33. const router = useRouter();
  34. const queryKey = makeMonitorListQueryKey(organization, router.location);
  35. const {
  36. data: monitorList,
  37. getResponseHeader: monitorListHeaders,
  38. isLoading,
  39. } = useApiQuery<Monitor[]>(queryKey, {
  40. staleTime: 0,
  41. });
  42. useRouteAnalyticsEventNames('monitors.page_viewed', 'Monitors: Page Viewed');
  43. useRouteAnalyticsParams({empty_state: !monitorList || monitorList.length === 0});
  44. const monitorListPageLinks = monitorListHeaders?.('Link');
  45. const handleSearch = (query: string) => {
  46. const currentQuery = {...(router.location.query ?? {}), cursor: undefined};
  47. router.push({
  48. pathname: location.pathname,
  49. query: normalizeDateTimeParams({...currentQuery, query}),
  50. });
  51. };
  52. const shouldShowNewOnboarding = organization.features.includes('crons-new-onboarding');
  53. const onboardingComponent = shouldShowNewOnboarding ? (
  54. <CronsLandingPanel />
  55. ) : (
  56. <OldCronsLandingPanel />
  57. );
  58. return (
  59. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  60. <Layout.Page>
  61. <Layout.Header>
  62. <Layout.HeaderContent>
  63. <Layout.Title>
  64. {t('Cron Monitors')}
  65. <PageHeadingQuestionTooltip
  66. title={t(
  67. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  68. )}
  69. docsUrl="https://docs.sentry.io/product/crons/"
  70. />
  71. <FeatureBadge type="beta" />
  72. </Layout.Title>
  73. </Layout.HeaderContent>
  74. <Layout.HeaderActions>
  75. <ButtonBar gap={1}>
  76. <CronsFeedbackButton />
  77. <NewMonitorButton size="sm" icon={<IconAdd isCircled size="xs" />}>
  78. {t('Add Monitor')}
  79. </NewMonitorButton>
  80. </ButtonBar>
  81. </Layout.HeaderActions>
  82. </Layout.Header>
  83. <Layout.Body>
  84. <Layout.Main fullWidth>
  85. <Filters>
  86. <PageFilterBar>
  87. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  88. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  89. </PageFilterBar>
  90. <SearchBar
  91. query={decodeScalar(qs.parse(location.search)?.query, '')}
  92. placeholder={t('Search by name or slug')}
  93. onSearch={handleSearch}
  94. />
  95. </Filters>
  96. {isLoading ? (
  97. <LoadingIndicator />
  98. ) : monitorList?.length ? (
  99. <Fragment>
  100. <OverviewTimeline monitorList={monitorList} />
  101. {monitorListPageLinks && <Pagination pageLinks={monitorListPageLinks} />}
  102. </Fragment>
  103. ) : (
  104. onboardingComponent
  105. )}
  106. </Layout.Main>
  107. </Layout.Body>
  108. </Layout.Page>
  109. </SentryDocumentTitle>
  110. );
  111. }
  112. const Filters = styled('div')`
  113. display: grid;
  114. grid-template-columns: max-content 1fr;
  115. gap: ${space(1.5)};
  116. margin-bottom: ${space(2)};
  117. `;