11import { Component } from 'react' ;
22import { RouteComponentProps } from 'react-router' ;
33import styled from '@emotion/styled' ;
4+ import uniq from 'lodash/uniq' ;
45
56import { addErrorMessage , addMessage } from 'sentry/actionCreators/indicator' ;
67import AsyncComponent from 'sentry/components/asyncComponent' ;
@@ -13,6 +14,7 @@ import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
1314import { IconArrow } from 'sentry/icons' ;
1415import { t } from 'sentry/locale' ;
1516import { Organization , PageFilters , Project } from 'sentry/types' ;
17+ import { defined } from 'sentry/utils' ;
1618import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent' ;
1719import Projects from 'sentry/utils/projects' ;
1820import Teams from 'sentry/utils/teams' ;
@@ -31,7 +33,7 @@ type Props = RouteComponentProps<{}, {}> & {
3133} ;
3234
3335type State = {
34- ruleList ?: CombinedMetricIssueAlerts [ ] | null ;
36+ ruleList ?: Array < CombinedMetricIssueAlerts | null > | null ;
3537 teamFilterSearch ?: string ;
3638} ;
3739
@@ -58,12 +60,6 @@ class AlertRulesList extends AsyncComponent<Props, State & AsyncComponent['state
5860 ] ;
5961 }
6062
61- get projectsFromResults ( ) {
62- const ruleList = this . state . ruleList ?? [ ] ;
63-
64- return [ ...new Set ( ruleList . map ( ( { projects} ) => projects ) . flat ( ) ) ] ;
65- }
66-
6763 handleChangeFilter = ( activeFilters : string [ ] ) => {
6864 const { router, location} = this . props ;
6965 const { cursor : _cursor , page : _page , ...currentQuery } = location . query ;
@@ -133,9 +129,11 @@ class AlertRulesList extends AsyncComponent<Props, State & AsyncComponent['state
133129
134130 renderList ( ) {
135131 const { location, organization, router} = this . props ;
136- const { loading, ruleList = [ ] , ruleListPageLinks} = this . state ;
132+ const { loading, ruleListPageLinks} = this . state ;
137133 const { query} = location ;
138134 const hasEditAccess = organization . access . includes ( 'alerts:write' ) ;
135+ const ruleList = ( this . state . ruleList ?? [ ] ) . filter ( defined ) ;
136+ const projectsFromResults = uniq ( ruleList . flatMap ( ( { projects} ) => projects ) ) ;
139137
140138 const sort : {
141139 asc : boolean ;
@@ -209,12 +207,12 @@ class AlertRulesList extends AsyncComponent<Props, State & AsyncComponent['state
209207 t ( 'Actions' ) ,
210208 ] }
211209 isLoading = { loading || ! loadedTeams }
212- isEmpty = { ruleList ? .length === 0 }
210+ isEmpty = { ruleList . length === 0 }
213211 emptyMessage = { t ( 'No alert rules found for the current query.' ) }
214212 >
215- < Projects orgId = { organization . slug } slugs = { this . projectsFromResults } >
213+ < Projects orgId = { organization . slug } slugs = { projectsFromResults } >
216214 { ( { initiallyLoaded, projects} ) =>
217- ruleList ? .map ( rule => (
215+ ruleList . map ( rule => (
218216 < RuleListRow
219217 // Metric and issue alerts can have the same id
220218 key = { `${
0 commit comments