feat(client): impelement retry all button on Document Management page
This commit is contained in:
parent
8cea916abf
commit
8d27132e12
|
|
@ -19,6 +19,7 @@ import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
|
DialogContentText,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
Pagination,
|
Pagination,
|
||||||
CircularProgress,
|
CircularProgress,
|
||||||
|
|
@ -233,6 +234,7 @@ const DocumentManagementPage: React.FC = () => {
|
||||||
const [retryHistoryModalOpen, setRetryHistoryModalOpen] = useState(false);
|
const [retryHistoryModalOpen, setRetryHistoryModalOpen] = useState(false);
|
||||||
const [selectedDocumentForHistory, setSelectedDocumentForHistory] = useState<string | null>(null);
|
const [selectedDocumentForHistory, setSelectedDocumentForHistory] = useState<string | null>(null);
|
||||||
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
||||||
|
const [confirmRetryAllOpen, setConfirmRetryAllOpen] = useState(false);
|
||||||
|
|
||||||
const fetchFailedDocuments = async () => {
|
const fetchFailedDocuments = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -358,6 +360,42 @@ const DocumentManagementPage: React.FC = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRetryAllDocuments = async () => {
|
||||||
|
try {
|
||||||
|
setRetryingAll(true);
|
||||||
|
const response = await documentService.bulkRetryOcr({
|
||||||
|
mode: 'all',
|
||||||
|
preview_only: false
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.queued_count > 0) {
|
||||||
|
setSnackbar({
|
||||||
|
open: true,
|
||||||
|
message: `Successfully queued ${response.data.queued_count} documents for OCR retry. Estimated processing time: ${Math.ceil(response.data.estimated_total_time_minutes)} minutes.`,
|
||||||
|
severity: 'success'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Refresh all tabs since we're retrying all documents
|
||||||
|
await refreshCurrentTab();
|
||||||
|
} else {
|
||||||
|
setSnackbar({
|
||||||
|
open: true,
|
||||||
|
message: 'No documents found to retry',
|
||||||
|
severity: 'info'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error retrying all documents:', error);
|
||||||
|
setSnackbar({
|
||||||
|
open: true,
|
||||||
|
message: 'Failed to retry documents. Please try again.',
|
||||||
|
severity: 'error'
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setRetryingAll(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleRetryAllFailed = async () => {
|
const handleRetryAllFailed = async () => {
|
||||||
try {
|
try {
|
||||||
setRetryingAll(true);
|
setRetryingAll(true);
|
||||||
|
|
@ -735,14 +773,33 @@ const DocumentManagementPage: React.FC = () => {
|
||||||
<Typography variant="h4" component="h1">
|
<Typography variant="h4" component="h1">
|
||||||
Document Management
|
Document Management
|
||||||
</Typography>
|
</Typography>
|
||||||
<Button
|
<Box display="flex" gap={2}>
|
||||||
variant="outlined"
|
<Button
|
||||||
startIcon={<RefreshIcon />}
|
variant="contained"
|
||||||
onClick={refreshCurrentTab}
|
color="primary"
|
||||||
disabled={loading || duplicatesLoading || retryingAll}
|
size="large"
|
||||||
>
|
startIcon={retryingAll ? <CircularProgress size={20} color="inherit" /> : <RefreshIcon />}
|
||||||
Refresh
|
onClick={() => setConfirmRetryAllOpen(true)}
|
||||||
</Button>
|
disabled={retryingAll}
|
||||||
|
sx={{
|
||||||
|
minWidth: 200,
|
||||||
|
boxShadow: 3,
|
||||||
|
'&:hover': {
|
||||||
|
boxShadow: 6,
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{retryingAll ? 'Retrying All...' : 'Retry All Documents'}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
startIcon={<RefreshIcon />}
|
||||||
|
onClick={refreshCurrentTab}
|
||||||
|
disabled={loading || duplicatesLoading || retryingAll}
|
||||||
|
>
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Paper sx={{ mb: 3, borderRadius: 2, overflow: 'hidden' }}>
|
<Paper sx={{ mb: 3, borderRadius: 2, overflow: 'hidden' }}>
|
||||||
|
|
@ -825,7 +882,7 @@ const DocumentManagementPage: React.FC = () => {
|
||||||
size="small"
|
size="small"
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
{retryingAll ? 'Retrying All...' : 'Retry All Failed OCR'}
|
{retryingAll ? 'Retrying...' : 'Retry Failed Only'}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
@ -2219,6 +2276,43 @@ const DocumentManagementPage: React.FC = () => {
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
{/* Confirm Retry All Documents Dialog */}
|
||||||
|
<Dialog open={confirmRetryAllOpen} onClose={() => setConfirmRetryAllOpen(false)}>
|
||||||
|
<DialogTitle>
|
||||||
|
<Box display="flex" alignItems="center">
|
||||||
|
<RefreshIcon sx={{ mr: 1, color: 'primary.main' }} />
|
||||||
|
Retry All Documents
|
||||||
|
</Box>
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogContentText>
|
||||||
|
This will retry OCR processing for <strong>all documents</strong> in your library, regardless of their current OCR status.
|
||||||
|
This includes documents that have already been successfully processed.
|
||||||
|
</DialogContentText>
|
||||||
|
<Box sx={{ mt: 2, p: 2, bgcolor: 'warning.light', borderRadius: 1 }}>
|
||||||
|
<Typography variant="body2" color="warning.dark">
|
||||||
|
<strong>Note:</strong> This is a resource-intensive operation that may take a significant amount of time depending on the number of documents.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={() => setConfirmRetryAllOpen(false)}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setConfirmRetryAllOpen(false);
|
||||||
|
handleRetryAllDocuments();
|
||||||
|
}}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
startIcon={<RefreshIcon />}
|
||||||
|
>
|
||||||
|
Retry All Documents
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{/* Advanced Retry Modal */}
|
{/* Advanced Retry Modal */}
|
||||||
<BulkRetryModal
|
<BulkRetryModal
|
||||||
open={bulkRetryModalOpen}
|
open={bulkRetryModalOpen}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue