diff --git a/public/app/features/alerting/unified/api/ruler.ts b/public/app/features/alerting/unified/api/ruler.ts index 536b7ce754f..c3a515df9dd 100644 --- a/public/app/features/alerting/unified/api/ruler.ts +++ b/public/app/features/alerting/unified/api/ruler.ts @@ -70,7 +70,7 @@ async function rulerGetRequest(url: string, empty: T): Promise { .toPromise(); return response.data; } catch (e) { - if (e?.status === 404) { + if (e?.status === 404 || e?.data?.message?.includes('group does not exist')) { return empty; } else if (e?.status === 500 && e?.data?.message?.includes('mapping values are not allowed in this context')) { throw { diff --git a/public/app/features/alerting/unified/components/RuleGroupPicker.tsx b/public/app/features/alerting/unified/components/RuleGroupPicker.tsx deleted file mode 100644 index 6b553a3e976..00000000000 --- a/public/app/features/alerting/unified/components/RuleGroupPicker.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import { Cascader, CascaderOption } from '@grafana/ui'; -import React, { FC, useEffect, useMemo } from 'react'; -import { useDispatch } from 'react-redux'; -import { useUnifiedAlertingSelector } from '../hooks/useUnifiedAlertingSelector'; -import { fetchRulerRulesAction } from '../state/actions'; - -interface RuleGroupValue { - namespace: string; - group: string; -} - -interface Props { - value?: RuleGroupValue; - onChange: (value: RuleGroupValue) => void; - dataSourceName: string; -} - -const stringifyValue = ({ namespace, group }: RuleGroupValue) => namespace + '|||' + group; -const parseValue = (value: string): RuleGroupValue => { - const [namespace, group] = value.split('|||'); - return { namespace, group }; -}; - -export const RuleGroupPicker: FC = ({ value, onChange, dataSourceName }) => { - const rulerRequests = useUnifiedAlertingSelector((state) => state.rulerRules); - const dispatch = useDispatch(); - useEffect(() => { - dispatch(fetchRulerRulesAction(dataSourceName)); - }, [dataSourceName, dispatch]); - - const rulesConfig = rulerRequests[dataSourceName]?.result; - - const options = useMemo((): CascaderOption[] => { - if (rulesConfig) { - return Object.entries(rulesConfig).map(([namespace, group]) => { - return { - label: namespace, - value: namespace, - items: group.map(({ name }) => { - return { label: name, value: stringifyValue({ namespace, group: name }) }; - }), - }; - }); - } - return []; - }, [rulesConfig]); - - // @TODO replace cascader with separate dropdowns - return ( - { - console.log('selected', value); - onChange(parseValue(value)); - }} - initialValue={value ? stringifyValue(value) : undefined} - displayAllSelectedLevels={true} - separator=" > " - key={JSON.stringify(options)} - options={options} - changeOnSelect={false} - /> - ); -}; diff --git a/public/app/features/alerting/unified/components/rule-editor/AlertTypeStep.tsx b/public/app/features/alerting/unified/components/rule-editor/AlertTypeStep.tsx index 85facfa6a70..84db059ed56 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AlertTypeStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AlertTypeStep.tsx @@ -7,9 +7,9 @@ import { RuleEditorSection } from './RuleEditorSection'; import { useFormContext } from 'react-hook-form'; import { RuleFormType, RuleFormValues } from '../../types/rule-form'; import { DataSourcePicker, DataSourcePickerProps } from '@grafana/runtime'; -import { RuleGroupPicker } from '../RuleGroupPicker'; import { useRulesSourcesWithRuler } from '../../hooks/useRuleSourcesWithRuler'; import { RuleFolderPicker } from './RuleFolderPicker'; +import { GroupAndNamespaceFields } from './GroupAndNamespaceFields'; const alertTypeOptions: SelectableValue[] = [ { @@ -123,27 +123,8 @@ export const AlertTypeStep: FC = ({ editingExistingRule }) => { )} - {ruleFormType === RuleFormType.system && ( - - {dataSourceName ? ( - - ) : ( - onChange((e.target as HTMLInputElement).value)} - /> - ); - } else { - return ( - onChange((e.target as HTMLInputElement).value)} + /> + ); + } else { + return ( +