Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

2.3 KB
Raw Blame
import type { ReactElement, ReactNode } from 'react';
import { Button } from '@signozhq/ui/button';
import { Typography } from '@signozhq/ui/typography';
import cx from 'classnames';

import styles from './PanelMessage.module.scss';

export interface PanelMessageAction {
	label: string;
	onClick: () => void;
	/** Optional leading icon for the action button. */
	icon?: ReactElement;
}

interface PanelMessageProps {
	/** Glyph shown above the title — sets the state's visual identity. */
	icon: ReactNode;
	title: string;
	/** Secondary line explaining the state / suggesting a next step. */
	description?: string;
	/** Optional call-to-action (e.g. Retry). Omitted → no button. */
	action?: PanelMessageAction;
	/** Second call-to-action rendered beside `action` (e.g. Extend + Retry). */
	secondaryAction?: PanelMessageAction;
	/** `danger` tints the icon for failure states; `neutral` for empty states. */
	tone?: 'neutral' | 'danger';
	'data-testid'?: string;
}

/**
 * Shared centred panel state (icon + title + optional description/action) so the
 * no-query / no-data / error states stay visually consistent across call sites.
 */
function PanelMessage({
	icon,
	title,
	description,
	action,
	secondaryAction,
	tone = 'neutral',
	'data-testid': testId,
}: PanelMessageProps): JSX.Element {
	const actions: Array<{ suffix: string; action: PanelMessageAction }> = [];
	if (action) {
		actions.push({ suffix: 'action', action });
	}
	if (secondaryAction) {
		actions.push({ suffix: 'secondary-action', action: secondaryAction });
	}

	return (
		<div className={styles.message} data-testid={testId}>
			<div className={cx(styles.icon, { [styles.iconDanger]: tone === 'danger' })}>
				{icon}
			</div>
			<Typography.Text className={styles.title}>{title}</Typography.Text>
			{description && (
				<Typography.Text className={styles.description}>
					{description}
				</Typography.Text>
			)}
			{actions.length > 0 && (
				<div className={styles.actions}>
					{actions.map(({ suffix, action: item }) => (
						<Button
							key={suffix}
							variant="outlined"
							color="secondary"
							size="sm"
							prefix={item.icon}
							onClick={item.onClick}
							testId={testId ? `${testId}-${suffix}` : undefined}
						>
							{item.label}
						</Button>
					))}
				</div>
			)}
		</div>
	);
}

export default PanelMessage;