edit.tsx 2.4 KB

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