From aeba2401a9326d8eddb062a2534d32b66ef3caeb Mon Sep 17 00:00:00 2001 From: rodrigopk Date: Tue, 6 Jan 2026 15:46:28 -0500 Subject: [PATCH] Handle unsafe array access --- .../alerting/unified/components/rules/RulesGroup.tsx | 6 +++--- .../alerting/unified/rule-list/PaginatedGrafanaLoader.tsx | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/public/app/features/alerting/unified/components/rules/RulesGroup.tsx b/public/app/features/alerting/unified/components/rules/RulesGroup.tsx index 83f0ebde0fb..aeead7db121 100644 --- a/public/app/features/alerting/unified/components/rules/RulesGroup.tsx +++ b/public/app/features/alerting/unified/components/rules/RulesGroup.tsx @@ -168,9 +168,9 @@ export const RulesGroup = React.memo(({ group, namespace, expandAll, viewMode }: if (isListView) { groupName = ; } else if (isUngroupedRuleGroup(group.name)) { - groupName = ( - - ); + const firstRuleName = group.rules[0]?.name ?? 'Unknown Rule'; + const groupDisplayName = `${firstRuleName} (Ungrouped)`; + groupName = ; } return ( diff --git a/public/app/features/alerting/unified/rule-list/PaginatedGrafanaLoader.tsx b/public/app/features/alerting/unified/rule-list/PaginatedGrafanaLoader.tsx index 8fffeddf261..8bb360ad6d2 100644 --- a/public/app/features/alerting/unified/rule-list/PaginatedGrafanaLoader.tsx +++ b/public/app/features/alerting/unified/rule-list/PaginatedGrafanaLoader.tsx @@ -162,7 +162,8 @@ export function GrafanaRuleGroupListItem({ group, namespaceName }: GrafanaRuleGr const detailsLink = groups.detailsPageLink(GRAFANA_RULES_SOURCE_NAME, group.folderUid, group.name); - const groupDisplayName = isUngroupedRuleGroup(group.name) ? `${group.rules[0].name} (Ungrouped)` : group.name; + const firstRuleName = group.rules[0]?.name ?? 'Unknown Rule'; + const groupDisplayName = isUngroupedRuleGroup(group.name) ? `${firstRuleName} (Ungrouped)` : group.name; return (