details.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  7. import {Panel, PanelHeader} from 'sentry/components/panels';
  8. import {t} from 'sentry/locale';
  9. import space from 'sentry/styles/space';
  10. import {Organization} from 'sentry/types';
  11. import withRouteAnalytics, {
  12. WithRouteAnalyticsProps,
  13. } from 'sentry/utils/routeAnalytics/withRouteAnalytics';
  14. import withOrganization from 'sentry/utils/withOrganization';
  15. import AsyncView from 'sentry/views/asyncView';
  16. import MonitorCheckIns from './monitorCheckIns';
  17. import MonitorHeader from './monitorHeader';
  18. import MonitorIssues from './monitorIssues';
  19. import MonitorStats from './monitorStats';
  20. import MonitorOnboarding from './onboarding';
  21. import {Monitor} from './types';
  22. type Props = AsyncView['props'] &
  23. WithRouteAnalyticsProps &
  24. RouteComponentProps<{monitorId: string}, {}> & {
  25. organization: Organization;
  26. };
  27. type State = AsyncView['state'] & {
  28. monitor: Monitor | null;
  29. };
  30. class MonitorDetails extends AsyncView<Props, State> {
  31. get orgSlug() {
  32. return this.props.organization.slug;
  33. }
  34. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  35. const {params, location} = this.props;
  36. return [
  37. [
  38. 'monitor',
  39. `/organizations/${this.orgSlug}/monitors/${params.monitorId}/`,
  40. {query: location.query},
  41. ],
  42. ];
  43. }
  44. getTitle() {
  45. if (this.state.monitor) {
  46. return `${this.state.monitor.name} - Monitors - ${this.orgSlug}`;
  47. }
  48. return `Monitors - ${this.orgSlug}`;
  49. }
  50. onUpdate = (data: Monitor) =>
  51. this.setState(state => ({monitor: {...state.monitor, ...data}}));
  52. onRequestSuccess(response) {
  53. this.props.setEventNames(
  54. 'monitors.details_page_viewed',
  55. 'Monitors: Details Page Viewed'
  56. );
  57. this.props.setRouteAnalyticsParams({
  58. empty_state: !response.data?.lastCheckIn,
  59. });
  60. }
  61. renderBody() {
  62. const {monitor} = this.state;
  63. if (monitor === null) {
  64. return null;
  65. }
  66. return (
  67. <Layout.Page>
  68. <MonitorHeader monitor={monitor} orgId={this.orgSlug} onUpdate={this.onUpdate} />
  69. <Layout.Body>
  70. <Layout.Main fullWidth>
  71. {!monitor.lastCheckIn ? (
  72. <MonitorOnboarding />
  73. ) : (
  74. <Fragment>
  75. <StyledPageFilterBar condensed>
  76. <DatePageFilter alignDropdown="left" />
  77. </StyledPageFilterBar>
  78. <MonitorStats monitor={monitor} orgId={this.orgSlug} />
  79. <MonitorIssues monitor={monitor} orgId={this.orgSlug} />
  80. <Panel>
  81. <PanelHeader>{t('Recent Check-ins')}</PanelHeader>
  82. <MonitorCheckIns monitor={monitor} orgId={this.orgSlug} />
  83. </Panel>
  84. </Fragment>
  85. )}
  86. </Layout.Main>
  87. </Layout.Body>
  88. </Layout.Page>
  89. );
  90. }
  91. }
  92. const StyledPageFilterBar = styled(PageFilterBar)`
  93. margin-bottom: ${space(2)};
  94. `;
  95. export default withRouteAnalytics(withOrganization(MonitorDetails));