66} from "~/assets/icons/EnvironmentIcons" ;
77import type { RuntimeEnvironment } from "~/models/runtimeEnvironment.server" ;
88import { cn } from "~/utils/cn" ;
9+ import { SimpleTooltip } from "~/components/primitives/Tooltip" ;
10+ import { useEffect , useRef , useState } from "react" ;
911
1012type Environment = Pick < RuntimeEnvironment , "type" > & { branchName ?: string | null } ;
1113
@@ -56,7 +58,10 @@ export function EnvironmentCombo({
5658} ) {
5759 return (
5860 < span className = { cn ( "flex items-center gap-1.5 text-sm text-text-bright" , className ) } >
59- < EnvironmentIcon environment = { environment } className = { cn ( "size-4.5" , iconClassName ) } />
61+ < EnvironmentIcon
62+ environment = { environment }
63+ className = { cn ( "size-4.5 shrink-0" , iconClassName ) }
64+ />
6065 < EnvironmentLabel environment = { environment } />
6166 </ span >
6267 ) ;
@@ -69,11 +74,61 @@ export function EnvironmentLabel({
6974 environment : Environment ;
7075 className ?: string ;
7176} ) {
72- return (
73- < span className = { cn ( environmentTextClassName ( environment ) , className ) } >
74- { environment . branchName ? environment . branchName : environmentFullTitle ( environment ) }
77+ const spanRef = useRef < HTMLSpanElement > ( null ) ;
78+ const [ isTruncated , setIsTruncated ] = useState ( false ) ;
79+ const text = environment . branchName ? environment . branchName : environmentFullTitle ( environment ) ;
80+
81+ useEffect ( ( ) => {
82+ const checkTruncation = ( ) => {
83+ if ( spanRef . current ) {
84+ const isTruncated = spanRef . current . scrollWidth > spanRef . current . clientWidth ;
85+ console . log (
86+ "isTruncated" ,
87+ isTruncated ,
88+ spanRef . current . scrollWidth ,
89+ spanRef . current . clientWidth
90+ ) ;
91+ setIsTruncated ( isTruncated ) ;
92+ }
93+ } ;
94+
95+ checkTruncation ( ) ;
96+ // Add resize observer to recheck on window resize
97+ const resizeObserver = new ResizeObserver ( checkTruncation ) ;
98+ if ( spanRef . current ) {
99+ resizeObserver . observe ( spanRef . current ) ;
100+ }
101+
102+ return ( ) => resizeObserver . disconnect ( ) ;
103+ } , [ text ] ) ;
104+
105+ const content = (
106+ < span
107+ ref = { spanRef }
108+ className = { cn ( "truncate text-left" , environmentTextClassName ( environment ) , className ) }
109+ >
110+ { text }
75111 </ span >
76112 ) ;
113+
114+ if ( isTruncated ) {
115+ return (
116+ < SimpleTooltip
117+ asChild
118+ button = { content }
119+ content = {
120+ < span ref = { spanRef } className = { cn ( "text-left" , environmentTextClassName ( environment ) ) } >
121+ { text }
122+ </ span >
123+ }
124+ side = "right"
125+ variant = "dark"
126+ sideOffset = { 34 }
127+ />
128+ ) ;
129+ }
130+
131+ return content ;
77132}
78133
79134export function environmentTitle ( environment : Environment , username ?: string ) {
0 commit comments