edit.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import * as Layout from 'sentry/components/layouts/thirds';
  3. import {t} from 'sentry/locale';
  4. import {Organization} from 'sentry/types';
  5. import withOrganization from 'sentry/utils/withOrganization';
  6. import AsyncView from 'sentry/views/asyncView';
  7. import MonitorForm from './monitorForm';
  8. import {Monitor} from './types';
  9. type Props = AsyncView['props'] &
  10. RouteComponentProps<{monitorId: string; orgId: string}, {}> & {
  11. organization: Organization;
  12. };
  13. type State = AsyncView['state'] & {
  14. monitor: Monitor | null;
  15. };
  16. class EditMonitor extends AsyncView<Props, State> {
  17. get orgSlug() {
  18. return this.props.organization.slug;
  19. }
  20. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  21. const {params} = this.props;
  22. return [['monitor', `/monitors/${params.monitorId}/`]];
  23. }
  24. onUpdate = (data: Monitor) =>
  25. this.setState(state => ({monitor: {...state.monitor, ...data}}));
  26. onSubmitSuccess = (data: Monitor) =>
  27. browserHistory.push(`/organizations/${this.orgSlug}/monitors/${data.id}/`);
  28. getTitle() {
  29. if (this.state.monitor) {
  30. return `${this.state.monitor.name} - Monitors - ${this.orgSlug}`;
  31. }
  32. return `Monitors - ${this.orgSlug}`;
  33. }
  34. renderBody() {
  35. const {monitor} = this.state;
  36. if (monitor === null) {
  37. return null;
  38. }
  39. return (
  40. <Layout.Body>
  41. <Layout.Main fullWidth>
  42. <h1>{t('Edit Monitor')}</h1>
  43. <MonitorForm
  44. monitor={monitor}
  45. apiMethod="PUT"
  46. apiEndpoint={`/monitors/${monitor.id}/`}
  47. onSubmitSuccess={this.onSubmitSuccess}
  48. />
  49. </Layout.Main>
  50. </Layout.Body>
  51. );
  52. }
  53. }
  54. export default withOrganization(EditMonitor);