Merge pull request #71 from readur/feat/view-failed-document

feat(frontend): view failed document and link to details
This commit is contained in:
Jon Fuller 2025-06-28 07:37:51 -07:00 committed by GitHub
commit cf966e50c8
1 changed files with 122 additions and 58 deletions

View File

@ -1,4 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { import {
Box, Box,
Typography, Typography,
@ -30,6 +31,7 @@ import {
Tab, Tab,
TextField, TextField,
useTheme, useTheme,
Divider,
} from '@mui/material'; } from '@mui/material';
import Grid from '@mui/material/GridLegacy'; import Grid from '@mui/material/GridLegacy';
import { import {
@ -44,9 +46,11 @@ import {
FileCopy as FileCopyIcon, FileCopy as FileCopyIcon,
Delete as DeleteIcon, Delete as DeleteIcon,
FindInPage as FindInPageIcon, FindInPage as FindInPageIcon,
OpenInNew as OpenInNewIcon,
} from '@mui/icons-material'; } from '@mui/icons-material';
import { format } from 'date-fns'; import { format } from 'date-fns';
import { api, documentService } from '../services/api'; import { api, documentService } from '../services/api';
import DocumentViewer from '../components/DocumentViewer';
interface FailedDocument { interface FailedDocument {
id: string; id: string;
@ -127,6 +131,7 @@ interface DuplicatesResponse {
const FailedOcrPage: React.FC = () => { const FailedOcrPage: React.FC = () => {
const theme = useTheme(); const theme = useTheme();
const navigate = useNavigate();
const [currentTab, setCurrentTab] = useState(0); const [currentTab, setCurrentTab] = useState(0);
const [documents, setDocuments] = useState<FailedDocument[]>([]); const [documents, setDocuments] = useState<FailedDocument[]>([]);
const [duplicates, setDuplicates] = useState<DuplicateGroup[]>([]); const [duplicates, setDuplicates] = useState<DuplicateGroup[]>([]);
@ -1028,7 +1033,7 @@ const FailedOcrPage: React.FC = () => {
<Dialog <Dialog
open={detailsOpen} open={detailsOpen}
onClose={() => setDetailsOpen(false)} onClose={() => setDetailsOpen(false)}
maxWidth="md" maxWidth="lg"
fullWidth fullWidth
> >
<DialogTitle> <DialogTitle>
@ -1036,8 +1041,50 @@ const FailedOcrPage: React.FC = () => {
</DialogTitle> </DialogTitle>
<DialogContent> <DialogContent>
{selectedDocument && ( {selectedDocument && (
<Grid container spacing={2}> <Grid container spacing={3}>
{/* File Preview Section */}
<Grid item xs={12} md={6}> <Grid item xs={12} md={6}>
<Typography variant="h6" sx={{ mb: 2 }}>
File Preview
</Typography>
<Box
onClick={() => {
if (selectedDocument) {
navigate(`/documents/${selectedDocument.id}`);
}
}}
sx={{
cursor: 'pointer',
border: '2px dashed',
borderColor: 'primary.main',
borderRadius: 2,
p: 1,
transition: 'all 0.2s ease-in-out',
'&:hover': {
borderColor: 'primary.dark',
boxShadow: 2,
},
}}
>
<DocumentViewer
documentId={selectedDocument.id}
filename={selectedDocument.original_filename}
mimeType={selectedDocument.mime_type}
/>
<Box sx={{ mt: 1, textAlign: 'center' }}>
<Typography variant="caption" color="primary.main">
Click to open full document details page
</Typography>
</Box>
</Box>
</Grid>
{/* Document Information Section */}
<Grid item xs={12} md={6}>
<Typography variant="h6" sx={{ mb: 2 }}>
Document Information
</Typography>
<Box>
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary">
<strong>Original Filename:</strong> <strong>Original Filename:</strong>
</Typography> </Typography>
@ -1059,20 +1106,6 @@ const FailedOcrPage: React.FC = () => {
{selectedDocument.mime_type} {selectedDocument.mime_type}
</Typography> </Typography>
<Typography variant="body2" color="text.secondary">
<strong>Tags:</strong>
</Typography>
<Box sx={{ mb: 2 }}>
{selectedDocument.tags.length > 0 ? (
selectedDocument.tags.map((tag) => (
<Chip key={tag} label={tag} size="small" sx={{ mr: 1, mb: 1 }} />
))
) : (
<Typography variant="body2" color="text.secondary">No tags</Typography>
)}
</Box>
</Grid>
<Grid item xs={12} md={6}>
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary">
<strong>Failure Category:</strong> <strong>Failure Category:</strong>
</Typography> </Typography>
@ -1082,7 +1115,7 @@ const FailedOcrPage: React.FC = () => {
sx={{ mb: 2 }} sx={{ mb: 2 }}
/> />
<Typography variant="body2" color="text.secondary"> <Typography variant="body2" color="text.secondary" sx={{ mt: 2 }}>
<strong>Retry Count:</strong> <strong>Retry Count:</strong>
</Typography> </Typography>
<Typography variant="body2" sx={{ mb: 2 }}> <Typography variant="body2" sx={{ mb: 2 }}>
@ -1102,8 +1135,28 @@ const FailedOcrPage: React.FC = () => {
<Typography variant="body2"> <Typography variant="body2">
{format(new Date(selectedDocument.updated_at), 'PPpp')} {format(new Date(selectedDocument.updated_at), 'PPpp')}
</Typography> </Typography>
<Typography variant="body2" color="text.secondary" sx={{ mt: 2 }}>
<strong>Tags:</strong>
</Typography>
<Box sx={{ mb: 2 }}>
{selectedDocument.tags.length > 0 ? (
selectedDocument.tags.map((tag) => (
<Chip key={tag} label={tag} size="small" sx={{ mr: 1, mb: 1 }} />
))
) : (
<Typography variant="body2" color="text.secondary">No tags</Typography>
)}
</Box>
</Box>
</Grid> </Grid>
{/* Error Details Section */}
<Grid item xs={12}> <Grid item xs={12}>
<Divider sx={{ my: 2 }} />
<Typography variant="h6" sx={{ mb: 2 }}>
Error Details
</Typography>
<Typography variant="body2" color="text.secondary" sx={{ mb: 1 }}> <Typography variant="body2" color="text.secondary" sx={{ mb: 1 }}>
<strong>Full Error Message:</strong> <strong>Full Error Message:</strong>
</Typography> </Typography>
@ -1125,6 +1178,17 @@ const FailedOcrPage: React.FC = () => {
)} )}
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button
onClick={() => {
if (selectedDocument) {
navigate(`/documents/${selectedDocument.id}`);
}
}}
startIcon={<OpenInNewIcon />}
color="primary"
>
Open Document Details
</Button>
{selectedDocument?.can_retry && ( {selectedDocument?.can_retry && (
<Button <Button
onClick={() => { onClick={() => {