From cd33accb1a9280ba857ff68aa33dc2381e2aea70 Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Mon, 1 Dec 2025 00:45:41 +0400 Subject: [PATCH] refactor: show tooltip for truncated text --- src/components/traffic-details-dialog.tsx | 60 ++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/src/components/traffic-details-dialog.tsx b/src/components/traffic-details-dialog.tsx index 5c020a2..2a0adab 100644 --- a/src/components/traffic-details-dialog.tsx +++ b/src/components/traffic-details-dialog.tsx @@ -26,6 +26,11 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import { + TooltipContent, + TooltipTrigger, + Tooltip as UITooltip, +} from "@/components/ui/tooltip"; import type { FilteredTrafficStats } from "@/types"; type TimePeriod = @@ -90,6 +95,53 @@ function getSecondsForPeriod(period: TimePeriod): number { } } +const TruncatedDomain = React.memo<{ domain: string }>(({ domain }) => { + const ref = React.useRef(null); + const [isTruncated, setIsTruncated] = React.useState(false); + + const checkTruncation = React.useCallback(() => { + if (ref.current) { + setIsTruncated(ref.current.scrollWidth > ref.current.clientWidth); + } + }, []); + + React.useLayoutEffect(() => { + checkTruncation(); + }); + + React.useEffect(() => { + const resizeObserver = new ResizeObserver(checkTruncation); + if (ref.current) { + resizeObserver.observe(ref.current); + } + + return () => { + resizeObserver.disconnect(); + }; + }, [checkTruncation]); + + const content = ( + + {domain} + + ); + + if (!isTruncated) { + return content; + } + + return ( + + {content} + +

{domain}

+
+
+ ); +}); + +TruncatedDomain.displayName = "TruncatedDomain"; + export function TrafficDetailsDialog({ isOpen, onClose, @@ -407,9 +459,7 @@ export function TrafficDetailsDialog({ {index + 1} - - {domain.domain} - + {domain.request_count.toLocaleString()} @@ -450,9 +500,7 @@ export function TrafficDetailsDialog({ {index + 1} - - {domain.domain} - + {domain.request_count.toLocaleString()}