2025-03-26 14:02:20 +08:00
|
|
|
|
import { useState, useEffect, useCallback, useRef } from 'react'
|
2025-03-08 09:26:21 +00:00
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2025-03-19 21:36:30 +08:00
|
|
|
|
import { useSettingsStore } from '@/stores/settings'
|
2025-02-15 23:22:37 +08:00
|
|
|
|
import Button from '@/components/ui/Button'
|
2025-03-26 13:11:53 +08:00
|
|
|
|
import { cn } from '@/lib/utils'
|
2025-02-15 23:22:37 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Table,
|
|
|
|
|
|
TableBody,
|
|
|
|
|
|
TableCell,
|
|
|
|
|
|
TableHead,
|
|
|
|
|
|
TableHeader,
|
|
|
|
|
|
TableRow
|
|
|
|
|
|
} from '@/components/ui/Table'
|
|
|
|
|
|
import { Card, CardHeader, CardTitle, CardContent, CardDescription } from '@/components/ui/Card'
|
|
|
|
|
|
import EmptyCard from '@/components/ui/EmptyCard'
|
2025-02-16 21:43:14 +08:00
|
|
|
|
import UploadDocumentsDialog from '@/components/documents/UploadDocumentsDialog'
|
|
|
|
|
|
import ClearDocumentsDialog from '@/components/documents/ClearDocumentsDialog'
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-02-17 01:05:31 +08:00
|
|
|
|
import { getDocuments, scanNewDocuments, DocsStatusesResponse } from '@/api/lightrag'
|
2025-02-15 23:22:37 +08:00
|
|
|
|
import { errorMessage } from '@/lib/utils'
|
|
|
|
|
|
import { toast } from 'sonner'
|
2025-02-17 01:05:31 +08:00
|
|
|
|
import { useBackendState } from '@/stores/state'
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
import { RefreshCwIcon, ActivityIcon, ArrowUpIcon, ArrowDownIcon } from 'lucide-react'
|
2025-03-25 22:42:46 +08:00
|
|
|
|
import { DocStatusResponse } from '@/api/lightrag'
|
2025-03-26 12:05:54 +08:00
|
|
|
|
import PipelineStatusDialog from '@/components/documents/PipelineStatusDialog'
|
2025-03-25 22:42:46 +08:00
|
|
|
|
|
|
|
|
|
|
const getDisplayFileName = (doc: DocStatusResponse, maxLength: number = 20): string => {
|
|
|
|
|
|
// Check if file_path exists and is a non-empty string
|
|
|
|
|
|
if (!doc.file_path || typeof doc.file_path !== 'string' || doc.file_path.trim() === '') {
|
|
|
|
|
|
return doc.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try to extract filename from path
|
|
|
|
|
|
const parts = doc.file_path.split('/');
|
|
|
|
|
|
const fileName = parts[parts.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure extracted filename is valid
|
|
|
|
|
|
if (!fileName || fileName.trim() === '') {
|
|
|
|
|
|
return doc.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If filename is longer than maxLength, truncate it and add ellipsis
|
2025-03-25 22:44:53 +08:00
|
|
|
|
return fileName.length > maxLength
|
|
|
|
|
|
? fileName.slice(0, maxLength) + '...'
|
2025-03-25 22:42:46 +08:00
|
|
|
|
: fileName;
|
|
|
|
|
|
};
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-03-26 13:11:53 +08:00
|
|
|
|
const pulseStyle = `
|
2025-03-27 16:50:27 +08:00
|
|
|
|
/* Tooltip styles */
|
2025-03-27 08:37:09 +08:00
|
|
|
|
.tooltip-container {
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
overflow: visible !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
.tooltip {
|
|
|
|
|
|
position: fixed; /* Use fixed positioning to escape overflow constraints */
|
|
|
|
|
|
z-index: 9999; /* Ensure tooltip appears above all other elements */
|
|
|
|
|
|
max-width: 600px;
|
|
|
|
|
|
white-space: normal;
|
|
|
|
|
|
border-radius: 0.375rem;
|
|
|
|
|
|
padding: 0.5rem 0.75rem;
|
|
|
|
|
|
background-color: rgba(0, 0, 0, 0.95);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
pointer-events: none; /* Prevent tooltip from interfering with mouse events */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.dark .tooltip {
|
|
|
|
|
|
background-color: rgba(255, 255, 255, 0.95);
|
|
|
|
|
|
color: black;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Position tooltip helper class */
|
|
|
|
|
|
.tooltip-helper {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
visibility: hidden;
|
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-26 13:11:53 +08:00
|
|
|
|
@keyframes pulse {
|
|
|
|
|
|
0% {
|
|
|
|
|
|
background-color: rgb(255 0 0 / 0.1);
|
|
|
|
|
|
border-color: rgb(255 0 0 / 0.2);
|
|
|
|
|
|
}
|
|
|
|
|
|
50% {
|
|
|
|
|
|
background-color: rgb(255 0 0 / 0.2);
|
|
|
|
|
|
border-color: rgb(255 0 0 / 0.4);
|
|
|
|
|
|
}
|
|
|
|
|
|
100% {
|
|
|
|
|
|
background-color: rgb(255 0 0 / 0.1);
|
|
|
|
|
|
border-color: rgb(255 0 0 / 0.2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.dark .pipeline-busy {
|
|
|
|
|
|
animation: dark-pulse 2s infinite;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes dark-pulse {
|
|
|
|
|
|
0% {
|
|
|
|
|
|
background-color: rgb(255 0 0 / 0.2);
|
|
|
|
|
|
border-color: rgb(255 0 0 / 0.4);
|
|
|
|
|
|
}
|
|
|
|
|
|
50% {
|
|
|
|
|
|
background-color: rgb(255 0 0 / 0.3);
|
|
|
|
|
|
border-color: rgb(255 0 0 / 0.6);
|
|
|
|
|
|
}
|
|
|
|
|
|
100% {
|
|
|
|
|
|
background-color: rgb(255 0 0 / 0.2);
|
|
|
|
|
|
border-color: rgb(255 0 0 / 0.4);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pipeline-busy {
|
|
|
|
|
|
animation: pulse 2s infinite;
|
|
|
|
|
|
border: 1px solid;
|
|
|
|
|
|
}
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Type definitions for sort field and direction
|
|
|
|
|
|
type SortField = 'created_at' | 'updated_at' | 'id';
|
|
|
|
|
|
type SortDirection = 'asc' | 'desc';
|
|
|
|
|
|
|
2025-02-15 23:22:37 +08:00
|
|
|
|
export default function DocumentManager() {
|
2025-03-26 12:05:54 +08:00
|
|
|
|
const [showPipelineStatus, setShowPipelineStatus] = useState(false)
|
2025-03-08 09:26:21 +00:00
|
|
|
|
const { t } = useTranslation()
|
2025-02-17 01:05:31 +08:00
|
|
|
|
const health = useBackendState.use.health()
|
2025-03-26 13:11:53 +08:00
|
|
|
|
const pipelineBusy = useBackendState.use.pipelineBusy()
|
2025-02-17 01:05:31 +08:00
|
|
|
|
const [docs, setDocs] = useState<DocsStatusesResponse | null>(null)
|
2025-03-19 21:36:30 +08:00
|
|
|
|
const currentTab = useSettingsStore.use.currentTab()
|
2025-03-25 22:42:46 +08:00
|
|
|
|
const showFileName = useSettingsStore.use.showFileName()
|
|
|
|
|
|
const setShowFileName = useSettingsStore.use.setShowFileName()
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Sort state
|
|
|
|
|
|
const [sortField, setSortField] = useState<SortField>('updated_at')
|
|
|
|
|
|
const [sortDirection, setSortDirection] = useState<SortDirection>('desc')
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Handle sort column click
|
|
|
|
|
|
const handleSort = (field: SortField) => {
|
|
|
|
|
|
if (sortField === field) {
|
|
|
|
|
|
// Toggle sort direction if clicking the same field
|
|
|
|
|
|
setSortDirection(prev => prev === 'asc' ? 'desc' : 'asc')
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Set new sort field with default desc direction
|
|
|
|
|
|
setSortField(field)
|
|
|
|
|
|
setSortDirection('desc')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Sort documents based on current sort field and direction
|
|
|
|
|
|
const sortDocuments = (documents: DocStatusResponse[]) => {
|
|
|
|
|
|
return [...documents].sort((a, b) => {
|
|
|
|
|
|
let valueA, valueB;
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Special handling for ID field based on showFileName setting
|
|
|
|
|
|
if (sortField === 'id' && showFileName) {
|
|
|
|
|
|
valueA = getDisplayFileName(a);
|
|
|
|
|
|
valueB = getDisplayFileName(b);
|
|
|
|
|
|
} else if (sortField === 'id') {
|
|
|
|
|
|
valueA = a.id;
|
|
|
|
|
|
valueB = b.id;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Date fields
|
|
|
|
|
|
valueA = new Date(a[sortField]).getTime();
|
|
|
|
|
|
valueB = new Date(b[sortField]).getTime();
|
|
|
|
|
|
}
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Apply sort direction
|
|
|
|
|
|
const sortMultiplier = sortDirection === 'asc' ? 1 : -1;
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Compare values
|
|
|
|
|
|
if (typeof valueA === 'string' && typeof valueB === 'string') {
|
|
|
|
|
|
return sortMultiplier * valueA.localeCompare(valueB);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return sortMultiplier * (valueA > valueB ? 1 : valueA < valueB ? -1 : 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-03-26 14:02:20 +08:00
|
|
|
|
// Store previous status counts
|
|
|
|
|
|
const prevStatusCounts = useRef({
|
|
|
|
|
|
processed: 0,
|
|
|
|
|
|
processing: 0,
|
|
|
|
|
|
pending: 0,
|
|
|
|
|
|
failed: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-03-26 13:11:53 +08:00
|
|
|
|
// Add pulse style to document
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const style = document.createElement('style')
|
|
|
|
|
|
style.textContent = pulseStyle
|
|
|
|
|
|
document.head.appendChild(style)
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
document.head.removeChild(style)
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
2025-03-27 08:37:09 +08:00
|
|
|
|
// Reference to the card content element
|
|
|
|
|
|
const cardContentRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Add tooltip position adjustment for fixed positioning
|
2025-03-27 02:21:02 +08:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (!docs) return;
|
2025-03-27 02:21:25 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Function to position tooltips
|
|
|
|
|
|
const positionTooltips = () => {
|
|
|
|
|
|
// Get all tooltip containers
|
|
|
|
|
|
const containers = document.querySelectorAll<HTMLElement>('.tooltip-container');
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
containers.forEach(container => {
|
|
|
|
|
|
const tooltip = container.querySelector<HTMLElement>('.tooltip');
|
|
|
|
|
|
if (!tooltip) return;
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Only position visible tooltips
|
|
|
|
|
|
if (getComputedStyle(tooltip).visibility === 'hidden') return;
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Get container position
|
|
|
|
|
|
const rect = container.getBoundingClientRect();
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Position tooltip above the container
|
|
|
|
|
|
tooltip.style.left = `${rect.left}px`;
|
|
|
|
|
|
tooltip.style.top = `${rect.top - 5}px`;
|
|
|
|
|
|
tooltip.style.transform = 'translateY(-100%)';
|
2025-03-27 02:21:02 +08:00
|
|
|
|
});
|
|
|
|
|
|
};
|
2025-03-27 02:21:25 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Set up event listeners
|
|
|
|
|
|
const handleMouseOver = (e: MouseEvent) => {
|
|
|
|
|
|
// Check if target or its parent is a tooltip container
|
|
|
|
|
|
const target = e.target as HTMLElement;
|
|
|
|
|
|
const container = target.closest('.tooltip-container');
|
|
|
|
|
|
if (!container) return;
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
// Small delay to ensure tooltip is visible before positioning
|
|
|
|
|
|
setTimeout(positionTooltips, 10);
|
|
|
|
|
|
};
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 16:50:27 +08:00
|
|
|
|
document.addEventListener('mouseover', handleMouseOver);
|
2025-03-27 16:55:15 +08:00
|
|
|
|
|
2025-03-27 02:21:02 +08:00
|
|
|
|
return () => {
|
2025-03-27 16:50:27 +08:00
|
|
|
|
document.removeEventListener('mouseover', handleMouseOver);
|
2025-03-27 02:21:02 +08:00
|
|
|
|
};
|
|
|
|
|
|
}, [docs]);
|
|
|
|
|
|
|
2025-02-15 23:22:37 +08:00
|
|
|
|
const fetchDocuments = useCallback(async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const docs = await getDocuments()
|
2025-03-26 17:30:06 +08:00
|
|
|
|
|
2025-03-26 14:02:20 +08:00
|
|
|
|
// Get new status counts (treat null as all zeros)
|
|
|
|
|
|
const newStatusCounts = {
|
|
|
|
|
|
processed: docs?.statuses?.processed?.length || 0,
|
|
|
|
|
|
processing: docs?.statuses?.processing?.length || 0,
|
|
|
|
|
|
pending: docs?.statuses?.pending?.length || 0,
|
|
|
|
|
|
failed: docs?.statuses?.failed?.length || 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check if any status count has changed
|
|
|
|
|
|
const hasStatusCountChange = (Object.keys(newStatusCounts) as Array<keyof typeof newStatusCounts>).some(
|
|
|
|
|
|
status => newStatusCounts[status] !== prevStatusCounts.current[status]
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Trigger health check if changes detected
|
|
|
|
|
|
if (hasStatusCountChange) {
|
|
|
|
|
|
useBackendState.getState().check()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update previous status counts
|
|
|
|
|
|
prevStatusCounts.current = newStatusCounts
|
|
|
|
|
|
|
|
|
|
|
|
// Update docs state
|
2025-02-17 01:05:31 +08:00
|
|
|
|
if (docs && docs.statuses) {
|
2025-02-18 00:30:51 +08:00
|
|
|
|
const numDocuments = Object.values(docs.statuses).reduce(
|
|
|
|
|
|
(acc, status) => acc + status.length,
|
|
|
|
|
|
0
|
|
|
|
|
|
)
|
|
|
|
|
|
if (numDocuments > 0) {
|
|
|
|
|
|
setDocs(docs)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setDocs(null)
|
|
|
|
|
|
}
|
2025-02-17 01:05:31 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
setDocs(null)
|
|
|
|
|
|
}
|
2025-02-15 23:22:37 +08:00
|
|
|
|
} catch (err) {
|
2025-03-08 09:26:21 +00:00
|
|
|
|
toast.error(t('documentPanel.documentManager.errors.loadFailed', { error: errorMessage(err) }))
|
2025-02-15 23:22:37 +08:00
|
|
|
|
}
|
2025-03-13 15:15:42 +08:00
|
|
|
|
}, [setDocs, t])
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-03-19 21:36:30 +08:00
|
|
|
|
// Fetch documents when the tab becomes visible
|
2025-02-15 23:22:37 +08:00
|
|
|
|
useEffect(() => {
|
2025-03-19 21:36:30 +08:00
|
|
|
|
if (currentTab === 'documents') {
|
2025-03-13 19:50:37 +08:00
|
|
|
|
fetchDocuments()
|
|
|
|
|
|
}
|
2025-03-19 21:36:30 +08:00
|
|
|
|
}, [currentTab, fetchDocuments])
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
|
|
|
|
|
const scanDocuments = useCallback(async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { status } = await scanNewDocuments()
|
|
|
|
|
|
toast.message(status)
|
|
|
|
|
|
} catch (err) {
|
2025-03-08 09:26:21 +00:00
|
|
|
|
toast.error(t('documentPanel.documentManager.errors.scanFailed', { error: errorMessage(err) }))
|
2025-02-15 23:22:37 +08:00
|
|
|
|
}
|
2025-03-13 15:15:42 +08:00
|
|
|
|
}, [t])
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-03-19 21:36:30 +08:00
|
|
|
|
// Set up polling when the documents tab is active and health is good
|
2025-02-17 01:05:31 +08:00
|
|
|
|
useEffect(() => {
|
2025-03-19 21:36:30 +08:00
|
|
|
|
if (currentTab !== 'documents' || !health) {
|
2025-03-13 19:50:37 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-03-14 00:03:45 +08:00
|
|
|
|
|
2025-02-17 01:05:31 +08:00
|
|
|
|
const interval = setInterval(async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await fetchDocuments()
|
|
|
|
|
|
} catch (err) {
|
2025-03-08 09:26:21 +00:00
|
|
|
|
toast.error(t('documentPanel.documentManager.errors.scanProgressFailed', { error: errorMessage(err) }))
|
2025-02-17 01:05:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}, 5000)
|
2025-03-14 00:03:45 +08:00
|
|
|
|
|
2025-02-17 01:05:31 +08:00
|
|
|
|
return () => clearInterval(interval)
|
2025-03-19 21:36:30 +08:00
|
|
|
|
}, [health, fetchDocuments, t, currentTab])
|
2025-02-15 23:22:37 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
// Add dependency on sort state to re-render when sort changes
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
// This effect ensures the component re-renders when sort state changes
|
|
|
|
|
|
}, [sortField, sortDirection]);
|
|
|
|
|
|
|
2025-02-15 23:22:37 +08:00
|
|
|
|
return (
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<Card className="!rounded-none !overflow-hidden flex flex-col h-full min-h-0">
|
|
|
|
|
|
<CardHeader className="py-2 px-6">
|
2025-03-08 09:26:21 +00:00
|
|
|
|
<CardTitle className="text-lg">{t('documentPanel.documentManager.title')}</CardTitle>
|
2025-02-15 23:22:37 +08:00
|
|
|
|
</CardHeader>
|
2025-03-27 11:11:59 +08:00
|
|
|
|
<CardContent className="flex-1 flex flex-col min-h-0 overflow-auto">
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<div className="flex gap-2 mb-2">
|
2025-03-26 12:05:54 +08:00
|
|
|
|
<div className="flex gap-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
onClick={scanDocuments}
|
|
|
|
|
|
side="bottom"
|
|
|
|
|
|
tooltip={t('documentPanel.documentManager.scanTooltip')}
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
>
|
|
|
|
|
|
<RefreshCwIcon /> {t('documentPanel.documentManager.scanButton')}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
onClick={() => setShowPipelineStatus(true)}
|
|
|
|
|
|
side="bottom"
|
2025-03-26 12:50:33 +08:00
|
|
|
|
tooltip={t('documentPanel.documentManager.pipelineStatusTooltip')}
|
2025-03-26 12:05:54 +08:00
|
|
|
|
size="sm"
|
2025-03-26 13:11:53 +08:00
|
|
|
|
className={cn(
|
|
|
|
|
|
pipelineBusy && 'pipeline-busy'
|
|
|
|
|
|
)}
|
2025-03-26 12:05:54 +08:00
|
|
|
|
>
|
2025-03-26 12:50:33 +08:00
|
|
|
|
<ActivityIcon /> {t('documentPanel.documentManager.pipelineStatusButton')}
|
2025-03-26 12:05:54 +08:00
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
2025-02-15 23:22:37 +08:00
|
|
|
|
<div className="flex-1" />
|
|
|
|
|
|
<ClearDocumentsDialog />
|
|
|
|
|
|
<UploadDocumentsDialog />
|
2025-03-26 12:05:54 +08:00
|
|
|
|
<PipelineStatusDialog
|
|
|
|
|
|
open={showPipelineStatus}
|
|
|
|
|
|
onOpenChange={setShowPipelineStatus}
|
|
|
|
|
|
/>
|
2025-02-15 23:22:37 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<Card className="flex-1 flex flex-col border rounded-md min-h-0 mb-0">
|
|
|
|
|
|
<CardHeader className="flex-none py-2 px-4">
|
2025-03-25 22:42:46 +08:00
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
|
|
<CardTitle>{t('documentPanel.documentManager.uploadedTitle')}</CardTitle>
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<span className="text-sm text-gray-500">{t('documentPanel.documentManager.fileNameLabel')}</span>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
onClick={() => setShowFileName(!showFileName)}
|
|
|
|
|
|
className="border-gray-200 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-800"
|
|
|
|
|
|
>
|
2025-03-25 22:44:53 +08:00
|
|
|
|
{showFileName
|
2025-03-25 22:42:46 +08:00
|
|
|
|
? t('documentPanel.documentManager.hideButton')
|
|
|
|
|
|
: t('documentPanel.documentManager.showButton')
|
|
|
|
|
|
}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-03-27 00:11:46 +08:00
|
|
|
|
<CardDescription aria-hidden="true" className="hidden">{t('documentPanel.documentManager.uploadedDescription')}</CardDescription>
|
2025-02-15 23:22:37 +08:00
|
|
|
|
</CardHeader>
|
|
|
|
|
|
|
2025-03-27 08:37:09 +08:00
|
|
|
|
<CardContent className="flex-1 relative p-0" ref={cardContentRef}>
|
2025-02-17 01:05:31 +08:00
|
|
|
|
{!docs && (
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<div className="absolute inset-0 p-0">
|
|
|
|
|
|
<EmptyCard
|
|
|
|
|
|
title={t('documentPanel.documentManager.emptyTitle')}
|
|
|
|
|
|
description={t('documentPanel.documentManager.emptyDescription')}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-02-15 23:22:37 +08:00
|
|
|
|
)}
|
2025-02-17 01:05:31 +08:00
|
|
|
|
{docs && (
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<div className="absolute inset-0 flex flex-col p-0">
|
2025-03-27 16:50:27 +08:00
|
|
|
|
<div className="w-full h-full flex flex-col border border-gray-200 dark:border-gray-700 overflow-hidden">
|
2025-03-27 11:11:59 +08:00
|
|
|
|
<Table className="w-full">
|
|
|
|
|
|
<TableHeader className="sticky top-0 bg-background z-10 shadow-sm">
|
|
|
|
|
|
<TableRow className="border-b bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/75 shadow-[inset_0_-1px_0_rgba(0,0,0,0.1)]">
|
2025-03-27 13:38:36 +08:00
|
|
|
|
<TableHead
|
2025-03-27 13:37:50 +08:00
|
|
|
|
onClick={() => handleSort('id')}
|
2025-03-27 15:38:57 +08:00
|
|
|
|
className="cursor-pointer hover:bg-gray-200 dark:hover:bg-gray-800 select-none"
|
2025-03-27 13:37:50 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
{t('documentPanel.documentManager.columns.id')}
|
|
|
|
|
|
{sortField === 'id' && (
|
|
|
|
|
|
<span className="ml-1">
|
|
|
|
|
|
{sortDirection === 'asc' ? <ArrowUpIcon size={14} /> : <ArrowDownIcon size={14} />}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</TableHead>
|
2025-03-27 11:11:59 +08:00
|
|
|
|
<TableHead>{t('documentPanel.documentManager.columns.summary')}</TableHead>
|
|
|
|
|
|
<TableHead>{t('documentPanel.documentManager.columns.status')}</TableHead>
|
|
|
|
|
|
<TableHead>{t('documentPanel.documentManager.columns.length')}</TableHead>
|
|
|
|
|
|
<TableHead>{t('documentPanel.documentManager.columns.chunks')}</TableHead>
|
2025-03-27 13:38:36 +08:00
|
|
|
|
<TableHead
|
2025-03-27 13:37:50 +08:00
|
|
|
|
onClick={() => handleSort('created_at')}
|
2025-03-27 15:38:57 +08:00
|
|
|
|
className="cursor-pointer hover:bg-gray-200 dark:hover:bg-gray-800 select-none"
|
2025-03-27 13:37:50 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
{t('documentPanel.documentManager.columns.created')}
|
|
|
|
|
|
{sortField === 'created_at' && (
|
|
|
|
|
|
<span className="ml-1">
|
|
|
|
|
|
{sortDirection === 'asc' ? <ArrowUpIcon size={14} /> : <ArrowDownIcon size={14} />}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</TableHead>
|
2025-03-27 13:38:36 +08:00
|
|
|
|
<TableHead
|
2025-03-27 13:37:50 +08:00
|
|
|
|
onClick={() => handleSort('updated_at')}
|
2025-03-27 15:38:57 +08:00
|
|
|
|
className="cursor-pointer hover:bg-gray-200 dark:hover:bg-gray-800 select-none"
|
2025-03-27 13:37:50 +08:00
|
|
|
|
>
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
|
|
{t('documentPanel.documentManager.columns.updated')}
|
|
|
|
|
|
{sortField === 'updated_at' && (
|
|
|
|
|
|
<span className="ml-1">
|
|
|
|
|
|
{sortDirection === 'asc' ? <ArrowUpIcon size={14} /> : <ArrowDownIcon size={14} />}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</TableHead>
|
2025-03-27 11:11:59 +08:00
|
|
|
|
</TableRow>
|
|
|
|
|
|
</TableHeader>
|
|
|
|
|
|
<TableBody className="text-sm overflow-auto">
|
2025-03-27 13:37:50 +08:00
|
|
|
|
{Object.entries(docs.statuses).flatMap(([status, documents]) => {
|
|
|
|
|
|
// Apply sorting to documents
|
|
|
|
|
|
const sortedDocuments = sortDocuments(documents);
|
2025-03-27 13:38:36 +08:00
|
|
|
|
|
2025-03-27 13:37:50 +08:00
|
|
|
|
return sortedDocuments.map(doc => (
|
2025-03-27 11:11:59 +08:00
|
|
|
|
<TableRow key={doc.id}>
|
|
|
|
|
|
<TableCell className="truncate font-mono overflow-visible max-w-[250px]">
|
|
|
|
|
|
{showFileName ? (
|
|
|
|
|
|
<>
|
2025-03-27 08:37:09 +08:00
|
|
|
|
<div className="group relative overflow-visible tooltip-container">
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<div className="truncate">
|
2025-03-27 11:11:59 +08:00
|
|
|
|
{getDisplayFileName(doc, 30)}
|
2025-03-27 02:21:02 +08:00
|
|
|
|
</div>
|
2025-03-27 16:50:27 +08:00
|
|
|
|
<div className="invisible group-hover:visible tooltip">
|
2025-03-27 02:21:02 +08:00
|
|
|
|
{doc.file_path}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-03-27 11:11:59 +08:00
|
|
|
|
<div className="text-xs text-gray-500">{doc.id}</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
2025-03-27 08:37:09 +08:00
|
|
|
|
<div className="group relative overflow-visible tooltip-container">
|
2025-03-27 02:21:02 +08:00
|
|
|
|
<div className="truncate">
|
2025-03-27 11:11:59 +08:00
|
|
|
|
{doc.id}
|
2025-03-27 02:21:02 +08:00
|
|
|
|
</div>
|
2025-03-27 16:50:27 +08:00
|
|
|
|
<div className="invisible group-hover:visible tooltip">
|
2025-03-27 11:11:59 +08:00
|
|
|
|
{doc.file_path}
|
2025-03-27 02:21:02 +08:00
|
|
|
|
</div>
|
2025-03-25 22:42:46 +08:00
|
|
|
|
</div>
|
2025-03-27 11:11:59 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
<TableCell className="max-w-xs min-w-45 truncate overflow-visible">
|
|
|
|
|
|
<div className="group relative overflow-visible tooltip-container">
|
|
|
|
|
|
<div className="truncate">
|
|
|
|
|
|
{doc.content_summary}
|
|
|
|
|
|
</div>
|
2025-03-27 16:50:27 +08:00
|
|
|
|
<div className="invisible group-hover:visible tooltip">
|
2025-03-27 11:11:59 +08:00
|
|
|
|
{doc.content_summary}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
<TableCell>
|
|
|
|
|
|
{status === 'processed' && (
|
|
|
|
|
|
<span className="text-green-600">{t('documentPanel.documentManager.status.completed')}</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{status === 'processing' && (
|
|
|
|
|
|
<span className="text-blue-600">{t('documentPanel.documentManager.status.processing')}</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{status === 'pending' && <span className="text-yellow-600">{t('documentPanel.documentManager.status.pending')}</span>}
|
|
|
|
|
|
{status === 'failed' && <span className="text-red-600">{t('documentPanel.documentManager.status.failed')}</span>}
|
|
|
|
|
|
{doc.error && (
|
|
|
|
|
|
<span className="ml-2 text-red-500" title={doc.error}>
|
|
|
|
|
|
⚠️
|
|
|
|
|
|
</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
<TableCell>{doc.content_length ?? '-'}</TableCell>
|
|
|
|
|
|
<TableCell>{doc.chunks_count ?? '-'}</TableCell>
|
|
|
|
|
|
<TableCell className="truncate">
|
|
|
|
|
|
{new Date(doc.created_at).toLocaleString()}
|
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
<TableCell className="truncate">
|
|
|
|
|
|
{new Date(doc.updated_at).toLocaleString()}
|
|
|
|
|
|
</TableCell>
|
|
|
|
|
|
</TableRow>
|
2025-03-27 13:37:50 +08:00
|
|
|
|
));
|
|
|
|
|
|
})}
|
2025-03-27 11:11:59 +08:00
|
|
|
|
</TableBody>
|
|
|
|
|
|
</Table>
|
2025-03-27 02:21:02 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-02-15 23:22:37 +08:00
|
|
|
|
)}
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</CardContent>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|