Skip to content

Commit 1a29694

Browse files
authored
feat(ui): smart truncation tooltips, org name limits, and logo UI polish (Dokploy#5345)
1 parent 1572008 commit 1a29694

4 files changed

Lines changed: 96 additions & 11 deletions

File tree

‎apps/dokploy/components/dashboard/organization/handle-organization.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { standardSchemaResolver as zodResolver } from "@hookform/resolvers/standard-schema";
22

3-
import { GlobeIcon, PenBoxIcon, Plus, X } from "lucide-react";
3+
import { PenBoxIcon, Plus, X } from "lucide-react";
44
import { useEffect, useRef, useState } from "react";
55
import { useForm } from "react-hook-form";
66
import { toast } from "sonner";
77
import { z } from "zod";
8+
import { Logo } from "@/components/shared/logo";
89
import { Button } from "@/components/ui/button";
910
import {
1011
Dialog,
@@ -255,8 +256,10 @@ export function AddOrganization({
255256
control={form.control}
256257
name="name"
257258
render={({ field }) => (
258-
<FormItem className="tems-center gap-4">
259-
<FormLabel className="text-right">Name</FormLabel>
259+
<FormItem className="items-center gap-4">
260+
<div className="flex items-center justify-between">
261+
<FormLabel className="text-right">Name</FormLabel>
262+
</div>
260263
<FormControl>
261264
<Input
262265
placeholder="Organization name"
@@ -285,16 +288,16 @@ export function AddOrganization({
285288
<FormControl>
286289
<div className="col-span-3 flex flex-col gap-3">
287290
<div className="flex items-center gap-3">
288-
<div className="flex size-10 shrink-0 items-center justify-center rounded-md border bg-muted/50 p-1">
291+
<div className="flex size-10 shrink-0 items-center justify-center rounded-md border bg-muted/50 overflow-hidden">
289292
{field.value ? (
290293
// biome-ignore lint/performance/noImgElement: user uploaded logo preview
291294
<img
292295
src={field.value}
293296
alt="Logo preview"
294-
className="size-full object-contain"
297+
className="size-full object-cover"
295298
/>
296299
) : (
297-
<GlobeIcon className="size-5 text-muted-foreground" />
300+
<Logo className="size-7" />
298301
)}
299302
</div>
300303
<div className="relative flex-1">

‎apps/dokploy/components/layouts/side.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Link from "next/link";
4343
import { usePathname } from "next/navigation";
4444
import { useEffect, useState } from "react";
4545
import { toast } from "sonner";
46+
import { TruncateTooltip } from "@/components/shared/truncate-tooltip";
4647
import { Badge } from "@/components/ui/badge";
4748
import {
4849
Breadcrumb,
@@ -656,9 +657,12 @@ function SidebarLogo() {
656657
)}
657658
>
658659
<div className="flex items-center gap-1.5 min-w-0 w-full">
659-
<p className="text-sm font-medium truncate">
660-
{activeOrganization?.name ?? "Select Organization"}
661-
</p>
660+
<TruncateTooltip
661+
text={
662+
activeOrganization?.name ?? "Select Organization"
663+
}
664+
className="text-sm font-medium"
665+
/>
662666
{haveValidLicense && (
663667
<Badge variant="blue" className="shrink-0">
664668
Enterprise
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Tooltip as TooltipPrimitive } from "radix-ui";
2+
import type React from "react";
3+
import { useEffect, useRef, useState } from "react";
4+
import {
5+
Tooltip,
6+
TooltipProvider,
7+
TooltipTrigger,
8+
} from "@/components/ui/tooltip";
9+
import { cn } from "@/lib/utils";
10+
11+
interface Props extends React.HTMLAttributes<HTMLParagraphElement> {
12+
text: string;
13+
}
14+
15+
export const TruncateTooltip = ({ text, className, ...props }: Props) => {
16+
const textRef = useRef<HTMLParagraphElement>(null);
17+
const [isTruncated, setIsTruncated] = useState(false);
18+
const [isOpen, setIsOpen] = useState(false);
19+
20+
useEffect(() => {
21+
const element = textRef.current;
22+
if (!element) return;
23+
24+
const checkTruncation = () => {
25+
const truncated = element.scrollWidth > element.clientWidth;
26+
setIsTruncated(truncated);
27+
if (!truncated) {
28+
setIsOpen(false);
29+
}
30+
};
31+
32+
checkTruncation();
33+
34+
const resizeObserver = new ResizeObserver(() => {
35+
checkTruncation();
36+
});
37+
38+
resizeObserver.observe(element);
39+
40+
return () => {
41+
resizeObserver.disconnect();
42+
};
43+
}, [text]);
44+
45+
const content = (
46+
<p ref={textRef} className={cn("truncate", className)} {...props}>
47+
{text}
48+
</p>
49+
);
50+
51+
return (
52+
<TooltipProvider>
53+
<Tooltip
54+
delayDuration={0}
55+
open={isOpen}
56+
onOpenChange={(open) => {
57+
// Only allow opening if it's actually truncated
58+
if (isTruncated) {
59+
setIsOpen(open);
60+
} else {
61+
setIsOpen(false);
62+
}
63+
}}
64+
>
65+
<TooltipTrigger asChild>{content}</TooltipTrigger>
66+
<TooltipPrimitive.Portal>
67+
<TooltipPrimitive.Content
68+
side="bottom"
69+
align="start"
70+
className="z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md max-w-[280px] break-words animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2"
71+
>
72+
<p>{text}</p>
73+
</TooltipPrimitive.Content>
74+
</TooltipPrimitive.Portal>
75+
</Tooltip>
76+
</TooltipProvider>
77+
);
78+
};

‎apps/dokploy/server/api/routers/organization.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const organizationRouter = createTRPCRouter({
2525
create: protectedProcedure
2626
.input(
2727
z.object({
28-
name: z.string(),
28+
name: z.string().min(1),
2929
logo: z.string().optional(),
3030
}),
3131
)
@@ -130,7 +130,7 @@ export const organizationRouter = createTRPCRouter({
130130
.input(
131131
z.object({
132132
organizationId: z.string(),
133-
name: z.string(),
133+
name: z.string().min(1),
134134
logo: z.string().optional(),
135135
defaultRole: z.string().min(1).nullable().optional(),
136136
}),

0 commit comments

Comments
 (0)