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.9 KB
Raw Blame
import { HTMLAttributes } from 'react';
import { Color } from '@signozhq/design-tokens';
import { Table, TableColumnsType as ColumnsType } from 'antd';
import { Progress } from '@signozhq/ui/progress';
import logEvent from 'api/common/logEvent';
import { ConditionalAlertPopover } from 'container/AlertHistory/AlertPopover/AlertPopover';
import AlertLabels from 'pages/AlertDetails/AlertHeader/AlertLabels/AlertLabels';
import PaginationInfoText from 'periscope/components/PaginationInfoText/PaginationInfoText';
import {
	AlertRuleStats,
	AlertRuleTimelineTableResponse,
	AlertRuleTopContributors,
} from 'types/api/alerts/def';

function TopContributorsRows({
	topContributors,
	totalCurrentTriggers,
}: {
	topContributors: AlertRuleTopContributors[];
	totalCurrentTriggers: AlertRuleStats['totalCurrentTriggers'];
}): JSX.Element {
	const columns: ColumnsType<AlertRuleTopContributors> = [
		{
			title: 'labels',
			dataIndex: 'labels',
			key: 'labels',
			width: '51%',
			render: (
				labels: AlertRuleTopContributors['labels'],
				record,
			): JSX.Element => (
				<ConditionalAlertPopover
					relatedTracesLink={record.relatedTracesLink}
					relatedLogsLink={record.relatedLogsLink}
				>
					<div>
						<AlertLabels labels={labels} />
					</div>
				</ConditionalAlertPopover>
			),
		},
		{
			title: 'progressBar',
			dataIndex: 'count',
			key: 'progressBar',
			width: '39%',
			render: (count: AlertRuleTopContributors['count'], record): JSX.Element => (
				<ConditionalAlertPopover
					relatedTracesLink={record.relatedTracesLink}
					relatedLogsLink={record.relatedLogsLink}
				>
					<Progress
						percent={(count / totalCurrentTriggers) * 100}
						showInfo={false}
						strokeColor={Color.BG_ROBIN_500}
						className="top-contributors-progress"
					/>
				</ConditionalAlertPopover>
			),
		},
		{
			title: 'count',
			dataIndex: 'count',
			key: 'count',
			width: '10%',
			render: (count: AlertRuleTopContributors['count'], record): JSX.Element => (
				<ConditionalAlertPopover
					relatedTracesLink={record.relatedTracesLink}
					relatedLogsLink={record.relatedLogsLink}
				>
					<div
						className="total-contribution"
						data-testid="top-contributors-row-count"
					>
						{count}/{totalCurrentTriggers}
					</div>
				</ConditionalAlertPopover>
			),
		},
	];

	const handleRowClick = (
		record: AlertRuleTopContributors,
	): HTMLAttributes<AlertRuleTimelineTableResponse> & {
		'data-testid': string;
	} => ({
		'data-testid': 'top-contributors-row',
		onClick: (): void => {
			logEvent('Alert history: Top contributors row: Clicked', {
				labels: record.labels,
			});
		},
	});

	return (
		<Table
			rowClassName="contributors-row"
			rowKey={(row): string => `top-contributor-${row.fingerprint}`}
			onRow={handleRowClick}
			columns={columns}
			showHeader={false}
			dataSource={topContributors}
			pagination={
				topContributors.length > 10 ? { showTotal: PaginationInfoText } : false
			}
		/>
	);
}

export default TopContributorsRows;