edit.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import Breadcrumbs from 'sentry/components/breadcrumbs';
  3. import * as Layout from 'sentry/components/layouts/thirds';
  4. import {t} from 'sentry/locale';
  5. import {Organization} from 'sentry/types';
  6. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  7. import withOrganization from 'sentry/utils/withOrganization';
  8. import AsyncView from 'sentry/views/asyncView';
  9. import MonitorForm from './components/monitorForm';
  10. import {Monitor} from './types';
  11. type Props = AsyncView['props'] &
  12. RouteComponentProps<{monitorSlug: string}, {}> & {
  13. organization: Organization;
  14. };
  15. type State = AsyncView['state'] & {
  16. monitor: Monitor | null;
  17. };
  18. class EditMonitor extends AsyncView<Props, State> {
  19. get orgSlug() {
  20. return this.props.organization.slug;
  21. }
  22. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  23. const {params} = this.props;
  24. return [
  25. ['monitor', `/organizations/${this.orgSlug}/monitors/${params.monitorSlug}/`],
  26. ];
  27. }
  28. onSubmitSuccess = (data: Monitor) =>
  29. browserHistory.push(
  30. normalizeUrl(`/organizations/${this.orgSlug}/crons/${data.slug}/`)
  31. );
  32. getTitle() {
  33. if (this.state.monitor) {
  34. return `${this.state.monitor.name} - Crons - ${this.orgSlug}`;
  35. }
  36. return `Crons - ${this.orgSlug}`;
  37. }
  38. renderBody() {
  39. const {monitor} = this.state;
  40. if (monitor === null) {
  41. return null;
  42. }
  43. return (
  44. <Layout.Page>
  45. <Layout.Header>
  46. <Layout.HeaderContent>
  47. <Breadcrumbs
  48. crumbs={[
  49. {
  50. label: t('Crons'),
  51. to: `/organizations/${this.orgSlug}/crons/`,
  52. },
  53. {
  54. label: t('Editing %s', monitor.name),
  55. },
  56. ]}
  57. />
  58. <Layout.Title>{t('Edit Monitor')}</Layout.Title>
  59. </Layout.HeaderContent>
  60. </Layout.Header>
  61. <Layout.Body>
  62. <Layout.Main fullWidth>
  63. <MonitorForm
  64. monitor={monitor}
  65. apiMethod="PUT"
  66. apiEndpoint={`/organizations/${this.orgSlug}/monitors/${monitor.slug}/`}
  67. onSubmitSuccess={this.onSubmitSuccess}
  68. />
  69. </Layout.Main>
  70. </Layout.Body>
  71. </Layout.Page>
  72. );
  73. }
  74. }
  75. export default withOrganization(EditMonitor);