Skip to content

Commit ba697cf

Browse files
authored
fix(alerts): Remove null projects from alerts list (#45202)
1 parent 8afc4b3 commit ba697cf

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

static/app/views/alerts/list/rules/index.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Component} from 'react';
22
import {RouteComponentProps} from 'react-router';
33
import styled from '@emotion/styled';
4+
import uniq from 'lodash/uniq';
45

56
import {addErrorMessage, addMessage} from 'sentry/actionCreators/indicator';
67
import AsyncComponent from 'sentry/components/asyncComponent';
@@ -13,6 +14,7 @@ import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
1314
import {IconArrow} from 'sentry/icons';
1415
import {t} from 'sentry/locale';
1516
import {Organization, PageFilters, Project} from 'sentry/types';
17+
import {defined} from 'sentry/utils';
1618
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
1719
import Projects from 'sentry/utils/projects';
1820
import Teams from 'sentry/utils/teams';
@@ -31,7 +33,7 @@ type Props = RouteComponentProps<{}, {}> & {
3133
};
3234

3335
type 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

Comments
 (0)