Add re-analyse button and POST /documents/{id}/reprocess endpoint
Resets status to pending, clears error_message, and re-enqueues the background AI extraction task. Button is disabled while the document is already pending or processing; returns 409 in that case from the API. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -170,6 +170,9 @@ export const updateDocumentTags = (id: string, tags: string[]) =>
|
||||
export const updateDocumentTitle = (id: string, title: string) =>
|
||||
api.patch<DocumentOut>(`/documents/${id}/title`, { title }).then((r) => r.data);
|
||||
|
||||
export const reprocessDocument = (id: string) =>
|
||||
api.post<DocumentOut>(`/documents/${id}/reprocess`).then((r) => r.data);
|
||||
|
||||
export const assignCategory = (docId: string, catId: string) =>
|
||||
api.post(`/documents/${docId}/categories/${catId}`);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
assignCategory,
|
||||
removeCategory,
|
||||
updateDocumentTitle,
|
||||
reprocessDocument,
|
||||
type DocumentOut,
|
||||
type CategoryOut,
|
||||
type DocumentListParams,
|
||||
@@ -225,6 +226,11 @@ function DocumentRow({
|
||||
},
|
||||
});
|
||||
|
||||
const reprocessMut = useMutation({
|
||||
mutationFn: () => reprocessDocument(doc.id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["documents"] }),
|
||||
});
|
||||
|
||||
const handleAcceptSuggestion = (name: string, existing: CategoryOut | undefined) => {
|
||||
if (existing) {
|
||||
assignMut.mutate({ catId: existing.id });
|
||||
@@ -276,6 +282,22 @@ function DocumentRow({
|
||||
>
|
||||
Download
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
reprocessMut.mutate();
|
||||
}}
|
||||
disabled={reprocessMut.isPending || doc.status === "pending" || doc.status === "processing"}
|
||||
style={{
|
||||
fontSize: 12,
|
||||
cursor: reprocessMut.isPending || doc.status === "pending" || doc.status === "processing" ? "default" : "pointer",
|
||||
color: "#2a7ae2",
|
||||
opacity: reprocessMut.isPending || doc.status === "pending" || doc.status === "processing" ? 0.5 : 1,
|
||||
}}
|
||||
title="Re-run AI analysis on this document"
|
||||
>
|
||||
{reprocessMut.isPending ? "…" : "Re-analyse"}
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
|
||||
Reference in New Issue
Block a user