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.8 KB
Raw Blame
import { Info } from '@signozhq/icons';
import { Tooltip } from '@signozhq/ui/tooltip';

import styles from './ColumnHeader.module.scss';
import cx from 'classnames';
import { MouseEventHandler } from 'react';
import { DOCS_BASE_URL } from 'constants/app';

const DOCS_ROOT = `${DOCS_BASE_URL}/docs`;

interface ColumnHeaderProps {
	children?: React.ReactNode;
	docPath?: string;
	tooltip?: React.ReactNode;
	className?: string;
}

function ColumnHeader({
	children,
	docPath,
	tooltip,
	className,
}: ColumnHeaderProps): JSX.Element {
	const stopPropagationHandler: MouseEventHandler = (e): void =>
		e.stopPropagation();

	const renderContent = (): React.ReactNode => {
		if (children) {
			return children;
		}

		return null;
	};

	const renderInfoIcon = (): React.ReactNode => {
		if (docPath) {
			const tooltipTitle = tooltip || 'Not sure what this means?';
			const isJustStringTitle = typeof tooltipTitle === 'string';

			return (
				<Tooltip
					title={
						<div onClick={stopPropagationHandler}>
							{tooltipTitle}{' '}
							<a
								href={`${DOCS_ROOT}${docPath}`}
								target="_blank"
								rel="noopener"
								onClick={stopPropagationHandler}
							>
								{isJustStringTitle
									? 'Learn more.'
									: 'Check the documentation to learn more.'}
							</a>
						</div>
					}
				>
					<div className={styles.infoIcon}>
						<Info size="md" />
					</div>
				</Tooltip>
			);
		}

		if (tooltip) {
			return (
				<Tooltip title={<div onClick={stopPropagationHandler}>{tooltip}</div>}>
					<div className={styles.infoIcon}>
						<Info size="md" />
					</div>
				</Tooltip>
			);
		}

		return null;
	};

	return (
		<div className={cx(styles.columnHeader, className)} data-slot="column-header">
			<div className={styles.columnHeaderLabel}>{renderContent()}</div>
			{renderInfoIcon()}
		</div>
	);
}

export default ColumnHeader;