diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentTypeIcon.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentTypeIcon.tsx index b5d434e92..2bba85085 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentTypeIcon.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentTypeIcon.tsx @@ -1,6 +1,7 @@ "use client"; import type React from "react"; +import { useRef, useState, useEffect } from "react"; import { getConnectorIcon } from "@/contracts/enums/connectorIcons"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; @@ -15,26 +16,33 @@ export function getDocumentTypeLabel(type: string): string { .join(" "); } -const MAX_LABEL_LENGTH = 28; - export function DocumentTypeChip({ type, className }: { type: string; className?: string }) { const icon = getDocumentTypeIcon(type, "h-4 w-4"); const fullLabel = getDocumentTypeLabel(type); - const truncatedLabel = fullLabel.length > MAX_LABEL_LENGTH - ? `${fullLabel.slice(0, MAX_LABEL_LENGTH)}...` - : fullLabel; - const needsTruncation = fullLabel.length > MAX_LABEL_LENGTH; + const textRef = useRef(null); + const [isTruncated, setIsTruncated] = useState(false); + + useEffect(() => { + const checkTruncation = () => { + if (textRef.current) { + setIsTruncated(textRef.current.scrollWidth > textRef.current.clientWidth); + } + }; + checkTruncation(); + window.addEventListener("resize", checkTruncation); + return () => window.removeEventListener("resize", checkTruncation); + }, []); const chip = ( {icon} - {truncatedLabel} + {fullLabel} ); - if (needsTruncation) { + if (isTruncated) { return ( {chip} diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx index 3f45322ef..7e5f95af4 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx @@ -206,7 +206,7 @@ export function DocumentsTableShell({ {columnVisibility.document_type && ( - + )} @@ -243,7 +243,7 @@ export function DocumentsTableShell({ /> {columnVisibility.document_type && ( - + )} @@ -352,7 +352,7 @@ export function DocumentsTableShell({ {columnVisibility.document_type && ( - + {columnVisibility.document_type && ( - + )}