Skip to content

Commit 12f4653

Browse files
authored
Fix long preview branch names (#2124)
* Truncate long branch names, don’t let the icon shrink * Truncate and show tooltip for long branch names
1 parent 47f4726 commit 12f4653

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

apps/webapp/app/components/environments/EnvironmentLabel.tsx

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from "~/assets/icons/EnvironmentIcons";
77
import type { RuntimeEnvironment } from "~/models/runtimeEnvironment.server";
88
import { cn } from "~/utils/cn";
9+
import { SimpleTooltip } from "~/components/primitives/Tooltip";
10+
import { useEffect, useRef, useState } from "react";
911

1012
type 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

79134
export function environmentTitle(environment: Environment, username?: string) {

apps/webapp/app/components/primitives/Tooltip.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function SimpleTooltip({
6262
className,
6363
buttonClassName,
6464
asChild = false,
65+
sideOffset,
6566
}: {
6667
button: React.ReactNode;
6768
content: React.ReactNode;
@@ -72,6 +73,7 @@ function SimpleTooltip({
7273
className?: string;
7374
buttonClassName?: string;
7475
asChild?: boolean;
76+
sideOffset?: number;
7577
}) {
7678
return (
7779
<TooltipProvider disableHoverableContent={disableHoverableContent}>
@@ -82,6 +84,7 @@ function SimpleTooltip({
8284
<TooltipContent
8385
side={side}
8486
hidden={hidden}
87+
sideOffset={sideOffset}
8588
className={cn("text-xs", className)}
8689
variant={variant}
8790
>

0 commit comments

Comments
 (0)