overview.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 {decodeList, 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 {OwnerFilter} from './components/ownerFilter';
  37. import type {Monitor} from './types';
  38. import {makeMonitorListQueryKey} from './utils';
  39. const CronsListPageHeader = HookOrDefault({
  40. hookName: 'component:crons-list-page-header',
  41. });
  42. export default function Monitors() {
  43. const organization = useOrganization();
  44. const router = useRouter();
  45. const platform = decodeScalar(router.location.query?.platform) ?? null;
  46. const guide = decodeScalar(router.location.query?.guide);
  47. const queryKey = makeMonitorListQueryKey(organization, router.location.query);
  48. const {
  49. data: monitorList,
  50. getResponseHeader: monitorListHeaders,
  51. isLoading,
  52. refetch,
  53. } = useApiQuery<Monitor[]>(queryKey, {
  54. staleTime: 0,
  55. });
  56. useRouteAnalyticsEventNames('monitors.page_viewed', 'Monitors: Page Viewed');
  57. useRouteAnalyticsParams({empty_state: !monitorList || monitorList.length === 0});
  58. const monitorListPageLinks = monitorListHeaders?.('Link');
  59. const handleSearch = (query: string) => {
  60. const currentQuery = {...(router.location.query ?? {}), cursor: undefined};
  61. router.push({
  62. pathname: location.pathname,
  63. query: normalizeDateTimeParams({...currentQuery, query}),
  64. });
  65. };
  66. const showAddMonitor = !isValidPlatform(platform) || !isValidGuide(guide);
  67. return (
  68. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  69. <CronsListPageHeader organization={organization} />
  70. <Layout.Page>
  71. <Layout.Header>
  72. <Layout.HeaderContent>
  73. <Layout.Title>
  74. {t('Cron Monitors')}
  75. <PageHeadingQuestionTooltip
  76. title={t(
  77. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  78. )}
  79. docsUrl="https://docs.sentry.io/product/crons/"
  80. />
  81. </Layout.Title>
  82. </Layout.HeaderContent>
  83. <Layout.HeaderActions>
  84. <ButtonBar gap={1}>
  85. <FeedbackWidgetButton />
  86. <Button
  87. icon={<IconList />}
  88. size="sm"
  89. onClick={() =>
  90. openBulkEditMonitorsModal({
  91. onClose: refetch,
  92. })
  93. }
  94. analyticsEventKey="crons.bulk_edit_modal_button_clicked"
  95. analyticsEventName="Crons: Bulk Edit Modal Button Clicked"
  96. >
  97. {t('Manage Monitors')}
  98. </Button>
  99. {showAddMonitor && (
  100. <NewMonitorButton size="sm" icon={<IconAdd isCircled />}>
  101. {t('Add Monitor')}
  102. </NewMonitorButton>
  103. )}
  104. </ButtonBar>
  105. </Layout.HeaderActions>
  106. </Layout.Header>
  107. <Layout.Body>
  108. <Layout.Main fullWidth>
  109. <Filters>
  110. <OwnerFilter
  111. selectedOwners={decodeList(router.location.query.owner)}
  112. onChangeFilter={owner =>
  113. router.replace({
  114. ...router.location,
  115. query: {...router.location.query, owner},
  116. })
  117. }
  118. />
  119. <PageFilterBar>
  120. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  121. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  122. <DatePageFilter 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. ) : (
  138. <CronsLandingPanel />
  139. )}
  140. </Layout.Main>
  141. </Layout.Body>
  142. </Layout.Page>
  143. </SentryDocumentTitle>
  144. );
  145. }
  146. const Filters = styled('div')`
  147. display: flex;
  148. gap: ${space(1.5)};
  149. margin-bottom: ${space(2)};
  150. > :last-child {
  151. flex-grow: 1;
  152. }
  153. `;