From af3c9f30dc465763f7731855d4aecaa8ce177f4f Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 26 Mar 2025 14:14:29 +0800 Subject: [PATCH] feat(PipelineStatusDialog): add responsive height adjustment with minimum height guarantee --- .../documents/PipelineStatusDialog.tsx | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx b/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx index 83ec369b..1d4074e8 100644 --- a/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx +++ b/lightrag_webui/src/components/documents/PipelineStatusDialog.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useRef } from 'react' +import { useState, useEffect, useRef, useCallback } from 'react' import { useTranslation } from 'react-i18next' import { toast } from 'sonner' import { X, AlignLeft, AlignCenter, AlignRight } from 'lucide-react' @@ -9,7 +9,6 @@ import { AlertDialogHeader, AlertDialogTitle, AlertDialogOverlay, - AlertDialogDescription } from '@/components/ui/AlertDialog' import Button from '@/components/ui/Button' import { getPipelineStatus, PipelineStatusResponse } from '@/api/lightrag' @@ -31,15 +30,44 @@ export default function PipelineStatusDialog({ const [status, setStatus] = useState(null) const [position, setPosition] = useState('center') const [isUserScrolled, setIsUserScrolled] = useState(false) + const [historyHeight, setHistoryHeight] = useState('20em') const historyRef = useRef(null) + const resizeObserverRef = useRef(null) + + // Calculate history height based on window height + const updateHistoryHeight = useCallback(() => { + const minHeight = 7.5 // 5 lines * 1.5em line height + const windowHeight = window.innerHeight + const pixelsPerEm = parseFloat(getComputedStyle(document.documentElement).fontSize) + const maxHeightInEm = Math.max(Math.floor((windowHeight * 0.4) / pixelsPerEm), minHeight) + setHistoryHeight(`${maxHeightInEm}em`) + }, []) // Reset position when dialog opens useEffect(() => { if (open) { setPosition('center') setIsUserScrolled(false) + updateHistoryHeight() } - }, [open]) + }, [open, updateHistoryHeight]) + + // Setup resize observer + useEffect(() => { + if (!open) return + + resizeObserverRef.current = new ResizeObserver((entries) => { + if (entries[0]) { + updateHistoryHeight() + } + }) + + resizeObserverRef.current.observe(document.body) + + return () => { + resizeObserverRef.current?.disconnect() + } + }, [open, updateHistoryHeight]) // Handle scroll position useEffect(() => { @@ -145,10 +173,6 @@ export default function PipelineStatusDialog({ - - - {t('documentPanel.pipelineStatus.description')} - {/* Status Content */}
@@ -187,7 +211,8 @@ export default function PipelineStatusDialog({
{status?.history_messages?.map((msg, idx) => (
{msg}