Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(alerts): Remove null projects from alerts list #45202

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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