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.2 KB
Raw Blame
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
import { getPanelDefinition } from 'pages/DashboardPage/DashboardContainer/Panels/registry';
import { useTextBackground } from 'pages/DashboardPage/DashboardContainer/Panels/hooks/useTextBackground';

import type { DashboardSection } from '../../utils';
import QueryPanelContent from './QueryPanelContent';
import StaticPanelContent from './StaticPanelContent';
import styles from './Panel.module.scss';

/**
 * Layout context for the panel actions menu — present only in editable mode. No
 * callbacks: the menu resolves its own mutations from store-backed hooks.
 */
export interface PanelActionsConfig {
	currentLayoutIndex: number;
	sections: DashboardSection[];
}

interface PanelProps {
	panel: DashboardtypesPanelDTO;
	panelId: string;
	/** True once this panel enters the viewport — gates the fetch (owned by SectionGridItem). */
	isVisible?: boolean;
	/** Move/delete actions — present only in editable sectioned mode. */
	panelActions?: PanelActionsConfig;
}

/**
 * A single dashboard panel: the card shell, forking on the kind's mode before any
 * query machinery exists, so a static kind never mounts a fetch — not even a
 * disabled one.
 */
function Panel({
	panel,
	panelId,
	isVisible,
	panelActions,
}: PanelProps): JSX.Element {
	const panelDefinition = getPanelDefinition(panel.spec.plugin.kind);
	const background = useTextBackground(panel.spec);

	return (
		<div
			className={styles.panel}
			style={background.style}
			data-panel-visible={isVisible === false ? 'false' : 'true'}
			// Stable locator so the "Download as PNG" action can find this node to
			// capture, without threading a ref through the header/actions chain.
			data-panel-root={panelId}
			data-testid={`panel-${panelId}`}
		>
			{panelDefinition.mode === 'static' ? (
				<StaticPanelContent
					panel={panel}
					panelId={panelId}
					panelDefinition={panelDefinition}
					panelActions={panelActions}
				/>
			) : (
				<QueryPanelContent
					panel={panel}
					panelId={panelId}
					panelDefinition={panelDefinition}
					isVisible={isVisible}
					panelActions={panelActions}
				/>
			)}
		</div>
	);
}

export default Panel;