overview.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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} 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. return (
  53. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  54. <Layout.Page>
  55. <Layout.Header>
  56. <Layout.HeaderContent>
  57. <Layout.Title>
  58. {t('Cron Monitors')}
  59. <PageHeadingQuestionTooltip
  60. title={t(
  61. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  62. )}
  63. docsUrl="https://docs.sentry.io/product/crons/"
  64. />
  65. <FeatureBadge type="beta" />
  66. </Layout.Title>
  67. </Layout.HeaderContent>
  68. <Layout.HeaderActions>
  69. <ButtonBar gap={1}>
  70. <CronsFeedbackButton />
  71. <NewMonitorButton size="sm" icon={<IconAdd isCircled size="xs" />}>
  72. {t('Add Monitor')}
  73. </NewMonitorButton>
  74. </ButtonBar>
  75. </Layout.HeaderActions>
  76. </Layout.Header>
  77. <Layout.Body>
  78. <Layout.Main fullWidth>
  79. <Filters>
  80. <PageFilterBar>
  81. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  82. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  83. </PageFilterBar>
  84. <SearchBar
  85. query={decodeScalar(qs.parse(location.search)?.query, '')}
  86. placeholder={t('Search by name or slug')}
  87. onSearch={handleSearch}
  88. />
  89. </Filters>
  90. {isLoading ? (
  91. <LoadingIndicator />
  92. ) : monitorList?.length ? (
  93. <Fragment>
  94. <OverviewTimeline monitorList={monitorList} />
  95. {monitorListPageLinks && <Pagination pageLinks={monitorListPageLinks} />}
  96. </Fragment>
  97. ) : (
  98. <CronsLandingPanel />
  99. )}
  100. </Layout.Main>
  101. </Layout.Body>
  102. </Layout.Page>
  103. </SentryDocumentTitle>
  104. );
  105. }
  106. const Filters = styled('div')`
  107. display: grid;
  108. grid-template-columns: max-content 1fr;
  109. gap: ${space(1.5)};
  110. margin-bottom: ${space(2)};
  111. `;