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.

877 B
Raw Blame
import type { PanelTable } from 'pages/DashboardPage/DashboardContainer/queryV5/types';

/**
 * Reduces the scalar tables of a V5 response to the single number a NumberPanel
 * renders: the first row's `isValueColumn` cell of the first table with rows,
 * falling back to the row's first cell (mirrors the V1 `formatForWeb` read).
 * Returns `null` when there is no numeric value (renderer shows "No Data").
 */
export function prepareNumberData(tables: PanelTable[]): number | null {
	for (const table of tables) {
		if (table.rows.length === 0) {
			continue;
		}
		const row = table.rows[0].data;
		const valueColumn = table.columns.find((column) => column.isValueColumn);
		const raw = valueColumn
			? row[valueColumn.id || valueColumn.name]
			: Object.values(row)[0];
		const value = Number(raw);
		if (Number.isFinite(value)) {
			return value;
		}
	}

	return null;
}