overview.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 {deleteProjectProcessingErrorByType} from 'sentry/actionCreators/monitors';
  6. import {Button} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  9. import HookOrDefault from 'sentry/components/hookOrDefault';
  10. import * as Layout from 'sentry/components/layouts/thirds';
  11. import LoadingIndicator from 'sentry/components/loadingIndicator';
  12. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  13. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  14. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  15. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  16. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  17. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  18. import Pagination from 'sentry/components/pagination';
  19. import SearchBar from 'sentry/components/searchBar';
  20. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  21. import {IconAdd, IconList} from 'sentry/icons';
  22. import {t} from 'sentry/locale';
  23. import {space} from 'sentry/styles/space';
  24. import {useApiQuery} from 'sentry/utils/queryClient';
  25. import {decodeList, decodeScalar} from 'sentry/utils/queryString';
  26. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  27. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  28. import useApi from 'sentry/utils/useApi';
  29. import {useLocation} from 'sentry/utils/useLocation';
  30. import {useNavigate} from 'sentry/utils/useNavigate';
  31. import useOrganization from 'sentry/utils/useOrganization';
  32. import MonitorProcessingErrors from 'sentry/views/monitors/components/processingErrors/monitorProcessingErrors';
  33. import {makeMonitorListErrorsQueryKey} from 'sentry/views/monitors/components/processingErrors/utils';
  34. import {
  35. CronsLandingPanel,
  36. isValidGuide,
  37. isValidPlatform,
  38. } from './components/cronsLandingPanel';
  39. import {NewMonitorButton} from './components/newMonitorButton';
  40. import {OverviewTimeline} from './components/overviewTimeline';
  41. import {OwnerFilter} from './components/ownerFilter';
  42. import type {CheckinProcessingError, Monitor, ProcessingErrorType} from './types';
  43. import {makeMonitorListQueryKey} from './utils';
  44. const CronsListPageHeader = HookOrDefault({
  45. hookName: 'component:crons-list-page-header',
  46. });
  47. export default function Monitors() {
  48. const api = useApi();
  49. const organization = useOrganization();
  50. const navigate = useNavigate();
  51. const location = useLocation();
  52. const platform = decodeScalar(location.query?.platform) ?? null;
  53. const guide = decodeScalar(location.query?.guide);
  54. const project = decodeList(location.query?.project);
  55. const queryKey = makeMonitorListQueryKey(organization, location.query);
  56. const {
  57. data: monitorList,
  58. getResponseHeader: monitorListHeaders,
  59. isLoading,
  60. refetch,
  61. } = useApiQuery<Monitor[]>(queryKey, {
  62. staleTime: 0,
  63. });
  64. const processingErrorQueryKey = makeMonitorListErrorsQueryKey(organization, project);
  65. const {data: processingErrors, refetch: refetchErrors} = useApiQuery<
  66. CheckinProcessingError[]
  67. >(processingErrorQueryKey, {
  68. staleTime: 0,
  69. });
  70. useRouteAnalyticsEventNames('monitors.page_viewed', 'Monitors: Page Viewed');
  71. useRouteAnalyticsParams({empty_state: !monitorList || monitorList.length === 0});
  72. const monitorListPageLinks = monitorListHeaders?.('Link');
  73. const handleSearch = (query: string) => {
  74. const currentQuery = {...(location.query ?? {}), cursor: undefined};
  75. navigate({
  76. pathname: location.pathname,
  77. query: normalizeDateTimeParams({...currentQuery, query}),
  78. });
  79. };
  80. function handleDismissError(errortype: ProcessingErrorType, projectId: string) {
  81. deleteProjectProcessingErrorByType(api, organization.slug, projectId, errortype);
  82. refetchErrors();
  83. }
  84. const showAddMonitor = !isValidPlatform(platform) || !isValidGuide(guide);
  85. return (
  86. <SentryDocumentTitle title={`Crons — ${organization.slug}`}>
  87. <CronsListPageHeader organization={organization} />
  88. <Layout.Page>
  89. <Layout.Header>
  90. <Layout.HeaderContent>
  91. <Layout.Title>
  92. {t('Cron Monitors')}
  93. <PageHeadingQuestionTooltip
  94. title={t(
  95. 'Scheduled monitors that check in on recurring jobs and tell you if they’re running on schedule, failing, or succeeding.'
  96. )}
  97. docsUrl="https://docs.sentry.io/product/crons/"
  98. />
  99. </Layout.Title>
  100. </Layout.HeaderContent>
  101. <Layout.HeaderActions>
  102. <ButtonBar gap={1}>
  103. <FeedbackWidgetButton />
  104. <Button
  105. icon={<IconList />}
  106. size="sm"
  107. onClick={() =>
  108. openBulkEditMonitorsModal({
  109. onClose: refetch,
  110. })
  111. }
  112. analyticsEventKey="crons.bulk_edit_modal_button_clicked"
  113. analyticsEventName="Crons: Bulk Edit Modal Button Clicked"
  114. >
  115. {t('Manage Monitors')}
  116. </Button>
  117. {showAddMonitor && (
  118. <NewMonitorButton size="sm" icon={<IconAdd isCircled />}>
  119. {t('Add Monitor')}
  120. </NewMonitorButton>
  121. )}
  122. </ButtonBar>
  123. </Layout.HeaderActions>
  124. </Layout.Header>
  125. <Layout.Body>
  126. <Layout.Main fullWidth>
  127. <Filters>
  128. <OwnerFilter
  129. selectedOwners={decodeList(location.query.owner)}
  130. onChangeFilter={owner => {
  131. navigate(
  132. {
  133. ...location,
  134. query: {...location.query, owner},
  135. },
  136. {replace: true}
  137. );
  138. }}
  139. />
  140. <PageFilterBar>
  141. <ProjectPageFilter resetParamsOnChange={['cursor']} />
  142. <EnvironmentPageFilter resetParamsOnChange={['cursor']} />
  143. <DatePageFilter resetParamsOnChange={['cursor']} />
  144. </PageFilterBar>
  145. <SearchBar
  146. query={decodeScalar(qs.parse(location.search)?.query, '')}
  147. placeholder={t('Search by name or slug')}
  148. onSearch={handleSearch}
  149. />
  150. </Filters>
  151. {!!processingErrors?.length && (
  152. <MonitorProcessingErrors
  153. checkinErrors={processingErrors}
  154. onDismiss={handleDismissError}
  155. >
  156. {t(
  157. 'Errors were encountered while ingesting check-ins for the selected projects'
  158. )}
  159. </MonitorProcessingErrors>
  160. )}
  161. {isLoading ? (
  162. <LoadingIndicator />
  163. ) : monitorList?.length ? (
  164. <Fragment>
  165. <OverviewTimeline monitorList={monitorList} />
  166. {monitorListPageLinks && <Pagination pageLinks={monitorListPageLinks} />}
  167. </Fragment>
  168. ) : (
  169. <CronsLandingPanel />
  170. )}
  171. </Layout.Main>
  172. </Layout.Body>
  173. </Layout.Page>
  174. </SentryDocumentTitle>
  175. );
  176. }
  177. const Filters = styled('div')`
  178. display: flex;
  179. gap: ${space(1.5)};
  180. margin-bottom: ${space(2)};
  181. > :last-child {
  182. flex-grow: 1;
  183. }
  184. `;