Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Improve tags

Tim Wilson5a3299e9fa5d
diff --git a/apps/web/ui/links/link-controls.tsx b/apps/web/ui/links/link-controls.tsx
index 9485dbca51..101c485d7d 100644
--- a/apps/web/ui/links/link-controls.tsx
+++ b/apps/web/ui/links/link-controls.tsx
@@ -75,184 +75,188 @@ export function LinkControls({ link }: { link: ResponseLink }) {
});
return (
- <div
- ref={ref}
- className={cn(
- "flex items-center justify-end divide-x divide-gray-200 overflow-hidden rounded-md border border-gray-200",
- "sm:divide-transparent sm:border-transparent sm:group-hover/row:divide-gray-200 sm:group-hover/row:border-gray-200", // Only show divider on mobile or when hovered
- "w-[35px] transition-[width] duration-300 sm:group-hover/row:w-[100px]",
- )}
- >
- {isVisible && (
- <>
- <LinkQRModal />
- <AddEditLinkModal />
- <DuplicateLinkModal />
- <ArchiveLinkModal />
- <TransferLinkModal />
- <DeleteLinkModal />
- </>
- )}
- <Button
- icon={<PenWriting className={cn("h-4 w-4 shrink-0")} />}
- variant="outline"
- className="h-8 rounded-none border-0 px-2"
- onClick={() => setShowAddEditLinkModal(true)}
- />
- <Button
- icon={<QRCode className={cn("h-4 w-4 shrink-0")} />}
- variant="outline"
- className="h-8 rounded-none border-0 px-2"
- onClick={() => setShowLinkQRModal(true)}
- />
- <Popover
- content={
- <div className="w-full sm:w-48">
- <div className="grid gap-px p-2">
- <Button
- text="Edit"
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowAddEditLinkModal(true);
- }}
- icon={<PenWriting className="h-4 w-4" />}
- shortcut="E"
- className="h-9 px-2 font-medium"
- />
- <Button
- text="QR Code"
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowLinkQRModal(true);
- }}
- icon={<QRCode className="h-4 w-4" />}
- shortcut="Q"
- className="h-9 px-2 font-medium"
- />
- <Button
- text="Duplicate"
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowDuplicateLinkModal(true);
- }}
- icon={<CopyPlus className="h-4 w-4" />}
- shortcut="D"
- className="h-9 px-2 font-medium"
- />
- <Button
- text="Copy Link ID"
- variant="outline"
- onClick={() => copyLinkId()}
- icon={
- copiedLinkId ? (
- <CircleCheck className="h-4 w-4" />
- ) : (
- <Copy className="h-4 w-4" />
- )
- }
- shortcut="I"
- className="h-9 px-2 font-medium"
- />
- </div>
- <div className="border-t border-gray-200" />
- <div className="grid gap-px p-2">
- <Button
- text={link.archived ? "Unarchive" : "Archive"}
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowArchiveLinkModal(true);
- }}
- icon={<Archive className="h-4 w-4" />}
- shortcut="A"
- className="h-9 px-2 font-medium"
- />
- <Button
- text="Transfer"
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowTransferLinkModal(true);
- }}
- icon={<FolderInput className="h-4 w-4" />}
- shortcut="T"
- className="h-9 px-2 font-medium"
- {...(!isDubDomain(link.domain) && {
- disabledTooltip: (
- <SimpleTooltipContent
- title="Since this is a custom domain link, you can only transfer it to another workspace if you transfer the domain as well."
- cta="Learn more."
- href="https://dub.co/help/article/how-to-transfer-domains"
- />
- ),
- })}
- />
- {link.key !== "_root" && (
+ <div ref={ref} className="flex justify-end sm:w-[124px]">
+ <div
+ className={cn(
+ "flex items-center justify-end divide-x divide-gray-200 overflow-hidden rounded-md border border-gray-200",
+ "sm:divide-transparent sm:border-transparent sm:group-hover/row:divide-gray-200 sm:group-hover/row:border-gray-200", // Only show divider on mobile or when hovered
+ "w-[43px] transition-[width] duration-300 sm:group-hover/row:w-[124px]",
+ )}
+ >
+ {isVisible && (
+ <>
+ <LinkQRModal />
+ <AddEditLinkModal />
+ <DuplicateLinkModal />
+ <ArchiveLinkModal />
+ <TransferLinkModal />
+ <DeleteLinkModal />
+ </>
+ )}
+ <Button
+ icon={<PenWriting className={cn("h-4 w-4 shrink-0")} />}
+ variant="outline"
+ className="h-8 rounded-none border-0 px-3"
+ onClick={() => setShowAddEditLinkModal(true)}
+ />
+ <Button
+ icon={<QRCode className={cn("h-4 w-4 shrink-0")} />}
+ variant="outline"
+ className="h-8 rounded-none border-0 px-3"
+ onClick={() => setShowLinkQRModal(true)}
+ />
+ <Popover
+ content={
+ <div className="w-full sm:w-48">
+ <div className="grid gap-px p-2">
+ <Button
+ text="Edit"
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowAddEditLinkModal(true);
+ }}
+ icon={<PenWriting className="h-4 w-4" />}
+ shortcut="E"
+ className="h-9 px-2 font-medium"
+ />
<Button
- text="Delete"
- variant="danger-outline"
+ text="QR Code"
+ variant="outline"
onClick={() => {
setOpenPopover(false);
- setShowDeleteLinkModal(true);
+ setShowLinkQRModal(true);
}}
- icon={<Delete className="h-4 w-4" />}
- shortcut="X"
+ icon={<QRCode className="h-4 w-4" />}
+ shortcut="Q"
className="h-9 px-2 font-medium"
/>
- )}
- {!slug && ( // this is only shown in admin mode (where there's no slug)
- <button
+ <Button
+ text="Duplicate"
+ variant="outline"
onClick={() => {
- window.confirm(
- "Are you sure you want to ban this link? It will blacklist the domain and prevent any links from that domain from being created.",
- ) &&
- (setOpenPopover(false),
- toast.promise(
- fetch(`/api/admin/links/ban?key=${link.key}`, {
- method: "DELETE",
- }).then(async () => {
- await mutate(
- (key) =>
- typeof key === "string" &&
- key.startsWith("/api/admin/links/ban"),
- undefined,
- { revalidate: true },
- );
- }),
- {
- loading: "Banning link...",
- success: "Link banned!",
- error: "Error banning link.",
- },
- ));
+ setOpenPopover(false);
+ setShowDuplicateLinkModal(true);
}}
- className="group flex w-full items-center justify-between rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"
- >
- <IconMenu text="Ban" icon={<Delete className="h-4 w-4" />} />
- <kbd className="hidden rounded bg-red-100 px-2 py-0.5 text-xs font-light text-red-600 transition-all duration-75 group-hover:bg-red-500 group-hover:text-white sm:inline-block">
- B
- </kbd>
- </button>
- )}
+ icon={<CopyPlus className="h-4 w-4" />}
+ shortcut="D"
+ className="h-9 px-2 font-medium"
+ />
+ <Button
+ text="Copy Link ID"
+ variant="outline"
+ onClick={() => copyLinkId()}
+ icon={
+ copiedLinkId ? (
+ <CircleCheck className="h-4 w-4" />
+ ) : (
+ <Copy className="h-4 w-4" />
+ )
+ }
+ shortcut="I"
+ className="h-9 px-2 font-medium"
+ />
+ </div>
+ <div className="border-t border-gray-200" />
+ <div className="grid gap-px p-2">
+ <Button
+ text={link.archived ? "Unarchive" : "Archive"}
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowArchiveLinkModal(true);
+ }}
+ icon={<Archive className="h-4 w-4" />}
+ shortcut="A"
+ className="h-9 px-2 font-medium"
+ />
+ <Button
+ text="Transfer"
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowTransferLinkModal(true);
+ }}
+ icon={<FolderInput className="h-4 w-4" />}
+ shortcut="T"
+ className="h-9 px-2 font-medium"
+ {...(!isDubDomain(link.domain) && {
+ disabledTooltip: (
+ <SimpleTooltipContent
+ title="Since this is a custom domain link, you can only transfer it to another workspace if you transfer the domain as well."
+ cta="Learn more."
+ href="https://dub.co/help/article/how-to-transfer-domains"
+ />
+ ),
+ })}
+ />
+ {link.key !== "_root" && (
+ <Button
+ text="Delete"
+ variant="danger-outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowDeleteLinkModal(true);
+ }}
+ icon={<Delete className="h-4 w-4" />}
+ shortcut="X"
+ className="h-9 px-2 font-medium"
+ />
+ )}
+ {!slug && ( // this is only shown in admin mode (where there's no slug)
+ <button
+ onClick={() => {
+ window.confirm(
+ "Are you sure you want to ban this link? It will blacklist the domain and prevent any links from that domain from being created.",
+ ) &&
+ (setOpenPopover(false),
+ toast.promise(
+ fetch(`/api/admin/links/ban?key=${link.key}`, {
+ method: "DELETE",
+ }).then(async () => {
+ await mutate(
+ (key) =>
+ typeof key === "string" &&
+ key.startsWith("/api/admin/links/ban"),
+ undefined,
+ { revalidate: true },
+ );
+ }),
+ {
+ loading: "Banning link...",
+ success: "Link banned!",
+ error: "Error banning link.",
+ },
+ ));
+ }}
+ className="group flex w-full items-center justify-between rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"
+ >
+ <IconMenu
+ text="Ban"
+ icon={<Delete className="h-4 w-4" />}
+ />
+ <kbd className="hidden rounded bg-red-100 px-2 py-0.5 text-xs font-light text-red-600 transition-all duration-75 group-hover:bg-red-500 group-hover:text-white sm:inline-block">
+ B
+ </kbd>
+ </button>
+ )}
+ </div>
</div>
- </div>
- }
- align="end"
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- >
- <Button
- variant="outline"
- className="h-8 rounded-none border-0 px-1.5 transition-[border-color] duration-200"
- icon={<ThreeDots className="h-5 w-5 shrink-0" />}
- onClick={() => {
- setOpenPopover(!openPopover);
- }}
- />
- </Popover>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <Button
+ variant="outline"
+ className="h-8 rounded-none border-0 px-2.5 transition-[border-color] duration-200"
+ icon={<ThreeDots className="h-5 w-5 shrink-0" />}
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ />
+ </Popover>
+ </div>
</div>
);
}
diff --git a/apps/web/ui/links/link-details-column.tsx b/apps/web/ui/links/link-details-column.tsx
index 924923583d..cd0251e3b9 100644
--- a/apps/web/ui/links/link-details-column.tsx
+++ b/apps/web/ui/links/link-details-column.tsx
@@ -1,6 +1,6 @@
import { CompositeAnalyticsResponseOptions } from "@/lib/analytics/types";
import useWorkspace from "@/lib/swr/use-workspace";
-import { Crosshairs, useIntersectionObserver } from "@dub/ui";
+import { Crosshairs, Tooltip, useIntersectionObserver } from "@dub/ui";
import { CursorRays, InvoiceDollar } from "@dub/ui/src/icons";
import { fetcher, nFormatter } from "@dub/utils";
import Link from "next/link";
@@ -19,7 +19,7 @@ export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
const isVisible = !!entry?.isIntersecting;
const { id: workspaceId, slug, exceededClicks } = useWorkspace();
- const { primaryTags, additionalTags } = useOrganizedTags(tags);
+ const { primaryTag, additionalTags } = useOrganizedTags(tags);
const { data: totalEvents } = useSWR<{
[key in CompositeAnalyticsResponseOptions]?: number;
@@ -42,11 +42,22 @@ export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
return (
<div ref={ref} className="flex items-center justify-end gap-5">
- <div className="flex items-center gap-2">
- {primaryTags.map((tag) => (
- <TagBadge key={tag.id} {...tag} />
- ))}
- </div>
+ {primaryTag && (
+ <Tooltip
+ content={
+ <div className="flex flex-wrap gap-1.5 p-3">
+ {tags.map((tag) => (
+ <TagBadge key={tag.id} {...tag} />
+ ))}
+ </div>
+ }
+ side="bottom"
+ >
+ <div className="cursor-default transition-transform hover:scale-105">
+ <TagBadge withIcon {...primaryTag} plus={additionalTags.length} />
+ </div>
+ </Tooltip>
+ )}
<Link
href={`/${slug}/analytics?domain=${domain}&key=${key}`}
className="flex items-center gap-3 rounded-md bg-gray-100 px-2 py-0.5 text-sm text-gray-950 transition-colors hover:bg-gray-200"
@@ -66,9 +77,7 @@ export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
</div>
))}
</Link>
- <div className="ml-2">
- <LinkControls link={link} />
- </div>
+ <LinkControls link={link} />
</div>
);
}
@@ -76,9 +85,7 @@ export function LinkDetailsColumn({ link }: { link: ResponseLink }) {
function useOrganizedTags(tags: ResponseLink["tags"]) {
const searchParams = useSearchParams();
- const [primaryTags, additionalTags] = useMemo(() => {
- const primaryTagsCount = 1;
-
+ const [primaryTag, additionalTags] = useMemo(() => {
const filteredTagIds =
searchParams?.get("tagIds")?.split(",")?.filter(Boolean) ?? [];
@@ -94,11 +101,8 @@ function useOrganizedTags(tags: ResponseLink["tags"]) {
)
: tags;
- return [
- sortedTags.filter((_, idx) => idx < primaryTagsCount),
- sortedTags.filter((_, idx) => idx >= primaryTagsCount),
- ];
+ return [sortedTags?.[0], sortedTags.slice(1)];
}, [tags, searchParams]);
- return { primaryTags, additionalTags };
+ return { primaryTag, additionalTags };
}
diff --git a/apps/web/ui/links/tag-badge.tsx b/apps/web/ui/links/tag-badge.tsx
index a28c979b0c..0a7014151c 100644
--- a/apps/web/ui/links/tag-badge.tsx
+++ b/apps/web/ui/links/tag-badge.tsx
@@ -6,17 +6,19 @@ export default function TagBadge({
name,
color,
withIcon,
+ plus,
}: {
name: string;
color: TagColorProps;
withIcon?: boolean;
+ plus?: number;
}) {
return (
<span
className={cn(
"my-auto whitespace-nowrap rounded-md px-2 py-0.5 text-sm",
- withIcon &&
- "flex items-center space-x-1.5 rounded-full p-1.5 sm:rounded-md sm:px-2 sm:py-0.5",
+ (withIcon || plus) &&
+ "flex items-center gap-x-1.5 rounded-full p-1.5 sm:rounded-md sm:px-2 sm:py-0.5",
color === "red" && "bg-red-100 text-red-600",
color === "yellow" && "bg-yellow-100 text-yellow-600",
color === "green" && "bg-green-100 text-green-600",
@@ -29,6 +31,11 @@ export default function TagBadge({
<p {...(withIcon && { className: "hidden sm:inline-block" })}>
{truncate(name || "", 24)}
</p>
+ {plus && (
+ <span>
+ <span className="pl-1 pr-2.5 opacity-30">|</span>+{plus}
+ </span>
+ )}
</span>
);
}
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index b0e94c52f1..4e8c21f53d 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -76,7 +76,7 @@ const tableCellVariants = cva(
variants: {
variant: {
default: "border-r border-b", // Right and left borders, removed from outer columns above
- "compact-list": "border-b bg-white", // Bottom border, with other sides added above
+ "compact-list": "border-b", // Bottom border, with other sides added above
"loose-list": "border-y bg-white", // Top and bottom borders, with other sides added above
},
},