Skip to content

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

* Added breadcrumb to document card

AshishViradiya153a82a8bf6d16d
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsx
index 6a881715..ce819ffc 100644
--- a/components/documents/document-card.tsx
+++ b/components/documents/document-card.tsx
@@ -7,6 +7,8 @@ import { TeamContextType } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
import {
BetweenHorizontalStartIcon,
+ ChevronRight,
+ FolderIcon,
FolderInputIcon,
Layers2Icon,
MoreVertical,
@@ -16,6 +18,13 @@ import { useTheme } from "next-themes";
import { toast } from "sonner";
import { mutate } from "swr";
+import useDatarooms from "@/lib/swr/use-datarooms";
+import useLimits from "@/lib/swr/use-limits";
+import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
+import { cn, getBreadcrumbPath, nFormatter, timeAgo } from "@/lib/utils";
+import { fileIcon } from "@/lib/utils/get-file-icon";
+import { useCopyToClipboard } from "@/lib/utils/use-copy-to-clipboard";
+
import BarChart from "@/components/shared/icons/bar-chart";
import { Button } from "@/components/ui/button";
import {
@@ -27,13 +36,6 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
-import useDatarooms from "@/lib/swr/use-datarooms";
-import useLimits from "@/lib/swr/use-limits";
-import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
-import { cn, nFormatter, timeAgo } from "@/lib/utils";
-import { fileIcon } from "@/lib/utils/get-file-icon";
-import { useCopyToClipboard } from "@/lib/utils/use-copy-to-clipboard";
-
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
import { DataroomTrialModal } from "../datarooms/dataroom-trial-modal";
import { AddToDataroomModal } from "./add-document-to-dataroom-modal";
@@ -252,6 +254,17 @@ export default function DocumentsCard({
</>
) : null}
</div>
+ <div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground">
+ {getBreadcrumbPath(prismaDocument.folder.path).map(
+ (segment, index) => (
+ <p className="flex items-center gap-x-1 truncate hover:underline">
+ {index !== 0 && <ChevronRight className="h-3 w-3" />}
+ <FolderIcon className="h-3 w-3" />
+ <Link href={segment.pathLink}>{segment.name}</Link>
+ </p>
+ ),
+ )}
+ </div>
</div>
</div>
diff --git a/lib/types.ts b/lib/types.ts
index 803e8bb8..19bfeeb4 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -31,6 +31,10 @@ export interface DocumentWithLinksAndLinkCountAndViewCount extends Document {
versions: number;
};
links: Link[];
+ folder: {
+ name: string;
+ path: string;
+ }
}
export interface DocumentWithVersion extends Document {
diff --git a/lib/utils.ts b/lib/utils.ts
index 4082ba1a..7ff53c00 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -540,3 +540,13 @@ export function hexToRgb(hex: string) {
}
export const trim = (u: unknown) => (typeof u === "string" ? u.trim() : u);
+
+export const getBreadcrumbPath = (path: string, basePath = "tree") => {
+ const segments = path.split("/").filter(Boolean); // Remove empty strings
+ let currentPath = basePath; // Start with base path
+
+ return segments.map((segment) => {
+ currentPath += `/${segment}`; // Append current segment to path
+ return { name: segment, pathLink: currentPath };
+ });
+};
\ No newline at end of file
diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.ts
index e5d8846d..cffd0b19 100644
--- a/pages/api/teams/[teamId]/documents/index.ts
+++ b/pages/api/teams/[teamId]/documents/index.ts
@@ -91,6 +91,12 @@ export default async function handle(
},
orderBy,
include: {
+ folder: {
+ select: {
+ name: true,
+ path: true,
+ },
+ },
...(sort &&
sort === "lastViewed" && {
views: {