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:
curo1305
2026-04-17 17:00:17 +02:00
parent 7d0edbd5e7
commit d2042153a7
5 changed files with 59 additions and 1 deletions
+3
View File
@@ -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}`);
+22
View File
@@ -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();