Alerting: Disable export all rules button when no GMA rules (#80126)
Disable export button when no GMA rules
This commit is contained in:
@@ -10,9 +10,11 @@ import { logInfo, LogMessages } from './Analytics';
|
||||
import { GrafanaRulesExporter } from './components/export/GrafanaRulesExporter';
|
||||
import { AlertingAction, useAlertingAbility } from './hooks/useAbilities';
|
||||
|
||||
interface Props {}
|
||||
interface Props {
|
||||
enableExport?: boolean;
|
||||
}
|
||||
|
||||
export function MoreActionsRuleButtons({}: Props) {
|
||||
export function MoreActionsRuleButtons({ enableExport }: Props) {
|
||||
const [createRuleSupported, createRuleAllowed] = useAlertingAbility(AlertingAction.CreateAlertRule);
|
||||
const [createCloudRuleSupported, createCloudRuleAllowed] = useAlertingAbility(AlertingAction.CreateExternalAlertRule);
|
||||
const [exportRulesSupported, exportRulesAllowed] = useAlertingAbility(AlertingAction.ExportGrafanaManagedRules);
|
||||
@@ -40,7 +42,13 @@ export function MoreActionsRuleButtons({}: Props) {
|
||||
|
||||
if (canExportRules) {
|
||||
menuItems.push(
|
||||
<MenuItem label="Export all Grafana-managed rules" key="export-all-rules" onClick={toggleShowExportDrawer} />
|
||||
<MenuItem
|
||||
label="Export all Grafana-managed rules"
|
||||
key="export-all-rules"
|
||||
onClick={toggleShowExportDrawer}
|
||||
disabled={!enableExport}
|
||||
description={enableExport ? '' : 'No Grafana-managed rules found'}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import { useFilteredRules, useRulesFilter } from './hooks/useFilteredRules';
|
||||
import { useUnifiedAlertingSelector } from './hooks/useUnifiedAlertingSelector';
|
||||
import { fetchAllPromAndRulerRulesAction } from './state/actions';
|
||||
import { RULE_LIST_POLL_INTERVAL_MS } from './utils/constants';
|
||||
import { getAllRulesSourceNames } from './utils/datasource';
|
||||
import { getAllRulesSourceNames, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource';
|
||||
|
||||
const VIEWS = {
|
||||
groups: RuleListGroupView,
|
||||
@@ -77,6 +77,9 @@ const RuleList = withErrorBoundary(
|
||||
return noRules && state.dispatched;
|
||||
});
|
||||
|
||||
const grafanaRules = useUnifiedAlertingSelector((state) => state.rulerRules[GRAFANA_RULES_SOURCE_NAME]?.result);
|
||||
const hasGrafanaRules = Object.keys(grafanaRules ?? {}).length > 0;
|
||||
|
||||
const limitAlerts = hasActiveFilters ? undefined : LIMIT_ALERTS;
|
||||
// Trigger data refresh only when the RULE_LIST_POLL_INTERVAL_MS elapsed since the previous load FINISHED
|
||||
const [_, fetchRules] = useAsyncFn(async () => {
|
||||
@@ -126,7 +129,7 @@ const RuleList = withErrorBoundary(
|
||||
<RuleStats namespaces={filteredNamespaces} />
|
||||
</div>
|
||||
<Stack direction="row" gap={0.5}>
|
||||
<MoreActionsRuleButtons />
|
||||
<MoreActionsRuleButtons enableExport={hasGrafanaRules} />
|
||||
</Stack>
|
||||
</div>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user