Grafana UI: Clearly separate multiple warnings by using HTML tags (#97979)

* Allow html in tooltips

* Display multiple warnings/infos properly with html

* Revert "Allow html in tooltips"

This reverts commit 5c7e965d2d554b693d4897e52cf6865e0c9b8374.

* Display multiple warnings/infos properly with html in ReactNode

* Fix lint

* Revise according to code review

* Revise according to code review part 2

* Revise according to code review part 3
This commit is contained in:
zenador
2025-03-19 07:05:53 +01:00
committed by GitHub
parent 6c704484e9
commit 7f9fa8c662
3 changed files with 7 additions and 4 deletions
@@ -10,6 +10,7 @@ import { useStyles2 } from '../../themes/ThemeContext';
import { IconName } from '../../types';
import { SkeletonComponent, attachSkeleton } from '../../utils/skeleton';
import { Icon } from '../Icon/Icon';
import { PopoverContent } from '../Tooltip';
import { Tooltip } from '../Tooltip/Tooltip';
export type BadgeColor = 'blue' | 'red' | 'green' | 'orange' | 'purple' | 'darkgrey';
@@ -18,7 +19,7 @@ export interface BadgeProps extends HTMLAttributes<HTMLDivElement> {
text: React.ReactNode;
color: BadgeColor;
icon?: IconName;
tooltip?: string;
tooltip?: PopoverContent;
}
const BadgeComponent = React.memo<BadgeProps>(({ icon, color, text, tooltip, className, ...otherProps }) => {
@@ -17,7 +17,8 @@ export const PluginStateInfo = (props: Props) => {
<Badge
className={props.className}
color={display.color}
title={display.tooltip}
title={typeof display.tooltip === 'string' ? display.tooltip : undefined}
tooltip={typeof display.tooltip !== 'string' ? display.tooltip : undefined}
text={display.text}
icon={display.icon}
/>
@@ -34,7 +34,7 @@ import {
usePluginComponents,
} from '@grafana/runtime';
import { DataQuery } from '@grafana/schema';
import { Badge, ErrorBoundaryAlert } from '@grafana/ui';
import { Badge, ErrorBoundaryAlert, List } from '@grafana/ui';
import { OperationRowHelp } from 'app/core/components/QueryOperationRow/OperationRowHelp';
import {
QueryOperationAction,
@@ -424,7 +424,8 @@ export class QueryEditorRow<TQuery extends DataQuery> extends PureComponent<Prop
const colour = type === 'warning' ? 'orange' : 'blue';
const iconName = type === 'warning' ? 'exclamation-triangle' : 'file-landscape-alt';
const serializedWarnings = uniqueWarnings.map((warning) => warning.text).join('\n');
const listItems = uniqueWarnings.map((warning) => warning.text);
const serializedWarnings = <List items={listItems} renderItem={(item) => <>{item}</>} />;
return (
<Badge