Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat(all-documents): Add hide from All Documents feature

Cursor Agentc1b460ac8765
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsx
index 774a2d0e..1700f132 100644
--- a/components/documents/document-card.tsx
+++ b/components/documents/document-card.tsx
@@ -9,6 +9,7 @@ import {
BetweenHorizontalStartIcon,
ChevronRight,
EyeIcon,
+ EyeOffIcon,
FileIcon,
FolderIcon,
FolderInputIcon,
@@ -231,6 +232,77 @@ export default function DocumentsCard({
);
};
+ const handleHideDocument = async (event: any) => {
+ event.stopPropagation();
+ event.preventDefault();
+
+ const page = Number(queryParams["page"]) || 1;
+ const pageSize = Number(queryParams["limit"]) || 10;
+
+ const queryParts = [];
+ if (searchQuery) queryParts.push(`query=${searchQuery}`);
+ if (sortQuery) queryParts.push(`sort=${sortQuery}`);
+
+ const paginationParams =
+ searchQuery || sortQuery ? `&page=${page}&limit=${pageSize}` : "";
+ if (paginationParams) queryParts.push(paginationParams.substring(1));
+ const queryString = queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
+
+ const endpoint = currentFolderPath
+ ? `/folders/documents/${currentFolderPath.join("/")}`
+ : `/documents${queryString}`;
+
+ toast.promise(
+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hide`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ documentIds: [prismaDocument.id],
+ hidden: true,
+ }),
+ }).then(async (res) => {
+ if (!res.ok) {
+ const error = await res.json();
+ throw new Error(error.message || "Failed to hide document");
+ }
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}${endpoint}`,
+ (currentData: any) => {
+ if (!currentData) return currentData;
+
+ if (Array.isArray(currentData)) {
+ return currentData.filter(
+ (doc: DocumentWithLinksAndLinkCountAndViewCount) =>
+ doc.id !== prismaDocument.id,
+ );
+ } else if (currentData.documents) {
+ return {
+ ...currentData,
+ documents: currentData.documents.filter(
+ (doc: DocumentWithLinksAndLinkCountAndViewCount) =>
+ doc.id !== prismaDocument.id,
+ ),
+ };
+ }
+ return currentData;
+ },
+ {
+ revalidate: false,
+ },
+ );
+ setMenuOpen(false);
+ }),
+ {
+ loading: "Hiding document from All Documents...",
+ success: "Document hidden from All Documents.",
+ error: (err) =>
+ err.message || "Failed to hide document. Try again.",
+ },
+ );
+ };
+
return (
<>
<div
@@ -378,6 +450,10 @@ export default function DocumentsCard({
Add to dataroom
</DropdownMenuItem>
)}
+ <DropdownMenuItem onClick={handleHideDocument}>
+ <EyeOffIcon className="mr-2 h-4 w-4" />
+ Hide from All Documents
+ </DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(event) => handleButtonClick(event, prismaDocument.id)}
diff --git a/components/documents/documents-list.tsx b/components/documents/documents-list.tsx
index 6dafca36..33959e31 100644
--- a/components/documents/documents-list.tsx
+++ b/components/documents/documents-list.tsx
@@ -17,6 +17,7 @@ import {
useSensors,
} from "@dnd-kit/core";
import {
+ EyeOffIcon,
FileIcon,
FolderIcon,
FolderInputIcon,
@@ -25,6 +26,7 @@ import {
} from "lucide-react";
import { motion } from "motion/react";
import { toast } from "sonner";
+import { mutate } from "swr";
import { moveDocumentToFolder } from "@/lib/documents/move-documents";
import { moveFolderToFolder } from "@/lib/documents/move-folder";
@@ -347,6 +349,88 @@ export function DocumentsList({
setSelectedFolders([]);
};
+ const [isHiding, setIsHiding] = useState(false);
+
+ const handleBulkHide = useCallback(async () => {
+ if (selectedDocuments.length === 0 && selectedFolders.length === 0) return;
+
+ setIsHiding(true);
+
+ try {
+ const promises: Promise<Response>[] = [];
+
+ // Hide documents
+ if (selectedDocuments.length > 0) {
+ promises.push(
+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hide`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ documentIds: selectedDocuments,
+ hidden: true,
+ }),
+ }),
+ );
+ }
+
+ // Hide folders (cascades to children)
+ if (selectedFolders.length > 0) {
+ promises.push(
+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/folders/hide`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ folderIds: selectedFolders,
+ hidden: true,
+ }),
+ }),
+ );
+ }
+
+ const results = await Promise.all(promises);
+
+ // Check for errors
+ for (const res of results) {
+ if (!res.ok) {
+ const error = await res.json();
+ throw new Error(error.message || "Failed to hide items");
+ }
+ }
+
+ // Revalidate data
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders?root=true`);
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders`);
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents`);
+
+ if (folderPathName && folderPathName.length > 0) {
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/folders/${folderPathName.join("/")}`,
+ );
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/folders/documents/${folderPathName.join("/")}`,
+ );
+ }
+
+ // Reset selection
+ setSelectedDocuments([]);
+ setSelectedFolders([]);
+
+ toast.success(
+ `Successfully hidden ${selectedDocuments.length > 0 ? `${selectedDocuments.length} document${selectedDocuments.length > 1 ? "s" : ""}` : ""}${selectedDocuments.length > 0 && selectedFolders.length > 0 ? " and " : ""}${selectedFolders.length > 0 ? `${selectedFolders.length} folder${selectedFolders.length > 1 ? "s" : ""}` : ""} from All Documents`,
+ );
+ } catch (error) {
+ toast.error(
+ error instanceof Error ? error.message : "Failed to hide items",
+ );
+ } finally {
+ setIsHiding(false);
+ }
+ }, [selectedDocuments, selectedFolders, teamInfo?.currentTeam?.id, folderPathName]);
+
const HeaderContent = memo(() => {
if (selectedDocumentsLength > 0 || selectedFoldersLength > 0) {
const totalItems = (documents?.length || 0) + (folders?.length || 0);
@@ -411,6 +495,17 @@ export function DocumentsList({
<FolderInputIcon className="h-5 w-5" />
</Button>
</ButtonTooltip>
+ <ButtonTooltip content="Hide from All Documents">
+ <Button
+ onClick={handleBulkHide}
+ disabled={isHiding}
+ className="mx-1.5 my-1 size-8 rounded-full hover:bg-gray-200 hover:dark:bg-gray-700"
+ variant="ghost"
+ size="icon"
+ >
+ <EyeOffIcon className="h-5 w-5" />
+ </Button>
+ </ButtonTooltip>
<ButtonTooltip content="Delete">
<Button
onClick={() => setShowDeleteItemsModal(true)}
diff --git a/components/documents/folder-card.tsx b/components/documents/folder-card.tsx
index 6efe1fe5..2c9ece56 100644
--- a/components/documents/folder-card.tsx
+++ b/components/documents/folder-card.tsx
@@ -7,6 +7,7 @@ import {
BetweenHorizontalStartIcon,
ClipboardCopyIcon,
CopyIcon,
+ EyeOffIcon,
FolderIcon,
FolderInputIcon,
FolderPenIcon,
@@ -153,6 +154,42 @@ export default function FolderCard({
router.push(folderPath);
};
+ const handleHideFolder = async (e: React.MouseEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+
+ toast.promise(
+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/folders/hide`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ folderIds: [folder.id],
+ hidden: true,
+ }),
+ }).then(async (res) => {
+ if (!res.ok) {
+ const error = await res.json();
+ throw new Error(error.message || "Failed to hide folder");
+ }
+ // Revalidate the folders and documents
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders?root=true`);
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders`);
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/folders${parentFolderPath}`,
+ );
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents`);
+ setMenuOpen(false);
+ }),
+ {
+ loading: "Hiding folder from All Documents...",
+ success: "Folder hidden from All Documents.",
+ error: (err) => err.message || "Failed to hide folder. Try again.",
+ },
+ );
+ };
+
return (
<>
<div
@@ -278,6 +315,12 @@ export default function FolderCard({
{folder.id}
</span>
</DropdownMenuItem>
+ {!isDataroom && (
+ <DropdownMenuItem onClick={handleHideFolder}>
+ <EyeOffIcon className="mr-2 h-4 w-4" />
+ Hide from All Documents
+ </DropdownMenuItem>
+ )}
<DropdownMenuSeparator />
<DropdownMenuItem
diff --git a/pages/api/teams/[teamId]/documents/hide.ts b/pages/api/teams/[teamId]/documents/hide.ts
new file mode 100644
index 00000000..e022ed4d
--- /dev/null
+++ b/pages/api/teams/[teamId]/documents/hide.ts
@@ -0,0 +1,74 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { getServerSession } from "next-auth/next";
+
+import { errorhandler } from "@/lib/errorHandler";
+import prisma from "@/lib/prisma";
+import { CustomUser } from "@/lib/types";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "POST") {
+ // POST /api/teams/:teamId/documents/hide
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const { teamId } = req.query as { teamId: string };
+ const userId = (session.user as CustomUser).id;
+
+ const { documentIds, hidden } = req.body as {
+ documentIds: string[];
+ hidden: boolean;
+ };
+
+ if (!documentIds || !Array.isArray(documentIds) || documentIds.length === 0) {
+ return res.status(400).json({ error: "Document IDs are required" });
+ }
+
+ if (typeof hidden !== "boolean") {
+ return res.status(400).json({ error: "Hidden flag is required" });
+ }
+
+ try {
+ // Check team access
+ const teamAccess = await prisma.userTeam.findUnique({
+ where: {
+ userId_teamId: {
+ userId,
+ teamId,
+ },
+ },
+ });
+
+ if (!teamAccess) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ // Update the documents
+ const result = await prisma.document.updateMany({
+ where: {
+ id: { in: documentIds },
+ teamId,
+ },
+ data: {
+ hiddenInAllDocuments: hidden,
+ },
+ });
+
+ return res.status(200).json({
+ message: `${result.count} document(s) ${hidden ? "hidden" : "unhidden"} successfully`,
+ count: result.count,
+ });
+ } catch (error) {
+ errorhandler(error, res);
+ }
+ } else {
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index 232b7f5c..cf11b3d8 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -75,37 +75,45 @@ export default async function handle(
orderBy = { createdAt: "desc" };
}
+ // Build the base where clause for All Documents view
+ // Documents should be excluded if:
+ // 1. They are directly hidden (hiddenInAllDocuments: true)
+ // 2. They are in a folder that is hidden (folder.hiddenInAllDocuments: true)
+ const baseWhere = {
+ teamId: teamId,
+ hiddenInAllDocuments: false, // Exclude directly hidden documents
+ ...(query && {
+ name: {
+ contains: query,
+ mode: "insensitive" as const,
+ },
+ }),
+ // For root view (no search/sort), only show root-level documents
+ ...(!(query || sort) && {
+ folderId: null,
+ }),
+ // For search/sort view, also exclude documents in hidden folders
+ ...((query || sort) && {
+ OR: [
+ { folderId: null },
+ {
+ folder: {
+ hiddenInAllDocuments: false,
+ },
+ },
+ ],
+ }),
+ };
+
const totalDocuments = usePagination
? await prisma.document.count({
- where: {
- teamId: teamId,
- ...(query && {
- name: {
- contains: query,
- mode: "insensitive",
- },
- }),
- ...(!(query || sort) && {
- folderId: null,
- }),
- },
+ where: baseWhere,
})
: undefined;
// First, get documents without expensive counts
const documents = await prisma.document.findMany({
- where: {
- teamId: teamId,
- ...(query && {
- name: {
- contains: query,
- mode: "insensitive",
- },
- }),
- ...(!(query || sort) && {
- folderId: null,
- }),
- },
+ where: baseWhere,
orderBy,
...(usePagination && {
skip: ((page as number) - 1) * (limit as number),
diff --git a/pages/api/teams/[teamId]/folders/[...name].ts b/pages/api/teams/[teamId]/folders/[...name].ts
index 84c26305..092fe68e 100644
--- a/pages/api/teams/[teamId]/folders/[...name].ts
+++ b/pages/api/teams/[teamId]/folders/[...name].ts
@@ -69,13 +69,21 @@ export default async function handle(
where: {
teamId: teamId,
parentId: parentFolder.id,
+ hiddenInAllDocuments: false, // Exclude hidden folders from All Documents folder tree
},
orderBy: {
name: "asc",
},
include: {
_count: {
- select: { documents: true, childFolders: true },
+ select: {
+ documents: {
+ where: { hiddenInAllDocuments: false },
+ },
+ childFolders: {
+ where: { hiddenInAllDocuments: false },
+ },
+ },
},
},
});
diff --git a/pages/api/teams/[teamId]/folders/documents/[...name].ts b/pages/api/teams/[teamId]/folders/documents/[...name].ts
index 6aaf1723..360892bf 100644
--- a/pages/api/teams/[teamId]/folders/documents/[...name].ts
+++ b/pages/api/teams/[teamId]/folders/documents/[...name].ts
@@ -70,6 +70,7 @@ export default async function handle(
where: {
teamId: teamId,
folderId: folder.id,
+ hiddenInAllDocuments: false, // Exclude hidden documents from All Documents folder view
},
orderBy: {
createdAt: "desc",
diff --git a/pages/api/teams/[teamId]/folders/hide.ts b/pages/api/teams/[teamId]/folders/hide.ts
new file mode 100644
index 00000000..8a2ddc1f
--- /dev/null
+++ b/pages/api/teams/[teamId]/folders/hide.ts
@@ -0,0 +1,144 @@
+import { NextApiRequest, NextApiResponse } from "next";
+
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { getServerSession } from "next-auth/next";
+
+import { errorhandler } from "@/lib/errorHandler";
+import prisma from "@/lib/prisma";
+import { CustomUser } from "@/lib/types";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "POST") {
+ // POST /api/teams/:teamId/folders/hide
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const { teamId } = req.query as { teamId: string };
+ const userId = (session.user as CustomUser).id;
+
+ const { folderIds, hidden } = req.body as {
+ folderIds: string[];
+ hidden: boolean;
+ };
+
+ if (!folderIds || !Array.isArray(folderIds) || folderIds.length === 0) {
+ return res.status(400).json({ error: "Folder IDs are required" });
+ }
+
+ if (typeof hidden !== "boolean") {
+ return res.status(400).json({ error: "Hidden flag is required" });
+ }
+
+ try {
+ // Check team access
+ const teamAccess = await prisma.userTeam.findUnique({
+ where: {
+ userId_teamId: {
+ userId,
+ teamId,
+ },
+ },
+ });
+
+ if (!teamAccess) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ // Get the folders to find their paths for cascading
+ const folders = await prisma.folder.findMany({
+ where: {
+ id: { in: folderIds },
+ teamId,
+ },
+ select: {
+ id: true,
+ path: true,
+ },
+ });
+
+ if (folders.length === 0) {
+ return res.status(404).json({ error: "No folders found" });
+ }
+
+ // Update the selected folders
+ const folderResult = await prisma.folder.updateMany({
+ where: {
+ id: { in: folderIds },
+ teamId,
+ },
+ data: {
+ hiddenInAllDocuments: hidden,
+ },
+ });
+
+ // Build path conditions for cascading to child folders
+ // Cascade: hide/unhide all subfolders and documents that have paths starting with the hidden folder paths
+ const pathConditions = folders.map((folder) => ({
+ path: {
+ startsWith: folder.path + "/",
+ },
+ }));
+
+ // Update child folders (cascade)
+ let childFolderCount = 0;
+ if (pathConditions.length > 0) {
+ const childFolderResult = await prisma.folder.updateMany({
+ where: {
+ teamId,
+ OR: pathConditions,
+ },
+ data: {
+ hiddenInAllDocuments: hidden,
+ },
+ });
+ childFolderCount = childFolderResult.count;
+ }
+
+ // Update documents in these folders and subfolders
+ // Get all folder IDs (selected + children)
+ const allFolderPaths = folders.map((f) => f.path);
+ const childFolders = await prisma.folder.findMany({
+ where: {
+ teamId,
+ OR: pathConditions.length > 0 ? pathConditions : [{ id: "none" }],
+ },
+ select: {
+ id: true,
+ path: true,
+ },
+ });
+
+ const allFolderIds = [
+ ...folderIds,
+ ...childFolders.map((f) => f.id),
+ ];
+
+ // Update documents in all affected folders
+ const documentResult = await prisma.document.updateMany({
+ where: {
+ teamId,
+ folderId: { in: allFolderIds },
+ },
+ data: {
+ hiddenInAllDocuments: hidden,
+ },
+ });
+
+ return res.status(200).json({
+ message: `${folderResult.count} folder(s) and ${documentResult.count} document(s) ${hidden ? "hidden" : "unhidden"} successfully`,
+ foldersCount: folderResult.count + childFolderCount,
+ documentsCount: documentResult.count,
+ });
+ } catch (error) {
+ errorhandler(error, res);
+ }
+ } else {
+ res.setHeader("Allow", ["POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/folders/index.ts b/pages/api/teams/[teamId]/folders/index.ts
index 7a21291f..36cb98b7 100644
--- a/pages/api/teams/[teamId]/folders/index.ts
+++ b/pages/api/teams/[teamId]/folders/index.ts
@@ -42,13 +42,21 @@ export default async function handle(
where: {
teamId: teamId,
parentId: null,
+ hiddenInAllDocuments: false, // Exclude hidden folders from All Documents view
},
orderBy: {
name: "asc",
},
include: {
_count: {
- select: { documents: true, childFolders: true },
+ select: {
+ documents: {
+ where: { hiddenInAllDocuments: false },
+ },
+ childFolders: {
+ where: { hiddenInAllDocuments: false },
+ },
+ },
},
},
});
diff --git a/prisma/migrations/20260113000000_add_hidden_in_all_documents/migration.sql b/prisma/migrations/20260113000000_add_hidden_in_all_documents/migration.sql
new file mode 100644
index 00000000..5f096c96
--- /dev/null
+++ b/prisma/migrations/20260113000000_add_hidden_in_all_documents/migration.sql
@@ -0,0 +1,11 @@
+-- AlterTable
+ALTER TABLE "Document" ADD COLUMN "hiddenInAllDocuments" BOOLEAN NOT NULL DEFAULT false;
+
+-- AlterTable
+ALTER TABLE "Folder" ADD COLUMN "hiddenInAllDocuments" BOOLEAN NOT NULL DEFAULT false;
+
+-- CreateIndex
+CREATE INDEX "Document_teamId_hiddenInAllDocuments_idx" ON "Document"("teamId", "hiddenInAllDocuments");
+
+-- CreateIndex
+CREATE INDEX "Folder_teamId_hiddenInAllDocuments_idx" ON "Folder"("teamId", "hiddenInAllDocuments");
diff --git a/prisma/schema/document.prisma b/prisma/schema/document.prisma
index 8dbe331c..bd111834 100644
--- a/prisma/schema/document.prisma
+++ b/prisma/schema/document.prisma
@@ -16,6 +16,7 @@ model Document {
advancedExcelEnabled Boolean @default(false) // This indicates if advanced Excel is enabled for this document
agentsEnabled Boolean @default(false) // This indicates if AI agents are enabled for this document
downloadOnly Boolean @default(false) // Indicates if the document is download only
+ hiddenInAllDocuments Boolean @default(false) // Indicates if the document is hidden from All Documents view
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
links Link[]
@@ -39,6 +40,7 @@ model Document {
@@index([folderId])
@@index([teamId, folderId]) // Performance optimization for document filtering by team and folder
@@index([teamId, name]) // Performance optimization for document search by name
+ @@index([teamId, hiddenInAllDocuments]) // Performance optimization for filtering hidden documents
}
model DocumentVersion {
@@ -93,21 +95,23 @@ enum DocumentStorageType {
}
model Folder {
- id String @id @default(cuid())
- name String
- path String // the materialized path to the folder; starts always with "/"
- parentId String?
- documents Document[]
- childFolders Folder[] @relation("SubFolders")
- parentFolder Folder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)
- teamId String
- team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
+ id String @id @default(cuid())
+ name String
+ path String // the materialized path to the folder; starts always with "/"
+ parentId String?
+ hiddenInAllDocuments Boolean @default(false) // Indicates if the folder is hidden from All Documents view
+ documents Document[]
+ childFolders Folder[] @relation("SubFolders")
+ parentFolder Folder? @relation("SubFolders", fields: [parentId], references: [id], onDelete: SetNull)
+ teamId String
+ team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([teamId, path])
@@index([parentId])
+ @@index([teamId, hiddenInAllDocuments]) // Performance optimization for filtering hidden folders
}
model DocumentUpload {