Skip to content

Commit

Permalink
fix(alerts): Remove null projects from alerts list (#45202)
Browse files Browse the repository at this point in the history
  • Loading branch information
scttcper authored Feb 28, 2023
1 parent 8afc4b3 commit ba697cf
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions static/app/views/alerts/list/rules/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component} from 'react';
import {RouteComponentProps} from 'react-router';
import styled from '@emotion/styled';
import uniq from 'lodash/uniq';

import {addErrorMessage, addMessage} from 'sentry/actionCreators/indicator';
import AsyncComponent from 'sentry/components/asyncComponent';
Expand All @@ -13,6 +14,7 @@ import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
import {IconArrow} from 'sentry/icons';
import {t} from 'sentry/locale';
import {Organization, PageFilters, Project} from 'sentry/types';
import {defined} from 'sentry/utils';
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
import Projects from 'sentry/utils/projects';
import Teams from 'sentry/utils/teams';
Expand All @@ -31,7 +33,7 @@ type Props = RouteComponentProps<{}, {}> & {
};

type State = {
ruleList?: CombinedMetricIssueAlerts[] | null;
ruleList?: Array<CombinedMetricIssueAlerts | null> | null;
teamFilterSearch?: string;
};

Expand All @@ -58,12 +60,6 @@ class AlertRulesList extends AsyncComponent<Props, State & AsyncComponent['state
];
}

get projectsFromResults() {
const ruleList = this.state.ruleList ?? [];

return [...new Set(ruleList.map(({projects}) => projects).flat())];
}

handleChangeFilter = (activeFilters: string[]) => {
const {router, location} = this.props;
const {cursor: _cursor, page: _page, ...currentQuery} = location.query;
Expand Down Expand Up @@ -133,9 +129,11 @@ class AlertRulesList extends AsyncComponent<Props, State & AsyncComponent['state

renderList() {
const {location, organization, router} = this.props;
const {loading, ruleList = [], ruleListPageLinks} = this.state;
const {loading, ruleListPageLinks} = this.state;
const {query} = location;
const hasEditAccess = organization.access.includes('alerts:write');
const ruleList = (this.state.ruleList ?? []).filter(defined);
const projectsFromResults = uniq(ruleList.flatMap(({projects}) => projects));

const sort: {
asc: boolean;
Expand Down Expand Up @@ -209,12 +207,12 @@ class AlertRulesList extends AsyncComponent<Props, State & AsyncComponent['state
t('Actions'),
]}
isLoading={loading || !loadedTeams}
isEmpty={ruleList?.length === 0}
isEmpty={ruleList.length === 0}
emptyMessage={t('No alert rules found for the current query.')}
>
<Projects orgId={organization.slug} slugs={this.projectsFromResults}>
<Projects orgId={organization.slug} slugs={projectsFromResults}>
{({initiallyLoaded, projects}) =>
ruleList?.map(rule => (
ruleList.map(rule => (
<RuleListRow
// Metric and issue alerts can have the same id
key={`${
Expand Down

0 comments on commit ba697cf

Please sign in to comment.