edit.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import AsyncView from 'sentry/views/asyncView';
  4. import MonitorForm from './monitorForm';
  5. import {Monitor} from './types';
  6. type Props = AsyncView['props'] &
  7. RouteComponentProps<{monitorId: string; orgId: string}, {}>;
  8. type State = AsyncView['state'] & {
  9. monitor: Monitor | null;
  10. };
  11. export default class EditMonitor extends AsyncView<Props, State> {
  12. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  13. const {params} = this.props;
  14. return [['monitor', `/monitors/${params.monitorId}/`]];
  15. }
  16. onUpdate = (data: Monitor) =>
  17. this.setState(state => ({monitor: {...state.monitor, ...data}}));
  18. onSubmitSuccess = (data: Monitor) =>
  19. browserHistory.push(`/organizations/${this.props.params.orgId}/monitors/${data.id}/`);
  20. getTitle() {
  21. if (this.state.monitor) {
  22. return `${this.state.monitor.name} - Monitors - ${this.props.params.orgId}`;
  23. }
  24. return `Monitors - ${this.props.params.orgId}`;
  25. }
  26. renderBody() {
  27. const {monitor} = this.state;
  28. if (monitor === null) {
  29. return null;
  30. }
  31. return (
  32. <Fragment>
  33. <h1>Edit Monitor</h1>
  34. <MonitorForm
  35. monitor={monitor}
  36. apiMethod="PUT"
  37. apiEndpoint={`/monitors/${monitor.id}/`}
  38. onSubmitSuccess={this.onSubmitSuccess}
  39. />
  40. </Fragment>
  41. );
  42. }
  43. }