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.8 KB
Raw Blame
import { Tooltip } from 'antd';
import { Badge } from '@signozhq/ui/badge';
import cx from 'classnames';
import { Pin, PinOff } from '@signozhq/icons';

import { SidebarItem } from '../sideNav.types';

import './NavItem.styles.scss';

export default function NavItem({
	item,
	isActive,
	onClick,
	isDisabled,
	onTogglePin,
	isPinned,
	showIcon,
	dataTestId,
}: {
	item: SidebarItem;
	isActive: boolean;
	onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
	isDisabled: boolean;
	onTogglePin?: (item: SidebarItem) => void;
	isPinned?: boolean;
	showIcon?: boolean;
	dataTestId?: string;
}): JSX.Element {
	const { label, icon, isBeta, isNew, isEarlyAccess, tooltip } = item;

	const handleTogglePinClick = (
		event: React.MouseEvent<SVGSVGElement, MouseEvent>,
	): void => {
		event.stopPropagation();
		onTogglePin?.(item);
	};

	const navItem = (
		<div
			className={cx(
				'nav-item',
				isActive ? 'active' : '',
				isDisabled ? 'disabled' : '',
			)}
			onClick={(event): void => {
				if (isDisabled) {
					return;
				}
				onClick(event);
			}}
			data-testid={dataTestId}
		>
			{showIcon && <div className="nav-item-active-marker" />}
			<div className="nav-item-data">
				{showIcon && (
					<div className={cx('nav-item-icon', isEarlyAccess ? 'noz-wave' : '')}>
						{icon}
					</div>
				)}

				<div className="nav-item-label">{label}</div>

				{isBeta && (
					<div className="nav-item-beta">
						<Badge variant="solid" color="primary">
							Beta
						</Badge>
					</div>
				)}

				{isNew && (
					<div className="nav-item-new">
						<Badge variant="solid" color="primary">
							New
						</Badge>
					</div>
				)}

				{isEarlyAccess && (
					<div className="nav-item-early-access">
						<Badge variant="solid" color="primary">
							Early Access
						</Badge>
					</div>
				)}

				{onTogglePin && !isPinned && (
					<Tooltip title="Add to shortcuts" placement="right">
						<Pin
							size={12}
							className="nav-item-pin-icon"
							onClick={handleTogglePinClick}
							color="var(--Vanilla-400, #c0c1c3)"
							data-testid={`nav-item-pin-${item.itemKey}`}
							aria-label="Add to shortcuts"
						/>
					</Tooltip>
				)}

				{onTogglePin && isPinned && (
					<Tooltip title="Remove from shortcuts" placement="right">
						<PinOff
							size={12}
							className="nav-item-pin-icon"
							onClick={handleTogglePinClick}
							color="var(--Vanilla-400, #c0c1c3)"
							data-testid={`nav-item-pin-${item.itemKey}`}
							aria-label="Remove from shortcuts"
						/>
					</Tooltip>
				)}
			</div>
		</div>
	);

	// Only non-pinnable items set `tooltip`; it would nest with the pin tooltip.
	return (
		<Tooltip title={tooltip} placement="right">
			{navItem}
		</Tooltip>
	);
}

NavItem.defaultProps = {
	onTogglePin: undefined,
	isPinned: false,
	showIcon: false,
	dataTestId: undefined,
};