details.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 {useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import usePageFilters from 'sentry/utils/usePageFilters';
  13. import MonitorCheckIns from './components/monitorCheckIns';
  14. import MonitorHeader from './components/monitorHeader';
  15. import MonitorIssues from './components/monitorIssues';
  16. import MonitorStats from './components/monitorStats';
  17. import MonitorOnboarding from './components/onboarding';
  18. import {Monitor} from './types';
  19. type Props = RouteComponentProps<{monitorSlug: string}, {}>;
  20. function MonitorDetails({params, location}: Props) {
  21. const {selection} = usePageFilters();
  22. const organization = useOrganization();
  23. const queryClient = useQueryClient();
  24. // TODO(epurkhiser): For now we just use the fist environment OR production
  25. // if we have all environments selected
  26. const environment = selection.environments[0] ?? 'production';
  27. const queryKey = [
  28. `/organizations/${organization.slug}/monitors/${params.monitorSlug}/`,
  29. {query: {...location.query, environment}},
  30. ] as const;
  31. const {data: monitor} = useApiQuery<Monitor>(queryKey, {staleTime: 0});
  32. function onUpdate(data: Monitor) {
  33. queryClient.setQueryData(queryKey, data);
  34. }
  35. if (!monitor) {
  36. return (
  37. <Layout.Page>
  38. <LoadingIndicator />
  39. </Layout.Page>
  40. );
  41. }
  42. const monitorEnv = monitor.environments.find(env => env.name === environment);
  43. return (
  44. <SentryDocumentTitle title={`Crons - ${monitor.name}`}>
  45. <Layout.Page>
  46. <MonitorHeader
  47. monitor={monitor}
  48. monitorEnv={monitorEnv}
  49. orgId={organization.slug}
  50. onUpdate={onUpdate}
  51. />
  52. <Layout.Body>
  53. <Layout.Main fullWidth>
  54. {!monitorEnv?.lastCheckIn ? (
  55. <MonitorOnboarding orgId={organization.slug} monitor={monitor} />
  56. ) : (
  57. <Fragment>
  58. <StyledPageFilterBar condensed>
  59. <DatePageFilter alignDropdown="left" />
  60. </StyledPageFilterBar>
  61. <MonitorStats
  62. orgId={organization.slug}
  63. monitor={monitor}
  64. monitorEnv={monitorEnv}
  65. />
  66. <MonitorIssues
  67. orgId={organization.slug}
  68. monitor={monitor}
  69. monitorEnv={monitorEnv}
  70. />
  71. <MonitorCheckIns
  72. orgId={organization.slug}
  73. monitor={monitor}
  74. monitorEnv={monitorEnv}
  75. />
  76. </Fragment>
  77. )}
  78. </Layout.Main>
  79. </Layout.Body>
  80. </Layout.Page>
  81. </SentryDocumentTitle>
  82. );
  83. }
  84. const StyledPageFilterBar = styled(PageFilterBar)`
  85. margin-bottom: ${space(2)};
  86. `;
  87. export default MonitorDetails;