From 68bc0f80768fe848fb43165011b34ddf875ef82c Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Tue, 28 Oct 2025 12:09:41 +0100 Subject: [PATCH] Alerting: Use common labels tooltip in Triage (#113072) * Add a tooltip mode for common labels and use it in Triage workbench * Change Tooltip to ToggleTip for displaying common labels --- .../rules/components/labels/AlertLabels.tsx | 65 ++++++++++++++----- .../unified/triage/rows/InstanceRow.tsx | 1 + 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/packages/grafana-alerting/src/grafana/rules/components/labels/AlertLabels.tsx b/packages/grafana-alerting/src/grafana/rules/components/labels/AlertLabels.tsx index 3646c02a13e..b2bd9fee77d 100644 --- a/packages/grafana-alerting/src/grafana/rules/components/labels/AlertLabels.tsx +++ b/packages/grafana-alerting/src/grafana/rules/components/labels/AlertLabels.tsx @@ -1,10 +1,10 @@ import { css } from '@emotion/css'; import { chain } from 'lodash'; -import { useState } from 'react'; +import { useMemo, useState } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Trans, t } from '@grafana/i18n'; -import { Button, useStyles2 } from '@grafana/ui'; +import { Button, Stack, Toggletip, useStyles2 } from '@grafana/ui'; import { findCommonLabels, isPrivateLabel } from '../../utils/labels'; @@ -16,14 +16,24 @@ export interface AlertLabelsProps { labelSets?: Array>; size?: LabelSize; onClick?: ([value, key]: [string | undefined, string | undefined]) => void; + commonLabelsMode?: 'expand' | 'tooltip'; } -export const AlertLabels = ({ labels, displayCommonLabels, labelSets, size, onClick }: AlertLabelsProps) => { +export const AlertLabels = ({ + labels, + displayCommonLabels, + labelSets, + size, + onClick, + commonLabelsMode = 'expand', +}: AlertLabelsProps) => { const styles = useStyles2(getStyles, size); const [showCommonLabels, setShowCommonLabels] = useState(false); - const computedCommonLabels = - displayCommonLabels && Array.isArray(labelSets) && labelSets.length > 1 ? findCommonLabels(labelSets) : {}; + const computedCommonLabels = useMemo( + () => (displayCommonLabels && Array.isArray(labelSets) && labelSets.length > 1 ? findCommonLabels(labelSets) : {}), + [displayCommonLabels, labelSets] + ); const labelsToShow = chain(labels) .toPairs() @@ -35,6 +45,17 @@ export const AlertLabels = ({ labels, displayCommonLabels, labelSets, size, onCl const hasCommonLabels = commonLabelsCount > 0; const tooltip = t('alert-labels.button.show.tooltip', 'Show common labels'); + const commonLabelsTooltip = useMemo( + () => ( + + {Object.entries(computedCommonLabels).map(([label, value]) => ( + + ))} + + ), + [computedCommonLabels, size] + ); + return (
{labelsToShow.map(([label, value]) => { @@ -53,18 +74,28 @@ export const AlertLabels = ({ labels, displayCommonLabels, labelSets, size, onCl {!showCommonLabels && hasCommonLabels && (
- + {commonLabelsMode === 'expand' ? ( + + ) : ( + + + + )}
)} {showCommonLabels && hasCommonLabels && ( diff --git a/public/app/features/alerting/unified/triage/rows/InstanceRow.tsx b/public/app/features/alerting/unified/triage/rows/InstanceRow.tsx index e18898aa48e..6bff83f9b20 100644 --- a/public/app/features/alerting/unified/triage/rows/InstanceRow.tsx +++ b/public/app/features/alerting/unified/triage/rows/InstanceRow.tsx @@ -112,6 +112,7 @@ export function InstanceRow({ displayCommonLabels={true} labelSets={[instance.labels, commonLabels]} size="xs" + commonLabelsMode="tooltip" /> ) }