diff --git a/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx index a55e702bfef..03cfdf33161 100644 --- a/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/NotificationsStep.tsx @@ -5,7 +5,9 @@ import { useFormContext } from 'react-hook-form'; import { GrafanaTheme2 } from '@grafana/data'; import { config } from '@grafana/runtime'; import { Icon, RadioButtonGroup, Stack, Text, useStyles2 } from '@grafana/ui'; +import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types'; +import { alertmanagerApi } from '../../api/alertmanagerApi'; import { RuleFormType, RuleFormValues } from '../../types/rule-form'; import { GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource'; @@ -25,6 +27,15 @@ enum RoutingOptions { ContactPoint = 'contact point', } +function useHasInternalAlertmanagerEnabled() { + const { useGetGrafanaAlertingConfigurationStatusQuery } = alertmanagerApi; + const { currentData: amChoiceStatus } = useGetGrafanaAlertingConfigurationStatusQuery(undefined); + return ( + amChoiceStatus?.alertmanagersChoice === AlertmanagerChoice.Internal || + amChoiceStatus?.alertmanagersChoice === AlertmanagerChoice.All + ); +} + export const NotificationsStep = ({ alertUid }: NotificationsStepProps) => { const { watch, getValues, setValue } = useFormContext(); const styles = useStyles2(getStyles); @@ -35,7 +46,10 @@ export const NotificationsStep = ({ alertUid }: NotificationsStepProps) => { const dataSourceName = watch('dataSourceName') ?? GRAFANA_RULES_SOURCE_NAME; const simplifiedRoutingToggleEnabled = config.featureToggles.alertingSimplifiedRouting ?? false; const shouldRenderpreview = type === RuleFormType.grafana; - const shouldAllowSimplifiedRouting = type === RuleFormType.grafana && simplifiedRoutingToggleEnabled; + const hasInternalAlertmanagerEnabled = useHasInternalAlertmanagerEnabled(); + + const shouldAllowSimplifiedRouting = + type === RuleFormType.grafana && simplifiedRoutingToggleEnabled && hasInternalAlertmanagerEnabled; function onCloseLabelsEditor( labelsToUpdate?: Array<{ diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx index eed0e9abd9f..5b635094ba5 100644 --- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/simplifiedRouting/SimplifiedRuleEditor.test.tsx @@ -14,6 +14,7 @@ import * as ruler from 'app/features/alerting/unified/api/ruler'; import * as useContactPoints from 'app/features/alerting/unified/components/contact-points/useContactPoints'; import { setupMswServer } from 'app/features/alerting/unified/mockApi'; import { grantUserPermissions, mockDataSource } from 'app/features/alerting/unified/mocks'; +import { setAlertmanagerChoices } from 'app/features/alerting/unified/mocks/server/configure'; import { AlertmanagerProvider } from 'app/features/alerting/unified/state/AlertmanagerContext'; import * as utils_config from 'app/features/alerting/unified/utils/config'; import { @@ -25,6 +26,7 @@ import { import { getDefaultQueries } from 'app/features/alerting/unified/utils/rule-form'; import { searchFolders } from 'app/features/manage-dashboards/state/actions'; import { DashboardSearchHit, DashboardSearchItemType } from 'app/features/search/types'; +import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types'; import { AccessControlAction } from 'app/types'; import { GrafanaAlertStateDecision } from 'app/types/unified-alerting-dto'; @@ -160,6 +162,14 @@ describe('Can create a new grafana managed alert unsing simplified routing', () expect(mocks.api.setRulerRuleGroup).not.toHaveBeenCalled(); }); }); + it('simplified routing is not available when Grafana AM is not enabled', async () => { + config.featureToggles.alertingSimplifiedRouting = true; + setAlertmanagerChoices(AlertmanagerChoice.External, 1); + renderSimplifiedRuleEditor(); + await waitForElementToBeRemoved(screen.getAllByTestId('Spinner')); + + expect(ui.inputs.simplifiedRouting.contactPointRouting.query()).not.toBeInTheDocument(); + }); it('can create new grafana managed alert when using simplified routing and selecting a contact point', async () => { const contactPointsAvailable: ContactPointWithMetadata[] = [