Files
grafana/public/app/features/alerting/unified/integration/AlertRulesToolbarButton.tsx
Konrad Lalik 26e71953a4 Alerting: Improve integration with dashboards (#80201)
* 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
2024-01-29 16:09:10 +01:00

40 lines
1.1 KiB
TypeScript

import React from 'react';
import { useToggle } from 'react-use';
import { ToolbarButton } from '@grafana/ui';
import { t } from '../../../../core/internationalization';
import { alertRuleApi } from '../api/alertRuleApi';
import { GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';
import { AlertRulesDrawer } from './AlertRulesDrawer';
interface AlertRulesToolbarButtonProps {
dashboardUid: string;
}
export default function AlertRulesToolbarButton({ dashboardUid }: AlertRulesToolbarButtonProps) {
const [showDrawer, toggleShowDrawer] = useToggle(false);
const { data: namespaces = [] } = alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({
ruleSourceName: GRAFANA_RULES_SOURCE_NAME,
dashboardUid: dashboardUid,
});
if (namespaces.length === 0) {
return null;
}
return (
<>
<ToolbarButton
tooltip={t('dashboard.toolbar.alert-rules', 'Alert rules')}
icon="bell"
onClick={toggleShowDrawer}
key="button-alerting"
/>
{showDrawer && <AlertRulesDrawer dashboardUid={dashboardUid} onClose={toggleShowDrawer} />}
</>
);
}