From fa9f69270736af61f1bd973e269bf54aaef61638 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:08:09 +0100 Subject: [PATCH] Alerting: Fix AlertsFolderView not showing rules when using nested folders (#84465) * Fix AlertsFolderView not showing rules when using nested folders * Fix tests --- .../features/alerting/unified/AlertsFolderView.test.tsx | 8 ++++++-- public/app/features/alerting/unified/AlertsFolderView.tsx | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/app/features/alerting/unified/AlertsFolderView.test.tsx b/public/app/features/alerting/unified/AlertsFolderView.test.tsx index f3bb1f61703..4ae40d245b4 100644 --- a/public/app/features/alerting/unified/AlertsFolderView.test.tsx +++ b/public/app/features/alerting/unified/AlertsFolderView.test.tsx @@ -42,13 +42,14 @@ const mockFolder = (folderOverride: Partial = {}): FolderState => { }; describe('AlertsFolderView tests', () => { - it('Should display grafana alert rules when the namespace name matches the folder name', () => { + it('Should display grafana alert rules when the folder uid matches the name space uid', () => { // Arrange const folder = mockFolder(); const grafanaNamespace: CombinedRuleNamespace = { name: folder.title, rulesSource: GRAFANA_RULES_SOURCE_NAME, + uid: 'folder-1', groups: [ { name: 'group1', @@ -91,13 +92,14 @@ describe('AlertsFolderView tests', () => { expect(alertRows[5]).toHaveTextContent('Test Alert 6'); }); - it('Should not display alert rules when the namespace name does not match the folder name', () => { + it('Should not display alert rules when the namespace uid does not match the folder uid', () => { // Arrange const folder = mockFolder(); const grafanaNamespace: CombinedRuleNamespace = { name: 'Folder without alerts', rulesSource: GRAFANA_RULES_SOURCE_NAME, + uid: 'folder-2', groups: [ { name: 'default', @@ -130,6 +132,7 @@ describe('AlertsFolderView tests', () => { const grafanaNamespace: CombinedRuleNamespace = { name: folder.title, rulesSource: GRAFANA_RULES_SOURCE_NAME, + uid: 'folder-1', groups: [ { name: 'default', @@ -162,6 +165,7 @@ describe('AlertsFolderView tests', () => { const grafanaNamespace: CombinedRuleNamespace = { name: folder.title, rulesSource: GRAFANA_RULES_SOURCE_NAME, + uid: 'folder-1', groups: [ { name: 'default', diff --git a/public/app/features/alerting/unified/AlertsFolderView.tsx b/public/app/features/alerting/unified/AlertsFolderView.tsx index 212acdc87f3..ff71c426a72 100644 --- a/public/app/features/alerting/unified/AlertsFolderView.tsx +++ b/public/app/features/alerting/unified/AlertsFolderView.tsx @@ -50,7 +50,8 @@ export const AlertsFolderView = ({ folder }: Props) => { const { nameFilter, labelFilter, sortOrder, setNameFilter, setLabelFilter, setSortOrder } = useAlertsFolderViewParams(); - const matchingNamespace = combinedNamespaces.find((namespace) => namespace.name === folder.title); + const matchingNamespace = combinedNamespaces.find((namespace) => namespace.uid === folder.uid); + const alertRules = matchingNamespace?.groups.flatMap((group) => group.rules) ?? []; const filteredRules = filterAndSortRules(alertRules, nameFilter, labelFilter, sortOrder ?? SortOrder.Ascending);