diff --git a/static/app/views/alerts/rules/row.tsx b/static/app/views/alerts/rules/row.tsx index e7a87960880c21..b073fc7aa79a0a 100644 --- a/static/app/views/alerts/rules/row.tsx +++ b/static/app/views/alerts/rules/row.tsx @@ -39,28 +39,28 @@ type Props = { userTeams: Set; }; -type State = {}; - -class RuleListRow extends React.Component { - /** - * Memoized function to find a project from a list of projects - */ - getProject = memoize((slug: string, projects: Project[]) => - projects.find(project => project.slug === slug) - ); - - activeIncident() { - const {rule} = this.props; - return ( - rule.latestIncident?.status !== undefined && - [IncidentStatus.CRITICAL, IncidentStatus.WARNING].includes( - rule.latestIncident.status - ) +/** + * Memoized function to find a project from a list of projects + */ +const getProject = memoize((slug: string, projects: Project[]) => + projects.find(project => project.slug === slug) +); + +function RuleListRow({ + rule, + projectsLoaded, + projects, + orgId, + onDelete, + userTeams, +}: Props) { + const activeIncident = + rule.latestIncident?.status !== undefined && + [IncidentStatus.CRITICAL, IncidentStatus.WARNING].includes( + rule.latestIncident.status ); - } - renderLastIncidentDate(): React.ReactNode { - const {rule} = this.props; + function renderLastIncidentDate(): React.ReactNode { if (isIssueAlert(rule)) { return null; } @@ -69,7 +69,7 @@ class RuleListRow extends React.Component { return '-'; } - if (this.activeIncident()) { + if (activeIncident) { return (
{t('Triggered ')} @@ -86,14 +86,11 @@ class RuleListRow extends React.Component { ); } - renderAlertRuleStatus(): React.ReactNode { - const {rule} = this.props; - + function renderAlertRuleStatus(): React.ReactNode { if (isIssueAlert(rule)) { return null; } - const activeIncident = this.activeIncident(); const criticalTrigger = rule.triggers.find(({label}) => label === 'critical'); const warningTrigger = rule.triggers.find(({label}) => label === 'warning'); const resolvedTrigger = rule.resolveThreshold; @@ -138,131 +135,107 @@ class RuleListRow extends React.Component { ); } - render() { - const {rule, projectsLoaded, projects, orgId, onDelete, userTeams} = this.props; - const slug = rule.projects[0]; - const editLink = `/organizations/${orgId}/alerts/${ - isIssueAlert(rule) ? 'rules' : 'metric-rules' - }/${slug}/${rule.id}/`; - - const detailsLink = `/organizations/${orgId}/alerts/rules/details/${rule.id}/`; - - const ownerId = rule.owner?.split(':')[1]; - const teamActor = ownerId - ? {type: 'team' as Actor['type'], id: ownerId, name: ''} - : null; - - const canEdit = ownerId ? userTeams.has(ownerId) : true; - const alertLink = isIssueAlert(rule) ? ( - rule.name - ) : ( - {rule.name} - ); + const slug = rule.projects[0]; + const editLink = `/organizations/${orgId}/alerts/${ + isIssueAlert(rule) ? 'rules' : 'metric-rules' + }/${slug}/${rule.id}/`; - const IssueStatusText: Record = { - [IncidentStatus.CRITICAL]: t('Critical'), - [IncidentStatus.WARNING]: t('Warning'), - [IncidentStatus.CLOSED]: t('Resolved'), - [IncidentStatus.OPENED]: t('Resolved'), - }; + const detailsLink = `/organizations/${orgId}/alerts/rules/details/${rule.id}/`; - return ( - - - - - - - - - {alertLink} - {!isIssueAlert(rule) && this.renderLastIncidentDate()} - - - {this.renderAlertRuleStatus()} + const ownerId = rule.owner?.split(':')[1]; + const teamActor = ownerId + ? {type: 'team' as Actor['type'], id: ownerId, name: ''} + : null; - - - - - + const canEdit = ownerId ? userTeams.has(ownerId) : true; + const alertLink = isIssueAlert(rule) ? ( + rule.name + ) : ( + {rule.name} + ); + + const IssueStatusText: Record = { + [IncidentStatus.CRITICAL]: t('Critical'), + [IncidentStatus.WARNING]: t('Warning'), + [IncidentStatus.CLOSED]: t('Resolved'), + [IncidentStatus.OPENED]: t('Resolved'), + }; + return ( + + - {teamActor ? : '-'} + + + + + {alertLink} + {!isIssueAlert(rule) && renderLastIncidentDate()} + + + {renderAlertRuleStatus()} - - + + - - - - {({hasAccess}) => ( - - - } - /> - } - > -
  • - {t('Edit')} -
  • - onDelete(slug, rule)} - > - - {t('Delete')} - - -
    -
    - - {/* Small screen actions */} - + + + + + {teamActor ? : '-'} + + + + + + + + {({hasAccess}) => ( + + + } + /> + } + > +
  • + {t('Edit')} +
  • { confirmText={t('Delete Rule')} onConfirm={() => onDelete(slug, rule)} > -