Alerting: Fix UI crashing when selecting custom grouping in alert panel (#64124)

Fix UI crashing when selecting custom grouping in alert panel
This commit is contained in:
Sonia Aguilar 2023-03-03 12:59:36 +01:00 committed by GitHub
parent c840f6fb9d
commit 9765c98b3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,6 @@ import { SelectableValue } from '@grafana/data';
import { Icon, MultiSelect } from '@grafana/ui';
import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/useUnifiedAlertingSelector';
import { fetchAllPromRulesAction } from 'app/features/alerting/unified/state/actions';
import { getAllRulesSourceNames } from 'app/features/alerting/unified/utils/datasource';
import {
isAsyncRequestMapSlicePending,
isAsyncRequestMapSliceSettled,
@ -31,7 +30,6 @@ export const GroupBy: FC<Props> = (props) => {
}, [dispatch]);
const promRulesByDatasource = useUnifiedAlertingSelector((state) => state.promRules);
const rulesDataSourceNames = useMemo(getAllRulesSourceNames, []);
const allRequestsReady = isAsyncRequestMapSliceSettled(promRulesByDatasource);
const loading = isAsyncRequestMapSlicePending(promRulesByDatasource);
@ -45,7 +43,7 @@ export const GroupBy: FC<Props> = (props) => {
return [];
}
const allLabels = rulesDataSourceNames
const allLabels = Object.keys(promRulesByDatasource)
.flatMap((datasource) => promRulesByDatasource[datasource].result ?? [])
.flatMap((rules) => rules.groups)
.flatMap((group) => group.rules.filter((rule): rule is AlertingRule => rule.type === PromRuleType.Alerting))
@ -54,7 +52,7 @@ export const GroupBy: FC<Props> = (props) => {
.flatMap((labels) => labels.filter(isPrivateLabel));
return uniq(allLabels);
}, [allRequestsReady, promRulesByDatasource, rulesDataSourceNames]);
}, [allRequestsReady, promRulesByDatasource]);
return (
<MultiSelect<string>