diff --git a/public/app/features/alerting/unified/utils/rules.ts b/public/app/features/alerting/unified/utils/rules.ts index 88bc70a2cb8..13aa9982983 100644 --- a/public/app/features/alerting/unified/utils/rules.ts +++ b/public/app/features/alerting/unified/utils/rules.ts @@ -293,7 +293,13 @@ export const flattenCombinedRules = (rules: CombinedRuleNamespace[]) => { groups.forEach(({ name: groupName, rules }) => { rules.forEach((rule) => { if (rule.promRule && isAlertingRule(rule.promRule)) { - acc.push({ dataSourceName: getRulesSourceName(rulesSource), namespaceName, groupName, ...rule }); + acc.push({ + dataSourceName: getRulesSourceName(rulesSource), + namespaceName, + groupName, + ...rule, + namespace: { ...rule.namespace, uid: rule.promRule.folderUid }, + }); } }); }); diff --git a/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx b/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx index db994772bd7..be6401e3ad1 100644 --- a/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx +++ b/public/app/plugins/panel/alertlist/UnifiedAlertList.tsx @@ -309,9 +309,9 @@ function filterRules(props: PanelProps, rules: Combined ); }); - if (options.folder) { + if (options.folder && options.folder.uid) { filteredRules = filteredRules.filter((rule) => { - return rule.namespaceName === options.folder.title; + return rule.namespace.uid === options.folder.uid; }); } if (options.datasource) { diff --git a/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx b/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx index d2b1a7622ba..1a8369dbbef 100644 --- a/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx +++ b/public/app/plugins/panel/alertlist/UnifiedalertList.test.tsx @@ -108,7 +108,7 @@ const defaultOptions: UnifiedAlertListOptions = { groupBy: [''], alertName: 'test', showInstances: false, - folder: { id: 1, title: 'test folder' }, + folder: { uid: 'abc', title: 'test folder' }, stateFilter: { firing: true, pending: false, noData: false, normal: true, error: false, recovering: false }, alertInstanceLabelFilter: '', datasource: 'grafana', diff --git a/public/app/plugins/panel/alertlist/module.tsx b/public/app/plugins/panel/alertlist/module.tsx index e11dd65ff5d..2d0e2ef64c5 100644 --- a/public/app/plugins/panel/alertlist/module.tsx +++ b/public/app/plugins/panel/alertlist/module.tsx @@ -1,8 +1,7 @@ import { DataSourceInstanceSettings, PanelPlugin } from '@grafana/data'; import { Button, Stack } from '@grafana/ui'; -import { OldFolderPicker } from 'app/core/components/Select/OldFolderPicker'; +import { NestedFolderPicker } from 'app/core/components/NestedFolderPicker/NestedFolderPicker'; import { DataSourcePicker } from 'app/features/datasources/components/picker/DataSourcePicker'; -import { PermissionLevelString } from 'app/types'; import { GRAFANA_DATASOURCE_NAME, @@ -118,7 +117,14 @@ const unifiedAlertList = new PanelPlugin(UnifiedAlertLi type={SUPPORTED_RULE_SOURCE_TYPES} noDefault current={props.value} - onChange={(ds: DataSourceInstanceSettings) => props.onChange(ds.name)} + onChange={(ds: DataSourceInstanceSettings) => { + // If we're changing the datasource, clear the folder selection + // as otherwise we might still be accidentally filtering out alerts + if (ds.uid !== 'grafana') { + props.context.options.folder = null; + } + return props.onChange(ds.name); + }} />