diff --git a/apps/webapp/app/components/environments/EnvironmentLabel.tsx b/apps/webapp/app/components/environments/EnvironmentLabel.tsx index 3afa861cf3..35c5c05a33 100644 --- a/apps/webapp/app/components/environments/EnvironmentLabel.tsx +++ b/apps/webapp/app/components/environments/EnvironmentLabel.tsx @@ -6,6 +6,8 @@ import { } from "~/assets/icons/EnvironmentIcons"; import type { RuntimeEnvironment } from "~/models/runtimeEnvironment.server"; import { cn } from "~/utils/cn"; +import { SimpleTooltip } from "~/components/primitives/Tooltip"; +import { useEffect, useRef, useState } from "react"; type Environment = Pick & { branchName?: string | null }; @@ -56,7 +58,10 @@ export function EnvironmentCombo({ }) { return ( - + ); @@ -69,11 +74,61 @@ export function EnvironmentLabel({ environment: Environment; className?: string; }) { - return ( - - {environment.branchName ? environment.branchName : environmentFullTitle(environment)} + const spanRef = useRef(null); + const [isTruncated, setIsTruncated] = useState(false); + const text = environment.branchName ? environment.branchName : environmentFullTitle(environment); + + useEffect(() => { + const checkTruncation = () => { + if (spanRef.current) { + const isTruncated = spanRef.current.scrollWidth > spanRef.current.clientWidth; + console.log( + "isTruncated", + isTruncated, + spanRef.current.scrollWidth, + spanRef.current.clientWidth + ); + setIsTruncated(isTruncated); + } + }; + + checkTruncation(); + // Add resize observer to recheck on window resize + const resizeObserver = new ResizeObserver(checkTruncation); + if (spanRef.current) { + resizeObserver.observe(spanRef.current); + } + + return () => resizeObserver.disconnect(); + }, [text]); + + const content = ( + + {text} ); + + if (isTruncated) { + return ( + + {text} + + } + side="right" + variant="dark" + sideOffset={34} + /> + ); + } + + return content; } export function environmentTitle(environment: Environment, username?: string) { diff --git a/apps/webapp/app/components/primitives/Tooltip.tsx b/apps/webapp/app/components/primitives/Tooltip.tsx index 354c6573e8..f5181cedc0 100644 --- a/apps/webapp/app/components/primitives/Tooltip.tsx +++ b/apps/webapp/app/components/primitives/Tooltip.tsx @@ -62,6 +62,7 @@ function SimpleTooltip({ className, buttonClassName, asChild = false, + sideOffset, }: { button: React.ReactNode; content: React.ReactNode; @@ -72,6 +73,7 @@ function SimpleTooltip({ className?: string; buttonClassName?: string; asChild?: boolean; + sideOffset?: number; }) { return ( @@ -82,6 +84,7 @@ function SimpleTooltip({