mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Add filtering by dashboard UID annotation * Update the inline doc for search * Add AlertRulesDrawer to the dashboards toolbar * Use DashboardPicker as a filter on the alert rules page * Fix accessibility errors * Update drawer subtitle * Display Alerting toolbar button only if there are linked alert rules * Change toolbar rendering method, prevent displaying when no linked rules * Improve text * Use React.lazy to load the Alert rule toolbar button and drawer when needed
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
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} />
|
|
)}
|
|
</>
|
|
);
|
|
}
|