From 5656d3015f2d333eef5d7c8920395d68541f9fb0 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Mon, 26 May 2025 18:21:30 +0200 Subject: [PATCH] Alerting: Hide labels section if we only have private labels (#105996) --- .../components/rule-viewer/RuleViewer.test.tsx | 14 ++++++++++++++ .../unified/components/rule-viewer/RuleViewer.tsx | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx index 35221269d59..a3125ccca53 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.test.tsx @@ -24,6 +24,7 @@ import { grantPermissionsHelper } from '../../test/test-utils'; import { setupDataSources } from '../../testSetup/datasources'; import { Annotation } from '../../utils/constants'; import { DataSourceType } from '../../utils/datasource'; +import { GRAFANA_ORIGIN_LABEL } from '../../utils/labels'; import * as ruleId from '../../utils/rule-id'; import { stringifyIdentifier } from '../../utils/rule-id'; @@ -286,6 +287,19 @@ describe('RuleViewer', () => { expect(versionSummary).toHaveTextContent(/Version 5 updated by alerting/i); expect(versionSummary).toHaveTextContent(/Version 6 updated by provisioning/i); }); + + it('should not show any labels if we only have private labels', async () => { + const ruleIdentifier = ruleId.fromCombinedRule('grafana', mockRule); + const rule = getGrafanaRule({ + name: 'Test alert', + labels: { + [GRAFANA_ORIGIN_LABEL]: 'plugins/synthetic-monitoring-app', + }, + }); + + await renderRuleViewer(rule, ruleIdentifier); + expect(screen.queryByText('Labels')).not.toBeInTheDocument(); + }); }); }); diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx index 32b648243b9..0d5e4094f48 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx @@ -1,5 +1,5 @@ import { css } from '@emotion/css'; -import { chain, isEmpty, truncate } from 'lodash'; +import { chain, truncate } from 'lodash'; import { useEffect, useState } from 'react'; import { useMeasure } from 'react-use'; @@ -40,6 +40,7 @@ import { useReturnTo } from '../../hooks/useReturnTo'; import { PluginOriginBadge } from '../../plugins/PluginOriginBadge'; import { Annotation } from '../../utils/constants'; import { ruleIdentifierToRuleSourceIdentifier } from '../../utils/datasource'; +import { labelsSize } from '../../utils/labels'; import { makeDashboardLink, makePanelLink, stringifyErrorLike } from '../../utils/misc'; import { createListFilterLink } from '../../utils/navigation'; import { @@ -188,7 +189,7 @@ const createMetadata = (rule: CombinedRule): PageInfoItem[] => { const hasDashboardAndPanel = dashboardUID && panelID; const hasDashboard = dashboardUID; - const hasLabels = !isEmpty(labels); + const hasLabels = labelsSize(labels) > 0; const interval = group.interval; const styles = useStyles2(getStyles);