Alerting: Hide labels section if we only have private labels (#105996)

This commit is contained in:
Gilles De Mey
2025-05-26 18:21:30 +02:00
committed by GitHub
parent c834a6e601
commit 5656d3015f
2 changed files with 17 additions and 2 deletions

View File

@ -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();
});
});
});

View File

@ -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);