overview.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import {openBulkEditMonitorsModal} from 'sentry/actionCreators/modal';
  5. import {Button} from 'sentry/components/button';
  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 {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  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, IconList} 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 type {Monitor} from './types';
  37. import {makeMonitorListQueryKey} from './utils';
  38. const CronsListPageHeader = HookOrDefault({
  39. hookName: 'component:crons-list-page-header',
  40. });
  41. export default function Monitors() {
  42. const organization = useOrganization();
  43. const router = useRouter();
  44. const platform = decodeScalar(router.location.query?.platform) ?? null;
  45. const guide = decodeScalar(router.location.query?.guide);
  46. const queryKey = makeMonitorListQueryKey(organization, router.location.query);
  47. const {
  48. data: monitorList,
  49. getResponseHeader: monitorListHeaders,
  50. isLoading,
  51. refetch,
  52. } = useApiQuery<Monitor[]>(queryKey, {
  53. staleTime: 0,
  54. });
  55. useRouteAnalyticsEventNames('monitors.page_viewed', 'Monitors: Page Viewed');
  56. useRouteAnalyticsParams({empty_state: !monitorList || monitorList.length === 0});
  57. const monitorListPageLinks = monitorListHeaders?.('Link');
  58. const handleSearch = (query: string) => {
  59. const currentQuery = {...(router.location.query ?? {}), cursor: undefined};
  60. router.push({
  61. pathname: location.pathname,
  62. query: normalizeDateTimeParams({...currentQuery, query}),
  63. });
  64. };
  65. const showAddMonitor = !isValidPlatform(platform) || !isValidGuide(guide);
  66. return (
  67. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  68. <CronsListPageHeader organization={organization} />
  69. <Layout.Page>
  70. <Layout.Header>
  71. <Layout.HeaderContent>
  72. <Layout.Title>
  73. {t('Cron Monitors')}
  74. <PageHeadingQuestionTooltip
  75. title={t(
  76. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  77. )}
  78. docsUrl="https://docs.sentry.io/product/crons/"
  79. />
  80. </Layout.Title>
  81. </Layout.HeaderContent>
  82. <Layout.HeaderActions>
  83. <ButtonBar gap={1}>
  84. <FeedbackWidgetButton />
  85. <Button
  86. icon={<IconList />}
  87. size="sm"
  88. onClick={() =>
  89. openBulkEditMonitorsModal({
  90. onClose: refetch,
  91. })
  92. }
  93. analyticsEventKey="crons.bulk_edit_modal_button_clicked"
  94. analyticsEventName="Crons: Bulk Edit Modal Button Clicked"
  95. >
  96. {t('Manage Monitors')}
  97. </Button>
  98. {showAddMonitor && (
  99. <NewMonitorButton size="sm" icon={<IconAdd isCircled />}>
  100. {t('Add Monitor')}
  101. </NewMonitorButton>
  102. )}
  103. </ButtonBar>
  104. </Layout.HeaderActions>
  105. </Layout.Header>
  106. <Layout.Body>
  107. <Layout.Main fullWidth>
  108. <Filters>
  109. <PageFilterBar>
  110. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  111. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  112. <DatePageFilter resetParamsOnChange={['cursor']} />
  113. </PageFilterBar>
  114. <SearchBar
  115. query={decodeScalar(qs.parse(location.search)?.query, '')}
  116. placeholder={t('Search by name or slug')}
  117. onSearch={handleSearch}
  118. />
  119. </Filters>
  120. {isLoading ? (
  121. <LoadingIndicator />
  122. ) : monitorList?.length ? (
  123. <Fragment>
  124. <OverviewTimeline monitorList={monitorList} />
  125. {monitorListPageLinks && <Pagination pageLinks={monitorListPageLinks} />}
  126. </Fragment>
  127. ) : (
  128. <CronsLandingPanel />
  129. )}
  130. </Layout.Main>
  131. </Layout.Body>
  132. </Layout.Page>
  133. </SentryDocumentTitle>
  134. );
  135. }
  136. const Filters = styled('div')`
  137. display: grid;
  138. grid-template-columns: max-content 1fr;
  139. gap: ${space(1.5)};
  140. margin-bottom: ${space(2)};
  141. `;