The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/alerting/unified/integration/AlertRulesDrawerContent.tsx

39 lines
1.3 KiB

import React from 'react';
import { useAsync } from 'react-use';
import { LoadingPlaceholder } from '@grafana/ui';
import { useDispatch } from 'app/types';
import { RulesTable } from '../components/rules/RulesTable';
import { useCombinedRuleNamespaces } from '../hooks/useCombinedRuleNamespaces';
import { fetchPromAndRulerRulesAction } from '../state/actions';
import { Annotation } from '../utils/constants';
import { GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';
interface Props {
dashboardUid: string;
}
export default function AlertRulesDrawerContent({ dashboardUid }: Props) {
const dispatch = useDispatch();
const { loading } = useAsync(async () => {
await dispatch(fetchPromAndRulerRulesAction({ rulesSourceName: GRAFANA_RULES_SOURCE_NAME }));
}, [dispatch]);
const grafanaNamespaces = useCombinedRuleNamespaces(GRAFANA_RULES_SOURCE_NAME);
const rules = grafanaNamespaces
.flatMap((ns) => ns.groups)
.flatMap((g) => g.rules)
.filter((rule) => rule.annotations[Annotation.dashboardUID] === dashboardUid);
return (
<>
{loading ? (
<LoadingPlaceholder text="Loading alert rules" />
) : (
<RulesTable rules={rules} showNextEvaluationColumn={false} showGroupColumn={false} />
)}
</>
);
}