diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx index f23893fbe..3c9ef2cbc 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsTableShell.tsx @@ -3,7 +3,6 @@ import { formatDistanceToNow } from "date-fns"; import { Calendar, ChevronDown, ChevronUp, FileText, FileX, Link2, Plus, User } from "lucide-react"; import { motion } from "motion/react"; -import { useParams } from "next/navigation"; import { useTranslations } from "next-intl"; import React, { useRef, useState, useEffect } from "react"; import { useDocumentUploadDialog } from "@/components/assistant-ui/document-upload-popup"; @@ -22,7 +21,6 @@ import { } from "@/components/ui/table"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { DocumentTypeChip } from "./DocumentTypeIcon"; -import { RowActions } from "./RowActions"; import type { ColumnVisibility, Document } from "./types"; export type SortKey = keyof Pick; @@ -134,7 +132,6 @@ export function DocumentsTableShell({ selectedIds, setSelectedIds, columnVisibility, - deleteDocument, sortKey, sortDesc, onSortChange, @@ -146,14 +143,11 @@ export function DocumentsTableShell({ selectedIds: Set; setSelectedIds: (update: Set) => void; columnVisibility: ColumnVisibility; - deleteDocument: (id: number) => Promise; sortKey: SortKey; sortDesc: boolean; onSortChange: (key: SortKey) => void; }) { const t = useTranslations("documents"); - const params = useParams(); - const searchSpaceId = params.search_space_id; const { openDialog } = useDocumentUploadDialog(); // State for metadata viewer (opened via Ctrl/Cmd+Click) @@ -222,13 +216,10 @@ export function DocumentsTableShell({ )} {columnVisibility.created_at && ( - + )} - - Actions - @@ -262,15 +253,10 @@ export function DocumentsTableShell({ )} {columnVisibility.created_at && ( - + )} - -
- -
-
))} @@ -387,7 +373,7 @@ export function DocumentsTableShell({
)} {columnVisibility.created_at && ( - + )} - - Actions - @@ -479,7 +462,7 @@ export function DocumentsTableShell({ )} {columnVisibility.created_at && ( - + {formatRelativeDate(doc.created_at)} @@ -490,18 +473,6 @@ export function DocumentsTableShell({ )} - -
- { - await onRefresh(); - }} - searchSpaceId={searchSpaceId as string} - /> -
-
); })} @@ -579,14 +550,6 @@ export function DocumentsTableShell({ )} - { - await onRefresh(); - }} - searchSpaceId={searchSpaceId as string} - /> ); diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/RowActions.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/RowActions.tsx index 3fd4dcac8..88077581c 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/RowActions.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/RowActions.tsx @@ -31,12 +31,10 @@ const NON_DELETABLE_DOCUMENT_TYPES = ["SURFSENSE_DOCS"] as const; export function RowActions({ document, deleteDocument, - refreshDocuments, searchSpaceId, }: { document: Document; deleteDocument: (id: number) => Promise; - refreshDocuments: () => Promise; searchSpaceId: string; }) { const [isDeleteOpen, setIsDeleteOpen] = useState(false); @@ -55,9 +53,9 @@ export function RowActions({ setIsDeleting(true); try { const ok = await deleteDocument(document.id); - if (ok) toast.success("Document deleted successfully"); - else toast.error("Failed to delete document"); - await refreshDocuments(); + if (!ok) toast.error("Failed to delete document"); + // Note: Success toast is handled by the mutation atom's onSuccess callback + // Cache is updated optimistically by the mutation, no need to refresh } catch (error) { console.error("Error deleting document:", error); toast.error("Failed to delete document"); diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/page.tsx index 269c2ca2f..0e08f7500 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/page.tsx @@ -187,20 +187,6 @@ export default function DocumentsTable() { } }, [debouncedSearch, refetchSearch, refetchDocuments, t, isRefreshing]); - // Create a delete function for single document deletion - const deleteDocument = useCallback( - async (id: number) => { - try { - await deleteDocumentMutation({ id }); - return true; - } catch (error) { - console.error("Failed to delete document:", error); - return false; - } - }, - [deleteDocumentMutation] - ); - const onBulkDelete = async () => { if (selectedIds.size === 0) { toast.error(t("no_rows_selected")); @@ -222,8 +208,7 @@ export default function DocumentsTable() { if (okCount === selectedIds.size) toast.success(t("delete_success_count", { count: okCount })); else toast.error(t("delete_partial_failed")); - // Refetch the current page with appropriate method - await refreshCurrentView(); + // Note: No need to call refreshCurrentView() - the mutation already updates the cache setSelectedIds(new Set()); } catch (e) { console.error(e); @@ -282,7 +267,6 @@ export default function DocumentsTable() { selectedIds={selectedIds} setSelectedIds={setSelectedIds} columnVisibility={columnVisibility} - deleteDocument={deleteDocument} sortKey={sortKey} sortDesc={sortDesc} onSortChange={handleSortChange} diff --git a/surfsense_web/atoms/documents/document-mutation.atoms.ts b/surfsense_web/atoms/documents/document-mutation.atoms.ts index 09e127735..ce077cd4a 100644 --- a/surfsense_web/atoms/documents/document-mutation.atoms.ts +++ b/surfsense_web/atoms/documents/document-mutation.atoms.ts @@ -95,7 +95,7 @@ export const deleteDocumentMutationAtom = atomWithMutation((get) => { }, onSuccess: (_, request: DeleteDocumentRequest) => { - toast.success("Document deleted successfully"); + // Note: Toast is handled by the caller (page.tsx onBulkDelete) to show count info queryClient.setQueryData( cacheKeys.documents.globalQueryParams(documentsQueryParams), (oldData: GetDocumentsResponse | undefined) => {