edit.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. onUpdate = (data: Monitor) =>
  29. this.setState(state => ({monitor: {...state.monitor, ...data}}));
  30. onSubmitSuccess = (data: Monitor) =>
  31. browserHistory.push(
  32. normalizeUrl(`/organizations/${this.orgSlug}/crons/${data.slug}/`)
  33. );
  34. getTitle() {
  35. if (this.state.monitor) {
  36. return `${this.state.monitor.name} - Crons - ${this.orgSlug}`;
  37. }
  38. return `Crons - ${this.orgSlug}`;
  39. }
  40. renderBody() {
  41. const {monitor} = this.state;
  42. if (monitor === null) {
  43. return null;
  44. }
  45. return (
  46. <Layout.Page>
  47. <Layout.Header>
  48. <Layout.HeaderContent>
  49. <Breadcrumbs
  50. crumbs={[
  51. {
  52. label: t('Crons'),
  53. to: `/organizations/${this.orgSlug}/crons/`,
  54. },
  55. {
  56. label: t('Editing %s', monitor.name),
  57. },
  58. ]}
  59. />
  60. <Layout.Title>{t('Edit Monitor')}</Layout.Title>
  61. </Layout.HeaderContent>
  62. </Layout.Header>
  63. <Layout.Body>
  64. <Layout.Main fullWidth>
  65. <MonitorForm
  66. monitor={monitor}
  67. apiMethod="PUT"
  68. apiEndpoint={`/organizations/${this.orgSlug}/monitors/${monitor.slug}/`}
  69. onSubmitSuccess={this.onSubmitSuccess}
  70. />
  71. </Layout.Main>
  72. </Layout.Body>
  73. </Layout.Page>
  74. );
  75. }
  76. }
  77. export default withOrganization(EditMonitor);