details.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import DatePageFilter from 'sentry/components/datePageFilter';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import LoadingIndicator from 'sentry/components/loadingIndicator';
  7. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  8. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  9. import {space} from 'sentry/styles/space';
  10. import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import usePageFilters from 'sentry/utils/usePageFilters';
  13. import DetailsSidebar from 'sentry/views/monitors/components/detailsSidebar';
  14. import MonitorCheckIns from './components/monitorCheckIns';
  15. import MonitorHeader from './components/monitorHeader';
  16. import MonitorIssues from './components/monitorIssues';
  17. import MonitorStats from './components/monitorStats';
  18. import MonitorOnboarding from './components/onboarding';
  19. import {Monitor} from './types';
  20. type Props = RouteComponentProps<{monitorSlug: string}, {}>;
  21. function MonitorDetails({params, location}: Props) {
  22. const {selection} = usePageFilters();
  23. const organization = useOrganization();
  24. const queryClient = useQueryClient();
  25. // TODO(epurkhiser): For now we just use the fist environment OR production
  26. // if we have all environments selected
  27. const environment = selection.environments[0];
  28. const queryKey = [
  29. `/organizations/${organization.slug}/monitors/${params.monitorSlug}/`,
  30. {query: {...location.query, environment}},
  31. ] as const;
  32. const {data: monitor} = useApiQuery<Monitor>(queryKey, {staleTime: 0});
  33. function onUpdate(data: Monitor) {
  34. const updatedMonitor = {
  35. ...data,
  36. // TODO(davidenwang): This is a bit of a hack, due to the PUT request
  37. // which pauses/unpauses a monitor not returning monitor environments
  38. // we should reuse the environments retrieved from the initial request
  39. environments: monitor?.environments,
  40. };
  41. setApiQueryData(queryClient, queryKey, updatedMonitor);
  42. }
  43. if (!monitor) {
  44. return (
  45. <Layout.Page>
  46. <LoadingIndicator />
  47. </Layout.Page>
  48. );
  49. }
  50. const monitorEnv = monitor.environments.find(env => env.name === environment);
  51. return (
  52. <SentryDocumentTitle title={`Crons - ${monitor.name}`}>
  53. <Layout.Page>
  54. <MonitorHeader monitor={monitor} orgId={organization.slug} onUpdate={onUpdate} />
  55. <Layout.Body>
  56. <Layout.Main>
  57. {!monitorEnv?.lastCheckIn ? (
  58. <MonitorOnboarding orgId={organization.slug} monitor={monitor} />
  59. ) : (
  60. <Fragment>
  61. <StyledPageFilterBar condensed>
  62. <DatePageFilter alignDropdown="left" />
  63. </StyledPageFilterBar>
  64. <MonitorStats
  65. orgId={organization.slug}
  66. monitor={monitor}
  67. monitorEnv={monitorEnv}
  68. />
  69. <MonitorIssues
  70. orgId={organization.slug}
  71. monitor={monitor}
  72. monitorEnv={monitorEnv}
  73. />
  74. <MonitorCheckIns
  75. orgId={organization.slug}
  76. monitor={monitor}
  77. monitorEnv={monitorEnv}
  78. />
  79. </Fragment>
  80. )}
  81. </Layout.Main>
  82. <Layout.Side>
  83. <DetailsSidebar monitorEnv={monitorEnv} monitor={monitor} />
  84. </Layout.Side>
  85. </Layout.Body>
  86. </Layout.Page>
  87. </SentryDocumentTitle>
  88. );
  89. }
  90. const StyledPageFilterBar = styled(PageFilterBar)`
  91. margin-bottom: ${space(2)};
  92. `;
  93. export default MonitorDetails;