Skip to content

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

feat: make links table expandable

Marc Seitz75856f8350b2
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 00aedf2c..08663e23 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -15,6 +15,11 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "@/components/ui/collapsible";
import { Button } from "@/components/ui/button";
import { useDocumentLinks } from "@/lib/swr/use-document";
@@ -47,7 +52,9 @@ export default function LinksTable() {
return (
<div className="w-full sm:p-4">
- <div><h2 className="p-4">All links</h2></div>
+ <div>
+ <h2 className="p-4">All links</h2>
+ </div>
<div className="rounded-md sm:border">
<Table>
<TableHeader>
@@ -62,65 +69,79 @@ export default function LinksTable() {
<TableBody>
{links ? (
links.map((link) => (
- <TableRow key={link.id} className="group/row">
- <TableCell>{link.name || "No link name"}</TableCell>
- <TableCell className="min-w-[260px] sm:min-w-[450px]">
- <div className="group/cell flex items-center gap-x-4 rounded-md bg-gray-700 px-3 py-1 group-hover/row:ring-1 group-hover/row:ring-gray-100 hover:bg-gray-200 transition-all">
- <div className="whitespace-nowrap hidden sm:flex text-sm text-gray-300 group-hover/cell:hidden">{`https://papermark.io/view/${link.id}`}</div>
- <div className="flex sm:hidden whitespace-nowrap text-sm text-gray-300 group-hover/cell:hidden">{`${link.id}`}</div>
- <button
- className="whitespace-nowrap text-sm text-center text-black hidden group-hover/cell:block w-full"
- onClick={() => handleCopyToClipboard(link.id)}
- title="Copy to clipboard"
- >
- Copy to Clipboard
- </button>
- </div>
- </TableCell>
- <TableCell>
- <div className="flex items-center space-x-1">
- <BarChart className="h-4 w-4 text-gray-400" />
- <p className="whitespace-nowrap text-sm text-gray-400">
- {nFormatter(link._count.views)}
- <span className="ml-1 hidden sm:inline-block">
- views
- </span>
- </p>
- </div>
- </TableCell>
- <TableCell className="text-sm text-gray-400">
- {link.views[0] ? (
- <time
- dateTime={new Date(
- link.views[0].viewedAt
- ).toISOString()}
- >
- {timeAgo(link.views[0].viewedAt)}
- </time>
- ) : (
- "-"
- )}
- </TableCell>
- <TableCell className="text-right">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" className="h-8 w-8 p-0">
- <span className="sr-only">Open menu</span>
- <MoreHorizontal className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DropdownMenuItem>Edit Link</DropdownMenuItem>
- <DropdownMenuItem>Make copy</DropdownMenuItem>
- <DropdownMenuSeparator />
- <DropdownMenuItem className="text-red-500 focus:text-red-200 focus:bg-red-900">
- Delete
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- </TableCell>
- </TableRow>
+ <Collapsible asChild>
+ <>
+ <TableRow key={link.id} className="group/row">
+ <TableCell>{link.name || "No link name"}</TableCell>
+ <TableCell className="min-w-[260px] sm:min-w-[450px]">
+ <div className="group/cell flex items-center gap-x-4 rounded-md bg-gray-700 px-3 py-1 group-hover/row:ring-1 group-hover/row:ring-gray-100 hover:bg-gray-200 transition-all">
+ <div className="whitespace-nowrap hidden sm:flex text-sm text-gray-300 group-hover/cell:hidden">{`https://papermark.io/view/${link.id}`}</div>
+ <div className="flex sm:hidden whitespace-nowrap text-sm text-gray-300 group-hover/cell:hidden">{`${link.id}`}</div>
+ <button
+ className="whitespace-nowrap text-sm text-center text-black hidden group-hover/cell:block w-full"
+ onClick={() => handleCopyToClipboard(link.id)}
+ title="Copy to clipboard"
+ >
+ Copy to Clipboard
+ </button>
+ </div>
+ </TableCell>
+ <TableCell>
+ <CollapsibleTrigger asChild>
+ <div className="flex items-center space-x-1">
+ <BarChart className="h-4 w-4 text-gray-400" />
+ <p className="whitespace-nowrap text-sm text-gray-400">
+ {nFormatter(link._count.views)}
+ <span className="ml-1 hidden sm:inline-block">
+ views
+ </span>
+ </p>
+ </div>
+ </CollapsibleTrigger>
+ </TableCell>
+ <TableCell className="text-sm text-gray-400">
+ {link.views[0] ? (
+ <time
+ dateTime={new Date(
+ link.views[0].viewedAt
+ ).toISOString()}
+ >
+ {timeAgo(link.views[0].viewedAt)}
+ </time>
+ ) : (
+ "-"
+ )}
+ </TableCell>
+ <TableCell className="text-right">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" className="h-8 w-8 p-0">
+ <span className="sr-only">Open menu</span>
+ <MoreHorizontal className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuItem>Edit Link</DropdownMenuItem>
+ <DropdownMenuItem>Make copy</DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem className="text-red-500 focus:text-red-200 focus:bg-red-900">
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ <CollapsibleContent asChild>
+ <TableRow className="bg-gray-700 hover:bg-gray-700">
+ <TableCell colSpan={5}>
+ Yes. Free to use for personal and commercial projects.
+ No attribution required.
+ </TableCell>
+ </TableRow>
+ </CollapsibleContent>
+ </>
+ </Collapsible>
))
) : (
<TableRow>
diff --git a/components/ui/collapsible.tsx b/components/ui/collapsible.tsx
new file mode 100644
index 00000000..a23e7a28
--- /dev/null
+++ b/components/ui/collapsible.tsx
@@ -0,0 +1,9 @@
+import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
+
+const Collapsible = CollapsiblePrimitive.Root
+
+const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
+
+const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
+
+export { Collapsible, CollapsibleTrigger, CollapsibleContent }
diff --git a/package-lock.json b/package-lock.json
index b116945c..b2d8ea40 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15,6 +15,7 @@
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^4.16.2",
"@radix-ui/react-checkbox": "^1.0.4",
+ "@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-separator": "^1.0.3",
@@ -1383,6 +1384,36 @@
}
}
},
+ "node_modules/@radix-ui/react-collapsible": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-collapsible/-/react-collapsible-1.0.3.tgz",
+ "integrity": "sha512-UBmVDkmR6IvDsloHVN+3rtx4Mi5TFvylYXpluuv0f37dtaz3H99bp8No0LGXRigVpl3UAT4l9j6bIchh42S/Gg==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.1",
+ "@radix-ui/react-compose-refs": "1.0.1",
+ "@radix-ui/react-context": "1.0.1",
+ "@radix-ui/react-id": "1.0.1",
+ "@radix-ui/react-presence": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-use-controllable-state": "1.0.1",
+ "@radix-ui/react-use-layout-effect": "1.0.1"
+ },
+ "peerDependencies": {
+ "@types/react": "*",
+ "@types/react-dom": "*",
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "@types/react-dom": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@radix-ui/react-collection": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz",
@@ -10163,6 +10194,22 @@
"@radix-ui/react-use-size": "1.0.1"
}
},
+ "@radix-ui/react-collapsible": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-collapsible/-/react-collapsible-1.0.3.tgz",
+ "integrity": "sha512-UBmVDkmR6IvDsloHVN+3rtx4Mi5TFvylYXpluuv0f37dtaz3H99bp8No0LGXRigVpl3UAT4l9j6bIchh42S/Gg==",
+ "requires": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.1",
+ "@radix-ui/react-compose-refs": "1.0.1",
+ "@radix-ui/react-context": "1.0.1",
+ "@radix-ui/react-id": "1.0.1",
+ "@radix-ui/react-presence": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-use-controllable-state": "1.0.1",
+ "@radix-ui/react-use-layout-effect": "1.0.1"
+ }
+ },
"@radix-ui/react-collection": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz",
diff --git a/package.json b/package.json
index 8c1bfe4e..71a756e6 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"@next-auth/prisma-adapter": "^1.0.7",
"@prisma/client": "^4.16.2",
"@radix-ui/react-checkbox": "^1.0.4",
+ "@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-separator": "^1.0.3",