From 9eed63bd6f7ac6770287762823175d0d7a779c62 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 27 Mar 2025 08:37:09 +0800 Subject: [PATCH] Improve tooltips display for small table list --- .../src/features/DocumentManager.tsx | 81 ++++++++++++++++--- 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/lightrag_webui/src/features/DocumentManager.tsx b/lightrag_webui/src/features/DocumentManager.tsx index ff7c3ad5..c32c8403 100644 --- a/lightrag_webui/src/features/DocumentManager.tsx +++ b/lightrag_webui/src/features/DocumentManager.tsx @@ -55,6 +55,18 @@ const pulseStyle = ` margin-top: 0 !important; } +/* Fixed tooltip styles for small tables */ +.tooltip-fixed { + position: fixed !important; + z-index: 9999 !important; +} + +/* Parent container for tooltips */ +.tooltip-container { + position: relative; + overflow: visible !important; +} + @keyframes pulse { 0% { background-color: rgb(255 0 0 / 0.1); @@ -123,27 +135,76 @@ export default function DocumentManager() { } }, []) + // Reference to the card content element + const cardContentRef = useRef(null); + // Add tooltip position adjustment based on mouse position useEffect(() => { if (!docs) return; // Function to handle mouse movement const handleMouseMove = (event: MouseEvent) => { - const cardContent = document.querySelector('.flex-1.relative.p-0'); + const cardContent = cardContentRef.current; if (!cardContent) return; const cardRect = cardContent.getBoundingClientRect(); const cardMiddleY = cardRect.top + cardRect.height / 2; + + // Get table element to check its height + const tableElement = cardContent.querySelector('table'); + const tableHeight = tableElement?.offsetHeight || 0; + + // Determine if table is small (less than 3 rows approximately) + const isSmallTable = tableHeight < 150; // Get all visible tooltips const visibleTooltips = document.querySelectorAll('.group:hover > div[class*="invisible group-hover:visible absolute"]'); visibleTooltips.forEach(tooltip => { - // If mouse is in the bottom half of the card, show tooltip above - if (event.clientY > cardMiddleY) { - tooltip.classList.add('tooltip-top'); + // Get the parent element that triggered the tooltip + const triggerElement = tooltip.parentElement; + if (!triggerElement) return; + + const triggerRect = triggerElement.getBoundingClientRect(); + + // If table is small, use fixed positioning + if (isSmallTable) { + tooltip.classList.add('tooltip-fixed'); + + // Calculate position based on trigger element and mouse + const tooltipHeight = tooltip.offsetHeight; + const viewportHeight = window.innerHeight; + + // Check if tooltip would go off the bottom of the viewport + const wouldOverflowBottom = event.clientY + tooltipHeight > viewportHeight; + + if (wouldOverflowBottom) { + // Position above the trigger + tooltip.style.top = `${triggerRect.top - tooltipHeight - 5}px`; + tooltip.style.bottom = 'auto'; + } else { + // Position below the trigger + tooltip.style.top = `${triggerRect.bottom + 5}px`; + tooltip.style.bottom = 'auto'; + } + + // Horizontal positioning + tooltip.style.left = `${triggerRect.left}px`; + tooltip.style.maxWidth = '800px'; + } else { - tooltip.classList.remove('tooltip-top'); + // For normal sized tables, use the original logic + tooltip.classList.remove('tooltip-fixed'); + tooltip.style.top = ''; + tooltip.style.left = ''; + tooltip.style.bottom = ''; + + // If mouse is in the bottom half of the card, show tooltip above + if (event.clientY > cardMiddleY) { + tooltip.classList.add('tooltip-top'); + } else { + tooltip.classList.remove('tooltip-top'); + } } }); }; @@ -294,7 +355,7 @@ export default function DocumentManager() { - + {!docs && (
- +
{t('documentPanel.documentManager.columns.id')} @@ -326,7 +387,7 @@ export default function DocumentManager() { {showFileName ? ( <> -
+
{getDisplayFileName(doc, 35)}
@@ -337,7 +398,7 @@ export default function DocumentManager() {
{doc.id}
) : ( -
+
{doc.id}
@@ -348,7 +409,7 @@ export default function DocumentManager() { )} -
+
{doc.content_summary}