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.

1.5 KB
Raw Blame
import type { DashboardtypesPanelSpecDTO } from 'api/generated/services/sigNoz.schemas';
import { resolveTexts } from 'hooks/dashboard/useContextVariables';

import { resolveContextLinkUrl } from './resolveContextLinkUrl';

/** A panel context link with its label and URL templates resolved, ready to render. */
export interface ResolvedDrilldownLink {
	id: string;
	label: string;
	url: string;
	/** Opens in a new tab; links saved before the toggle existed default to true. */
	targetBlank: boolean;
}

/**
 * Resolves a panel's context links for the drilldown menu: substitutes variables in each link's
 * label + URL, drops links without a URL, and skips substitution when `renderVariables === false`.
 */
export function resolvePanelContextLinks(
	links: DashboardtypesPanelSpecDTO['links'],
	processedVariables: Record<string, string>,
): ResolvedDrilldownLink[] {
	const usable = (links ?? []).filter((link) => !!link.url);
	if (usable.length === 0) {
		return [];
	}

	return usable.map((link, index) => {
		const rawLabel = link.name || link.url || '';
		const rawUrl = link.url ?? '';
		const targetBlank = link.targetBlank ?? true;
		// Only an explicit `false` opts out; undefined defaults to substitution on.
		if (link.renderVariables === false) {
			return { id: String(index), label: rawLabel, url: rawUrl, targetBlank };
		}
		return {
			id: String(index),
			label: resolveTexts({ texts: [rawLabel], processedVariables }).fullTexts[0],
			url: resolveContextLinkUrl(rawUrl, processedVariables),
			targetBlank,
		};
	});
}