Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

refactor: extract formatFilesToDelete into shared helper

Olfa Maslahe3a3c8cdfc16
diff --git a/frontend/components/knowledge-actions-dropdown.tsx b/frontend/components/knowledge-actions-dropdown.tsx
index 42b534246..8099a84a1 100644
--- a/frontend/components/knowledge-actions-dropdown.tsx
+++ b/frontend/components/knowledge-actions-dropdown.tsx
@@ -14,6 +14,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { DeleteConfirmationDialog } from "./delete-confirmation-dialog";
+import { formatFilesToDelete } from "@/lib/format-files-to-delete";
import { Button } from "./ui/button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
@@ -151,12 +152,16 @@ export const KnowledgeActionsDropdown = ({
<DeleteConfirmationDialog
open={showDeleteDialog}
onOpenChange={setShowDeleteDialog}
- title="Delete Document"
- description={`Are you sure you want to delete "${filename}"? This will remove all chunks and data associated with this document. This action cannot be undone.`}
+ title="Delete document"
+ description="Are you sure you want to delete this document?"
confirmText="Delete"
onConfirm={handleDelete}
isLoading={deleteDocumentMutation.isPending}
- />
+ >
+ <p className="my-2">This will remove all chunks and data associated with this document. This action cannot be undone.</p>
+ <p className="my-2">Document to be deleted:</p>
+ {formatFilesToDelete([{ filename }])}
+ </DeleteConfirmationDialog>
</>
);
};
diff --git a/frontend/lib/format-files-to-delete.tsx b/frontend/lib/format-files-to-delete.tsx
new file mode 100644
index 000000000..d8ce474c8
--- /dev/null
+++ b/frontend/lib/format-files-to-delete.tsx
@@ -0,0 +1,17 @@
+import { type ReactNode } from "react";
+
+export function formatFilesToDelete(
+ files: Array<{ filename: string }>,
+ maxVisible = 5,
+): ReactNode {
+ const visibleFiles = files.slice(0, maxVisible);
+ const remainingCount = files.length - maxVisible;
+ return (
+ <ul className="list-disc list-inside max-w-[29rem] sm:max-w-[calc(425px-3rem)]">
+ {visibleFiles.map((file) => <li key={file.filename} className="my-2 truncate">{file.filename}</li>)}
+ {remainingCount > 0 ? <li>&hellip; and {remainingCount} more document{
+ remainingCount > 1 ? "s" : ""
+ }</li> : "" }
+ </ul>
+ );
+}