From e615a6478cc6378ed8dcc86da561e5b798167c68 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Thu, 5 Feb 2026 01:29:15 +0530 Subject: [PATCH] feat: implement document deletion functionality and streamline column visibility management in DocumentsTable --- .../(manage)/components/DocumentsFilters.tsx | 59 +------------------ .../components/DocumentsTableShell.tsx | 34 +++++++++-- .../documents/(manage)/page.tsx | 25 ++++++-- 3 files changed, 50 insertions(+), 68 deletions(-) diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx index 2c3dc7eef..ed882916e 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx @@ -4,7 +4,6 @@ import { useSetAtom } from "jotai"; import { CircleAlert, CircleX, - Columns3, FilePlus2, FileType, ListFilter, @@ -31,11 +30,9 @@ import { import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import type { DocumentTypeEnum } from "@/contracts/types/document.types"; import { getDocumentTypeIcon, getDocumentTypeLabel } from "./DocumentTypeIcon"; -import type { ColumnVisibility } from "./types"; export function DocumentsFilters({ typeCounts: typeCountsRecord, @@ -45,8 +42,6 @@ export function DocumentsFilters({ onBulkDelete, onToggleType, activeTypes, - columnVisibility, - onToggleColumn, }: { typeCounts: Partial>; selectedIds: Set; @@ -55,8 +50,6 @@ export function DocumentsFilters({ onBulkDelete: () => Promise; onToggleType: (type: DocumentTypeEnum, checked: boolean) => void; activeTypes: DocumentTypeEnum[]; - columnVisibility: ColumnVisibility; - onToggleColumn: (id: keyof ColumnVisibility, checked: boolean) => void; }) { const t = useTranslations("documents"); const id = React.useId(); @@ -252,57 +245,7 @@ export function DocumentsFilters({ - {/* View/Columns Popover */} - - - - - -
-
- Toggle columns -
-
- {( - [ - ["document_type", "Source"], - ["created_by", "User"], - ["created_at", "Created"], - ] as Array<[keyof ColumnVisibility, string]> - ).map(([key, label], i) => ( - - ))} -
-
-
-
- - {/* Bulk Delete Button - positioned next to View on mobile */} + {/* Bulk Delete Button */} {selectedIds.size > 0 && ( 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 1be226a56..e79b4d104 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 @@ -28,6 +28,7 @@ import { import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { documentsApiService } from "@/lib/apis/documents-api.service"; import { DocumentTypeChip } from "./DocumentTypeIcon"; +import { RowActions } from "./RowActions"; import type { ColumnVisibility, Document } from "./types"; export type SortKey = keyof Pick; @@ -142,6 +143,8 @@ export function DocumentsTableShell({ sortKey, sortDesc, onSortChange, + deleteDocument, + searchSpaceId, }: { documents: Document[]; loading: boolean; @@ -153,6 +156,8 @@ export function DocumentsTableShell({ sortKey: SortKey; sortDesc: boolean; onSortChange: (key: SortKey) => void; + deleteDocument: (id: number) => Promise; + searchSpaceId: string; }) { const t = useTranslations("documents"); const { openDialog } = useDocumentUploadDialog(); @@ -273,7 +278,7 @@ export function DocumentsTableShell({ - +
@@ -296,6 +301,9 @@ export function DocumentsTableShell({
)} + + Actions +
@@ -307,7 +315,7 @@ export function DocumentsTableShell({ key={`skeleton-${index}`} className="border-b border-border/40 hover:bg-transparent" > - +
@@ -333,6 +341,9 @@ export function DocumentsTableShell({
)} + + + ))} @@ -406,7 +417,7 @@ export function DocumentsTableShell({ - +
)} + + Actions +
@@ -488,7 +502,7 @@ export function DocumentsTableShell({ : "hover:bg-muted/30" }`} > - +
)} + + + ); })} @@ -626,6 +647,11 @@ export function DocumentsTableShell({ )}
+ ); 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 31c95e5e6..ab92d1b94 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 @@ -138,10 +138,6 @@ export default function DocumentsTable() { setPageIndex(0); }; - const onToggleColumn = (id: keyof ColumnVisibility, checked: boolean) => { - setColumnVisibility((prev) => ({ ...prev, [id]: checked })); - }; - const [isRefreshing, setIsRefreshing] = useState(false); const refreshCurrentView = useCallback(async () => { @@ -193,6 +189,23 @@ export default function DocumentsTable() { } }; + // Single document delete handler for RowActions + const handleDeleteDocument = useCallback(async (id: number): Promise => { + try { + await deleteDocumentMutation({ id }); + toast.success(t("delete_success") || "Document deleted"); + // If in search mode, refetch search results to reflect deletion + if (isSearchMode) { + await refetchSearch(); + } + // Real-time mode: Electric will sync the deletion automatically + return true; + } catch (e) { + console.error("Error deleting document:", e); + return false; + } + }, [deleteDocumentMutation, isSearchMode, refetchSearch, t]); + const handleSortChange = useCallback((key: SortKey) => { setSortKey((currentKey) => { if (currentKey === key) { @@ -237,8 +250,6 @@ export default function DocumentsTable() { onBulkDelete={onBulkDelete} onToggleType={onToggleType} activeTypes={activeTypes} - columnVisibility={columnVisibility} - onToggleColumn={onToggleColumn} /> {/* Table */} @@ -253,6 +264,8 @@ export default function DocumentsTable() { sortKey={sortKey} sortDesc={sortDesc} onSortChange={handleSortChange} + deleteDocument={handleDeleteDocument} + searchSpaceId={String(searchSpaceId)} /> {/* Pagination */}