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.

display the custom link title on the Short links tab

Kiran K6484af78234b
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index bb0be83764..6ac5e67a43 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -1,7 +1,8 @@
import { LinkLogo, useRouterStuff } from "@dub/ui";
import { Globe, Hyperlink } from "@dub/ui/icons";
import { getApexDomain } from "@dub/utils";
-import { useContext, useState } from "react";
+import { useCallback, useContext, useState } from "react";
+import { useLinksDisplayOption } from "../links/links-display-provider";
import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import { AnalyticsContext } from "./analytics-provider";
@@ -19,6 +20,27 @@ export default function TopLinks() {
groupBy: `top_${tab}`,
});
+ const { value: displayProperties } = useLinksDisplayOption<string[]>(
+ "display-properties",
+ (value) => value,
+ ["link"],
+ );
+
+ const shortLinkTitle = useCallback(
+ (d: { url?: string; title?: string; shortLink?: string }) => {
+ if (tab === "urls") {
+ return d.url || "Unknown";
+ }
+
+ if (displayProperties.includes("title") && d.title) {
+ return d.title;
+ }
+
+ return d.shortLink || "Unknown";
+ },
+ [displayProperties, tab],
+ );
+
return (
<AnalyticsCard
tabs={[
@@ -44,10 +66,7 @@ export default function TopLinks() {
className="size-5 sm:size-5"
/>
),
- title:
- (tab === "links" && d["shortLink"]
- ? d["shortLink"]
- : d.url) ?? "Unknown",
+ title: shortLinkTitle(d as any),
// TODO: simplify this once we switch from domain+key to linkId
href: queryParams({
...((tab === "links" &&
diff --git a/apps/web/ui/links/links-display-provider.tsx b/apps/web/ui/links/links-display-provider.tsx
index 0c465458ff..3f10d7ea80 100644
--- a/apps/web/ui/links/links-display-provider.tsx
+++ b/apps/web/ui/links/links-display-provider.tsx
@@ -74,7 +74,7 @@ export const defaultDisplayProperties: LinkDisplayProperty[] = [
"analytics",
];
-function useLinksDisplayOption<T>(
+export function useLinksDisplayOption<T>(
key: string,
parsePersisted: (value: T) => T,
defaultValue: T,