@@ -38,6 +38,21 @@ import PipelineStatusDialog from '@/components/documents/PipelineStatusDialog'
3838
3939type StatusFilter = DocStatus | 'all' ;
4040
41+ // Utility functions defined outside component for better performance and to avoid dependency issues
42+ const getCountValue = ( counts : Record < string , number > , ...keys : string [ ] ) : number => {
43+ for ( const key of keys ) {
44+ const value = counts [ key ]
45+ if ( typeof value === 'number' ) {
46+ return value
47+ }
48+ }
49+ return 0
50+ }
51+
52+ const hasActiveDocumentsStatus = ( counts : Record < string , number > ) : boolean =>
53+ getCountValue ( counts , 'PROCESSING' , 'processing' ) > 0 ||
54+ getCountValue ( counts , 'PENDING' , 'pending' ) > 0 ||
55+ getCountValue ( counts , 'PREPROCESSED' , 'preprocessed' , 'multimodal_processed' ) > 0
4156
4257const getDisplayFileName = ( doc : DocStatusResponse , maxLength : number = 20 ) : string => {
4358 // Check if file_path exists and is a non-empty string
@@ -242,6 +257,7 @@ export default function DocumentManager() {
242257 const [ pageByStatus , setPageByStatus ] = useState < Record < StatusFilter , number > > ( {
243258 all : 1 ,
244259 processed : 1 ,
260+ multimodal_processed : 1 ,
245261 processing : 1 ,
246262 pending : 1 ,
247263 failed : 1 ,
@@ -308,6 +324,7 @@ export default function DocumentManager() {
308324 setPageByStatus ( {
309325 all : 1 ,
310326 processed : 1 ,
327+ 'multimodal_processed' : 1 ,
311328 processing : 1 ,
312329 pending : 1 ,
313330 failed : 1 ,
@@ -452,9 +469,19 @@ export default function DocumentManager() {
452469 return counts ;
453470 } , [ docs ] ) ;
454471
472+ const processedCount = getCountValue ( statusCounts , 'PROCESSED' , 'processed' ) || documentCounts . processed || 0 ;
473+ const preprocessedCount =
474+ getCountValue ( statusCounts , 'PREPROCESSED' , 'preprocessed' , 'multimodal_processed' ) ||
475+ documentCounts . multimodal_processed ||
476+ 0 ;
477+ const processingCount = getCountValue ( statusCounts , 'PROCESSING' , 'processing' ) || documentCounts . processing || 0 ;
478+ const pendingCount = getCountValue ( statusCounts , 'PENDING' , 'pending' ) || documentCounts . pending || 0 ;
479+ const failedCount = getCountValue ( statusCounts , 'FAILED' , 'failed' ) || documentCounts . failed || 0 ;
480+
455481 // Store previous status counts
456482 const prevStatusCounts = useRef ( {
457483 processed : 0 ,
484+ multimodal_processed : 0 ,
458485 processing : 0 ,
459486 pending : 0 ,
460487 failed : 0
@@ -545,6 +572,7 @@ export default function DocumentManager() {
545572 const legacyDocs : DocsStatusesResponse = {
546573 statuses : {
547574 processed : response . documents . filter ( ( doc : DocStatusResponse ) => doc . status === 'processed' ) ,
575+ multimodal_processed : response . documents . filter ( ( doc : DocStatusResponse ) => doc . status === 'multimodal_processed' ) ,
548576 processing : response . documents . filter ( ( doc : DocStatusResponse ) => doc . status === 'processing' ) ,
549577 pending : response . documents . filter ( ( doc : DocStatusResponse ) => doc . status === 'pending' ) ,
550578 failed : response . documents . filter ( ( doc : DocStatusResponse ) => doc . status === 'failed' )
@@ -827,7 +855,7 @@ export default function DocumentManager() {
827855 setTimeout ( ( ) => {
828856 if ( isMountedRef . current && currentTab === 'documents' && health ) {
829857 // Restore intelligent polling interval based on document status
830- const hasActiveDocuments = ( statusCounts . processing || 0 ) > 0 || ( statusCounts . pending || 0 ) > 0 ;
858+ const hasActiveDocuments = hasActiveDocumentsStatus ( statusCounts ) ;
831859 const normalInterval = hasActiveDocuments ? 5000 : 30000 ;
832860 startPollingInterval ( normalInterval ) ;
833861 }
@@ -863,7 +891,7 @@ export default function DocumentManager() {
863891 setTimeout ( ( ) => {
864892 if ( isMountedRef . current && currentTab === 'documents' && health ) {
865893 // Restore intelligent polling interval based on document status
866- const hasActiveDocuments = ( statusCounts . processing || 0 ) > 0 || ( statusCounts . pending || 0 ) > 0 ;
894+ const hasActiveDocuments = hasActiveDocumentsStatus ( statusCounts ) ;
867895 const normalInterval = hasActiveDocuments ? 5000 : 30000 ;
868896 startPollingInterval ( normalInterval ) ;
869897 }
@@ -887,6 +915,7 @@ export default function DocumentManager() {
887915 setPageByStatus ( {
888916 all : 1 ,
889917 processed : 1 ,
918+ multimodal_processed : 1 ,
890919 processing : 1 ,
891920 pending : 1 ,
892921 failed : 1 ,
@@ -927,6 +956,7 @@ export default function DocumentManager() {
927956 const legacyDocs : DocsStatusesResponse = {
928957 statuses : {
929958 processed : response . documents . filter ( doc => doc . status === 'processed' ) ,
959+ multimodal_processed : response . documents . filter ( doc => doc . status === 'multimodal_processed' ) ,
930960 processing : response . documents . filter ( doc => doc . status === 'processing' ) ,
931961 pending : response . documents . filter ( doc => doc . status === 'pending' ) ,
932962 failed : response . documents . filter ( doc => doc . status === 'failed' )
@@ -961,14 +991,21 @@ export default function DocumentManager() {
961991 handleIntelligentRefresh ( ) ;
962992
963993 // Reset polling timer after intelligent refresh
964- const hasActiveDocuments = ( statusCounts . processing || 0 ) > 0 || ( statusCounts . pending || 0 ) > 0 ;
994+ const hasActiveDocuments = hasActiveDocumentsStatus ( statusCounts ) ;
965995 const pollingInterval = hasActiveDocuments ? 5000 : 30000 ;
966996 startPollingInterval ( pollingInterval ) ;
967997 }
968998 }
969999 // Update the previous state
9701000 prevPipelineBusyRef . current = pipelineBusy ;
971- } , [ pipelineBusy , currentTab , health , handleIntelligentRefresh , statusCounts . processing , statusCounts . pending , startPollingInterval ] ) ;
1001+ } , [
1002+ pipelineBusy ,
1003+ currentTab ,
1004+ health ,
1005+ handleIntelligentRefresh ,
1006+ statusCounts ,
1007+ startPollingInterval
1008+ ] ) ;
9721009
9731010 // Set up intelligent polling with dynamic interval based on document status
9741011 useEffect ( ( ) => {
@@ -978,7 +1015,7 @@ export default function DocumentManager() {
9781015 }
9791016
9801017 // Determine polling interval based on document status
981- const hasActiveDocuments = ( statusCounts . processing || 0 ) > 0 || ( statusCounts . pending || 0 ) > 0 ;
1018+ const hasActiveDocuments = hasActiveDocumentsStatus ( statusCounts ) ;
9821019 const pollingInterval = hasActiveDocuments ? 5000 : 30000 ; // 5s if active, 30s if idle
9831020
9841021 startPollingInterval ( pollingInterval ) ;
@@ -995,6 +1032,7 @@ export default function DocumentManager() {
9951032 // Get new status counts
9961033 const newStatusCounts = {
9971034 processed : docs ?. statuses ?. processed ?. length || 0 ,
1035+ multimodal_processed : docs ?. statuses ?. multimodal_processed ?. length || 0 ,
9981036 processing : docs ?. statuses ?. processing ?. length || 0 ,
9991037 pending : docs ?. statuses ?. pending ?. length || 0 ,
10001038 failed : docs ?. statuses ?. failed ?. length || 0
@@ -1224,47 +1262,59 @@ export default function DocumentManager() {
12241262 onClick = { ( ) => handleStatusFilterChange ( 'processed' ) }
12251263 disabled = { isRefreshing }
12261264 className = { cn (
1227- ( statusCounts . PROCESSED || statusCounts . processed || documentCounts . processed ) > 0 ? 'text-green-600' : 'text-gray-500' ,
1265+ processedCount > 0 ? 'text-green-600' : 'text-gray-500' ,
12281266 statusFilter === 'processed' && 'bg-green-100 dark:bg-green-900/30 font-medium border border-green-400 dark:border-green-600 shadow-sm'
12291267 ) }
12301268 >
1231- { t ( 'documentPanel.documentManager.status.completed' ) } ({ statusCounts . PROCESSED || statusCounts . processed || 0 } )
1269+ { t ( 'documentPanel.documentManager.status.completed' ) } ({ processedCount } )
1270+ </ Button >
1271+ < Button
1272+ size = "sm"
1273+ variant = { statusFilter === 'multimodal_processed' ? 'secondary' : 'outline' }
1274+ onClick = { ( ) => handleStatusFilterChange ( 'multimodal_processed' ) }
1275+ disabled = { isRefreshing }
1276+ className = { cn (
1277+ preprocessedCount > 0 ? 'text-purple-600' : 'text-gray-500' ,
1278+ statusFilter === 'multimodal_processed' && 'bg-purple-100 dark:bg-purple-900/30 font-medium border border-purple-400 dark:border-purple-600 shadow-sm'
1279+ ) }
1280+ >
1281+ { t ( 'documentPanel.documentManager.status.preprocessed' ) } ({ preprocessedCount } )
12321282 </ Button >
12331283 < Button
12341284 size = "sm"
12351285 variant = { statusFilter === 'processing' ? 'secondary' : 'outline' }
12361286 onClick = { ( ) => handleStatusFilterChange ( 'processing' ) }
12371287 disabled = { isRefreshing }
12381288 className = { cn (
1239- ( statusCounts . PROCESSING || statusCounts . processing || documentCounts . processing ) > 0 ? 'text-blue-600' : 'text-gray-500' ,
1289+ processingCount > 0 ? 'text-blue-600' : 'text-gray-500' ,
12401290 statusFilter === 'processing' && 'bg-blue-100 dark:bg-blue-900/30 font-medium border border-blue-400 dark:border-blue-600 shadow-sm'
12411291 ) }
12421292 >
1243- { t ( 'documentPanel.documentManager.status.processing' ) } ({ statusCounts . PROCESSING || statusCounts . processing || 0 } )
1293+ { t ( 'documentPanel.documentManager.status.processing' ) } ({ processingCount } )
12441294 </ Button >
12451295 < Button
12461296 size = "sm"
12471297 variant = { statusFilter === 'pending' ? 'secondary' : 'outline' }
12481298 onClick = { ( ) => handleStatusFilterChange ( 'pending' ) }
12491299 disabled = { isRefreshing }
12501300 className = { cn (
1251- ( statusCounts . PENDING || statusCounts . pending || documentCounts . pending ) > 0 ? 'text-yellow-600' : 'text-gray-500' ,
1301+ pendingCount > 0 ? 'text-yellow-600' : 'text-gray-500' ,
12521302 statusFilter === 'pending' && 'bg-yellow-100 dark:bg-yellow-900/30 font-medium border border-yellow-400 dark:border-yellow-600 shadow-sm'
12531303 ) }
12541304 >
1255- { t ( 'documentPanel.documentManager.status.pending' ) } ({ statusCounts . PENDING || statusCounts . pending || 0 } )
1305+ { t ( 'documentPanel.documentManager.status.pending' ) } ({ pendingCount } )
12561306 </ Button >
12571307 < Button
12581308 size = "sm"
12591309 variant = { statusFilter === 'failed' ? 'secondary' : 'outline' }
12601310 onClick = { ( ) => handleStatusFilterChange ( 'failed' ) }
12611311 disabled = { isRefreshing }
12621312 className = { cn (
1263- ( statusCounts . FAILED || statusCounts . failed || documentCounts . failed ) > 0 ? 'text-red-600' : 'text-gray-500' ,
1313+ failedCount > 0 ? 'text-red-600' : 'text-gray-500' ,
12641314 statusFilter === 'failed' && 'bg-red-100 dark:bg-red-900/30 font-medium border border-red-400 dark:border-red-600 shadow-sm'
12651315 ) }
12661316 >
1267- { t ( 'documentPanel.documentManager.status.failed' ) } ({ statusCounts . FAILED || statusCounts . failed || 0 } )
1317+ { t ( 'documentPanel.documentManager.status.failed' ) } ({ failedCount } )
12681318 </ Button >
12691319 </ div >
12701320 < Button
@@ -1410,6 +1460,9 @@ export default function DocumentManager() {
14101460 { doc . status === 'processed' && (
14111461 < span className = "text-green-600" > { t ( 'documentPanel.documentManager.status.completed' ) } </ span >
14121462 ) }
1463+ { doc . status === 'multimodal_processed' && (
1464+ < span className = "text-purple-600" > { t ( 'documentPanel.documentManager.status.preprocessed' ) } </ span >
1465+ ) }
14131466 { doc . status === 'processing' && (
14141467 < span className = "text-blue-600" > { t ( 'documentPanel.documentManager.status.processing' ) } </ span >
14151468 ) }
0 commit comments