edit.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {Component, Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import * as Layout from 'app/components/layouts/thirds';
  5. import SentryDocumentTitle from 'app/components/sentryDocumentTitle';
  6. import {t} from 'app/locale';
  7. import space from 'app/styles/space';
  8. import {Organization, Project} from 'app/types';
  9. import {trackAnalyticsEvent} from 'app/utils/analytics';
  10. import BuilderBreadCrumbs from 'app/views/alerts/builder/builderBreadCrumbs';
  11. import IncidentRulesDetails from 'app/views/alerts/incidentRules/details';
  12. import IssueEditor from 'app/views/alerts/issueRuleEditor';
  13. type RouteParams = {
  14. orgId: string;
  15. projectId: string;
  16. ruleId: string;
  17. };
  18. type Props = RouteComponentProps<RouteParams, {}> & {
  19. organization: Organization;
  20. project: Project;
  21. hasMetricAlerts: boolean;
  22. };
  23. type State = {
  24. ruleName: string;
  25. };
  26. class ProjectAlertsEditor extends Component<Props, State> {
  27. state: State = {
  28. ruleName: '',
  29. };
  30. componentDidMount() {
  31. const {organization, project} = this.props;
  32. trackAnalyticsEvent({
  33. eventKey: 'edit_alert_rule.viewed',
  34. eventName: 'Edit Alert Rule: Viewed',
  35. organization_id: organization.id,
  36. project_id: project.id,
  37. alert_type: this.getAlertType(),
  38. });
  39. }
  40. handleChangeTitle = (ruleName: string) => {
  41. this.setState({ruleName});
  42. };
  43. getTitle() {
  44. const {ruleName} = this.state;
  45. return `${ruleName}`;
  46. }
  47. getAlertType(): 'metric' | 'issue' {
  48. return location.pathname.includes('/alerts/metric-rules/') ? 'metric' : 'issue';
  49. }
  50. render() {
  51. const {hasMetricAlerts, location, organization, project, routes} = this.props;
  52. const alertType = this.getAlertType();
  53. return (
  54. <Fragment>
  55. <SentryDocumentTitle
  56. title={this.getTitle()}
  57. orgSlug={organization.slug}
  58. projectSlug={project.slug}
  59. />
  60. <Layout.Header>
  61. <Layout.HeaderContent>
  62. <BuilderBreadCrumbs
  63. orgSlug={organization.slug}
  64. title={t('Edit Alert Rule')}
  65. projectSlug={project.slug}
  66. routes={routes}
  67. location={location}
  68. />
  69. <Layout.Title>{this.getTitle()}</Layout.Title>
  70. </Layout.HeaderContent>
  71. </Layout.Header>
  72. <EditConditionsBody>
  73. <Layout.Main fullWidth>
  74. {(!hasMetricAlerts || alertType === 'issue') && (
  75. <IssueEditor
  76. {...this.props}
  77. project={project}
  78. onChangeTitle={this.handleChangeTitle}
  79. />
  80. )}
  81. {hasMetricAlerts && alertType === 'metric' && (
  82. <IncidentRulesDetails
  83. {...this.props}
  84. project={project}
  85. onChangeTitle={this.handleChangeTitle}
  86. />
  87. )}
  88. </Layout.Main>
  89. </EditConditionsBody>
  90. </Fragment>
  91. );
  92. }
  93. }
  94. const EditConditionsBody = styled(Layout.Body)`
  95. margin-bottom: -${space(3)};
  96. *:not(img) {
  97. max-width: 1000px;
  98. }
  99. `;
  100. export default ProjectAlertsEditor;