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.

finalize changes

Steven Teybf9c51591f5e
diff --git a/apps/web/lib/stats.ts b/apps/web/lib/stats.ts
index 4ab8cacbf3..bdf346bc5e 100644
--- a/apps/web/lib/stats.ts
+++ b/apps/web/lib/stats.ts
@@ -58,8 +58,8 @@ export const intervalData = {
},
};
-export type LocationTabs = "country" | "city" | "region";
-export type TopLinksTabs = "link" | "url" | "alias";
+export type LocationTabs = "country" | "city";
+export type TopLinksTabs = "link" | "url";
export type DeviceTabs = "device" | "browser" | "os" | "ua";
const VALID_TINYBIRD_ENDPOINTS = [
@@ -67,7 +67,7 @@ const VALID_TINYBIRD_ENDPOINTS = [
"clicks",
"top_links",
"top_urls",
- "top_aliases",
+ // "top_aliases",
"country",
"city",
"device",
diff --git a/apps/web/scripts/format-links.ts b/apps/web/scripts/format-links.ts
index c30c41ae6c..057794492e 100644
--- a/apps/web/scripts/format-links.ts
+++ b/apps/web/scripts/format-links.ts
@@ -53,7 +53,7 @@ async function main() {
projectId: undefined,
link_id: obj.id,
url: obj.url || "",
- team_id: obj.projectId || "",
+ project_id: obj.projectId || "",
deleted: 0,
}) + "\n",
);
diff --git a/apps/web/ui/stats/index.tsx b/apps/web/ui/stats/index.tsx
index a5721d9156..5b0dc9a959 100644
--- a/apps/web/ui/stats/index.tsx
+++ b/apps/web/ui/stats/index.tsx
@@ -22,7 +22,6 @@ import Devices from "./devices";
import Locations from "./locations";
import Referer from "./referer";
import Toggle from "./toggle";
-import Feedback from "./feedback";
import useSWR from "swr";
import { fetcher } from "@dub/utils";
import { VALID_STATS_FILTERS } from "@/lib/stats";
@@ -35,7 +34,6 @@ export const StatsContext = createContext<{
queryString: string;
interval: string;
totalClicks?: number;
- modal?: boolean;
}>({
basePath: "",
baseApiPath: "",
@@ -45,13 +43,7 @@ export const StatsContext = createContext<{
interval: "",
});
-export default function Stats({
- staticDomain,
- modal,
-}: {
- staticDomain?: string;
- modal?: boolean;
-}) {
+export default function Stats({ staticDomain }: { staticDomain?: string }) {
const searchParams = useSearchParams();
const pathname = usePathname();
const router = useRouter();
@@ -116,17 +108,8 @@ export default function Stats({
key: key ? decodeURIComponent(key) : undefined, // link key (e.g. github, weathergpt, etc.)
interval, // time interval (e.g. 24h, 7d, 30d, etc.)
totalClicks, // total clicks for the link
- modal, // whether or not this is a modal
}}
>
- {modal && (
- <button
- className="group sticky right-4 top-4 z-30 float-right hidden rounded-full p-3 transition-all duration-75 hover:bg-gray-100 focus:outline-none active:scale-75 md:block"
- onClick={() => router.back()}
- >
- <X className="h-6 w-6" />
- </button>
- )}
<div className="bg-gray-50 py-10">
<Toggle />
<div className="mx-auto grid max-w-4xl gap-5">
diff --git a/apps/web/ui/stats/toggle.tsx b/apps/web/ui/stats/toggle.tsx
index fcd0e45924..2bcf5fbac2 100644
--- a/apps/web/ui/stats/toggle.tsx
+++ b/apps/web/ui/stats/toggle.tsx
@@ -40,7 +40,7 @@ export default function Toggle() {
const { slug } = useParams() as { slug?: string };
const { queryParams } = useRouterStuff();
- const { basePath, domain, key, interval, modal } = useContext(StatsContext);
+ const { basePath, domain, key, interval } = useContext(StatsContext);
const [openDatePopover, setOpenDatePopover] = useState(false);
@@ -59,8 +59,7 @@ export default function Toggle() {
<div
className={cn("sticky top-[6.85rem] z-10 mb-5 bg-gray-50 py-3 md:py-5", {
"top-14": isPublicStatsPage,
- "top-6 md:top-0": modal,
- "shadow-md": scrolled && !modal,
+ "shadow-md": scrolled,
})}
>
<div className="mx-auto flex h-20 max-w-4xl flex-col items-center justify-between space-y-3 px-2.5 md:h-10 md:flex-row md:space-y-0 lg:px-0">
diff --git a/apps/web/ui/stats/top-links.tsx b/apps/web/ui/stats/top-links.tsx
index e9f7de11e6..1088888c52 100644
--- a/apps/web/ui/stats/top-links.tsx
+++ b/apps/web/ui/stats/top-links.tsx
@@ -1,7 +1,7 @@
-import { LoadingSpinner, Modal, TabSelect, useRouterStuff } from "@dub/ui";
-import { capitalize, fetcher, linkConstructor, truncate } from "@dub/utils";
-import { Maximize } from "lucide-react";
-import { useContext, useState } from "react";
+import { LoadingSpinner, Modal, useRouterStuff } from "@dub/ui";
+import { fetcher, linkConstructor } from "@dub/utils";
+import { Maximize, X } from "lucide-react";
+import { useContext, useEffect, useState } from "react";
import useSWR from "swr";
import { StatsContext } from ".";
import BarList from "./bar-list";
@@ -10,7 +10,15 @@ import { TopLinksTabs } from "@/lib/stats";
export default function TopLinks() {
const [tab, setTab] = useState<TopLinksTabs>("link");
- const { baseApiPath, queryString, modal } = useContext(StatsContext);
+ const { baseApiPath, queryString, domain, key } = useContext(StatsContext);
+
+ useEffect(() => {
+ if (domain && key) {
+ setTab("url");
+ } else {
+ setTab("link");
+ }
+ }, [domain, key]);
const { data } = useSWR<
({ domain: string; key: string } & {
@@ -70,13 +78,24 @@ export default function TopLinks() {
</Modal>
<div className="scrollbar-hide relative z-0 h-[400px] overflow-scroll border border-gray-200 bg-white px-7 py-5 sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
<div className="mb-5 flex justify-between">
- <h1 className="text-lg font-semibold capitalize">Top Links</h1>
- <TabSelect
- options={["link", "url", "alias"]}
- selected={tab}
- // @ts-ignore
- selectAction={setTab}
- />
+ <h1 className="text-lg font-semibold capitalize">
+ Top {tab === "link" ? "Links" : "URLs"}
+ </h1>
+ {domain && key && (
+ <button
+ className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-1 text-sm text-gray-500 transition-all duration-75 hover:bg-gray-100 active:scale-[0.98] sm:px-3"
+ onClick={() => {
+ queryParams({
+ del: ["domain", "key"],
+ });
+ }}
+ >
+ <strong className="text-gray-800">
+ {linkConstructor({ domain, key, pretty: true })}
+ </strong>
+ <X className="h-4 w-4" />
+ </button>
+ )}
</div>
{data ? (
data.length > 0 ? (
@@ -91,7 +110,7 @@ export default function TopLinks() {
<LoadingSpinner />
</div>
)}
- {!modal && data && data.length > 9 && (
+ {data && data.length > 9 && (
<button
onClick={() => setShowModal(true)}
className="absolute inset-x-0 bottom-4 z-10 mx-auto flex w-full items-center justify-center space-x-2 rounded-md bg-gradient-to-b from-transparent to-white py-2 text-gray-500 transition-all hover:text-gray-800 active:scale-95"
diff --git a/packages/tinybird/datasources/dub_links_metadata.datasource b/packages/tinybird/datasources/dub_links_metadata.datasource
index 7e5d80384c..ae5d233acb 100644
--- a/packages/tinybird/datasources/dub_links_metadata.datasource
+++ b/packages/tinybird/datasources/dub_links_metadata.datasource
@@ -4,8 +4,8 @@ SCHEMA >
`domain` String `json:$.domain`,
`key` String `json:$.key`,
`url` String `json:$.url`,
- `team_id` String `json:$.team_id`,
+ `project_id` String `json:$.project_id`,
`deleted` UInt8 `json:$.deleted`
ENGINE "MergeTree"
-ENGINE_SORTING_KEY "timestamp, link_id, team_id, deleted"
\ No newline at end of file
+ENGINE_SORTING_KEY "timestamp, link_id, project_id, deleted"
\ No newline at end of file