Skip to content

Commit

Permalink
ref(ui): Convert metric rule create to functional component (#29274)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidenwang committed Oct 13, 2021
1 parent f26d50a commit 9c49b7e
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions static/app/views/alerts/incidentRules/create.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {Component} from 'react';
import {RouteComponentProps} from 'react-router';

import {Organization, Project, Team} from 'app/types';
Expand Down Expand Up @@ -33,40 +32,38 @@ type Props = {
/**
* Show metric rules form with an empty rule. Redirects to alerts list after creation.
*/
class IncidentRulesCreate extends Component<Props> {
handleSubmitSuccess = () => {
const {router} = this.props;
const {orgId} = this.props.params;
function IncidentRulesCreate(props: Props) {
function handleSubmitSuccess() {
const {router} = props;
const {orgId} = props.params;

metric.endTransaction({name: 'saveAlertRule'});
router.push(`/organizations/${orgId}/alerts/rules/`);
};
}

render() {
const {project, eventView, wizardTemplate, sessionId, teams, ...props} = this.props;
const defaultRule = eventView
? createRuleFromEventView(eventView)
: wizardTemplate
? createRuleFromWizardTemplate(wizardTemplate)
: createDefaultRule();
const {project, eventView, wizardTemplate, sessionId, teams, ...otherProps} = props;
const defaultRule = eventView
? createRuleFromEventView(eventView)
: wizardTemplate
? createRuleFromWizardTemplate(wizardTemplate)
: createDefaultRule();

const userTeamIds = teams.filter(({isMember}) => isMember).map(({id}) => id);
const userTeamIds = teams.filter(({isMember}) => isMember).map(({id}) => id);

const projectTeamIds = new Set(project.teams.map(({id}) => id));
const defaultOwnerId = userTeamIds.find(id => projectTeamIds.has(id)) ?? null;
defaultRule.owner = defaultOwnerId && `team:${defaultOwnerId}`;
const projectTeamIds = new Set(project.teams.map(({id}) => id));
const defaultOwnerId = userTeamIds.find(id => projectTeamIds.has(id)) ?? null;
defaultRule.owner = defaultOwnerId && `team:${defaultOwnerId}`;

return (
<RuleForm
onSubmitSuccess={this.handleSubmitSuccess}
rule={{...defaultRule, projects: [project.slug]}}
sessionId={sessionId}
project={project}
userTeamIds={userTeamIds}
{...props}
/>
);
}
return (
<RuleForm
onSubmitSuccess={handleSubmitSuccess}
rule={{...defaultRule, projects: [project.slug]}}
sessionId={sessionId}
project={project}
userTeamIds={userTeamIds}
{...otherProps}
/>
);
}

export default withTeams(IncidentRulesCreate);

0 comments on commit 9c49b7e

Please sign in to comment.