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.

add exclude root domains

Steven Teyaf56ac9b0100
diff --git a/apps/web/lib/stats.ts b/apps/web/lib/stats.ts
index bdf346bc5e..b1c57a64e6 100644
--- a/apps/web/lib/stats.ts
+++ b/apps/web/lib/stats.ts
@@ -85,6 +85,7 @@ export const VALID_STATS_FILTERS = [
"browser",
"os",
"referer",
+ "excludeRoot",
];
export const getStats = async ({
diff --git a/apps/web/ui/stats/clicks.tsx b/apps/web/ui/stats/clicks.tsx
index 38ce96f0ed..c0c231bd01 100644
--- a/apps/web/ui/stats/clicks.tsx
+++ b/apps/web/ui/stats/clicks.tsx
@@ -51,7 +51,7 @@ export default function Clicks() {
del: ["domain", "key"],
});
}}
- className="flex items-center space-x-1 rounded-md bg-gray-50 px-2 py-1 text-sm text-gray-500 transition-all duration-75 hover:bg-gray-100 active:scale-[0.98] sm:px-3"
+ className="flex items-center space-x-1 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 text-sm text-gray-500 transition-all hover:bg-gray-100"
>
<p>Link</p>
<strong className="text-gray-800">
@@ -66,7 +66,7 @@ export default function Clicks() {
del: "domain",
});
}}
- className="flex items-center space-x-1 rounded-md bg-gray-50 px-2 py-1 text-sm text-gray-500 transition-all duration-75 hover:bg-gray-100 active:scale-[0.98] sm:px-3"
+ className="flex items-center space-x-1 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 text-sm text-gray-500 transition-all hover:bg-gray-100"
>
<p>Domain</p>
<strong className="text-gray-800">{domain}</strong>
@@ -75,7 +75,7 @@ export default function Clicks() {
))}
{VALID_STATS_FILTERS.map((filter) => {
const value = searchParams?.get(filter);
- if (!value) return null;
+ if (!value || filter === "excludeRoot") return null;
return (
<button
onClick={() => {
@@ -83,7 +83,7 @@ export default function Clicks() {
del: filter,
});
}}
- className="flex items-center space-x-1 rounded-md bg-gray-50 px-2 py-1 text-sm text-gray-500 transition-all duration-75 hover:bg-gray-100 active:scale-[0.98] sm:px-3"
+ className="flex items-center space-x-1 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 text-sm text-gray-500 transition-all hover:bg-gray-100"
>
<p>{capitalize(filter)}</p>
<strong className="text-gray-800">
diff --git a/apps/web/ui/stats/index.tsx b/apps/web/ui/stats/index.tsx
index 5b0dc9a959..894385d899 100644
--- a/apps/web/ui/stats/index.tsx
+++ b/apps/web/ui/stats/index.tsx
@@ -8,13 +8,7 @@
We use the `useEndpoint()` hook to get the correct layout
*/
-import { X } from "lucide-react";
-import {
- useParams,
- usePathname,
- useRouter,
- useSearchParams,
-} from "next/navigation";
+import { useParams, usePathname, useSearchParams } from "next/navigation";
import { createContext, useMemo } from "react";
import Clicks from "./clicks";
import TopLinks from "./top-links";
@@ -46,7 +40,6 @@ export const StatsContext = createContext<{
export default function Stats({ staticDomain }: { staticDomain?: string }) {
const searchParams = useSearchParams();
const pathname = usePathname();
- const router = useRouter();
let { slug, key } = useParams() as {
slug?: string;
diff --git a/apps/web/ui/stats/top-links.tsx b/apps/web/ui/stats/top-links.tsx
index 1088888c52..7400db93bc 100644
--- a/apps/web/ui/stats/top-links.tsx
+++ b/apps/web/ui/stats/top-links.tsx
@@ -1,4 +1,4 @@
-import { LoadingSpinner, Modal, useRouterStuff } from "@dub/ui";
+import { LoadingSpinner, Modal, Switch, useRouterStuff } from "@dub/ui";
import { fetcher, linkConstructor } from "@dub/utils";
import { Maximize, X } from "lucide-react";
import { useContext, useEffect, useState } from "react";
@@ -6,6 +6,7 @@ import useSWR from "swr";
import { StatsContext } from ".";
import BarList from "./bar-list";
import { TopLinksTabs } from "@/lib/stats";
+import { useSearchParams } from "next/navigation";
export default function TopLinks() {
const [tab, setTab] = useState<TopLinksTabs>("link");
@@ -27,6 +28,8 @@ export default function TopLinks() {
>(`${baseApiPath}/top_${tab}s?${queryString}`, fetcher);
const { queryParams } = useRouterStuff();
+ const searchParams = useSearchParams();
+ const excludeRoot = !!searchParams.get("excludeRoot");
const [showModal, setShowModal] = useState(false);
const barList = (limit?: number) => (
@@ -81,9 +84,9 @@ export default function TopLinks() {
<h1 className="text-lg font-semibold capitalize">
Top {tab === "link" ? "Links" : "URLs"}
</h1>
- {domain && key && (
+ {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"
+ className="flex items-center space-x-1 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 text-sm text-gray-500 transition-all hover:bg-gray-100"
onClick={() => {
queryParams({
del: ["domain", "key"],
@@ -95,6 +98,31 @@ export default function TopLinks() {
</strong>
<X className="h-4 w-4" />
</button>
+ ) : (
+ <button
+ onClick={() => {
+ if (excludeRoot) {
+ queryParams({
+ del: "excludeRoot",
+ });
+ } else {
+ queryParams({
+ set: {
+ excludeRoot: "true",
+ },
+ });
+ }
+ }}
+ className="flex items-center space-x-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 hover:bg-gray-100"
+ >
+ <p className="text-sm font-medium">Exclude Root Domains</p>
+ <Switch
+ checked={excludeRoot}
+ trackDimensions="h-3 w-6"
+ thumbDimensions="w-2 h-2"
+ thumbTranslate="translate-x-3"
+ />
+ </button>
)}
</div>
{data ? (
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 50dc7a4f49..5ff4ecc298 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -45,6 +45,7 @@
"@radix-ui/react-switch": "^1.0.1",
"@radix-ui/react-tooltip": "^1.0.7",
"class-variance-authority": "^0.7.0",
+ "framer-motion": "^10.16.16",
"js-cookie": "^3.0.5",
"linkify-react": "^4.1.3",
"lucide-react": "^0.284.0",
diff --git a/packages/ui/src/switch.tsx b/packages/ui/src/switch.tsx
index c7b1f5ff80..47e453a2f3 100644
--- a/packages/ui/src/switch.tsx
+++ b/packages/ui/src/switch.tsx
@@ -14,7 +14,7 @@ export function Switch({
disabled = false,
disabledTooltip,
}: {
- fn: Dispatch<SetStateAction<boolean>> | (() => void);
+ fn?: Dispatch<SetStateAction<boolean>> | (() => void);
trackDimensions?: string;
thumbDimensions?: string;
thumbTranslate?: string;
@@ -36,7 +36,7 @@ export function Switch({
<SwitchPrimitive.Root
checked={checked}
name="switch"
- onCheckedChange={(checked) => fn(checked)}
+ {...(fn && { onCheckedChange: fn })}
disabled={disabled}
className={cn(
disabled
diff --git a/packages/ui/src/tab-select.tsx b/packages/ui/src/tab-select.tsx
index 7a26a97b4e..9e5e88c65e 100644
--- a/packages/ui/src/tab-select.tsx
+++ b/packages/ui/src/tab-select.tsx
@@ -1,3 +1,6 @@
+import { cn } from "@dub/utils";
+import { motion } from "framer-motion";
+
export function TabSelect({
options,
selected,
@@ -8,18 +11,27 @@ export function TabSelect({
selectAction: (option: string) => void;
}) {
return (
- <div className="relative inline-flex items-center space-x-3">
+ <div className="relative inline-flex items-center space-x-1">
{options.map((option) => (
<button
key={option}
- className={`${
- option === selected
- ? "bg-gray-200 text-gray-800"
- : "bg-gray-50 text-gray-600 hover:bg-gray-100"
- } rounded-md px-2 py-1 text-sm font-medium capitalize transition-all duration-75 active:scale-95 sm:px-3`}
+ className={cn(
+ "relative z-10 px-3 py-1 text-sm font-medium capitalize",
+ {
+ "transition-all hover:text-gray-500": option !== selected,
+ },
+ )}
onClick={() => selectAction(option)}
>
- {option}
+ <p>{option}</p>
+ {option === selected && (
+ <motion.div
+ layoutId={options.join("-")}
+ className="absolute left-0 top-0 h-full h-full w-full w-full rounded-lg border border-gray-200 bg-gray-50"
+ style={{ zIndex: -1 }}
+ transition={{ duration: 0.25 }}
+ />
+ )}
</button>
))}
</div>
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 981b29ee70..1cd72fe6f4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -678,6 +678,9 @@ importers:
class-variance-authority:
specifier: ^0.7.0
version: 0.7.0
+ framer-motion:
+ specifier: ^10.16.16
js-cookie:
specifier: ^3.0.5
version: 3.0.5
@@ -775,7 +778,7 @@ importers:
version: link:../tsconfig
tsup:
specifier: ^6.1.3
+ version: 6.1.3([email protected])
typescript:
specifier: ^5.1.6
version: 5.1.6
@@ -18110,6 +18113,42 @@ packages:
- ts-node
dev: true
+ resolution: {integrity: sha512-eRpBnbfpDFng+EJNTQ90N7QAf4HAGGC7O3buHIjroKWK7D1ibk9/YnR/3cS8HsMU5T+6Oi+cnF+yU5WmCnB//Q==}
+ engines: {node: '>=14'}
+ hasBin: true
+ peerDependencies:
+ '@swc/core': ^1
+ postcss: ^8.4.12
+ typescript: ^4.1.0
+ peerDependenciesMeta:
+ '@swc/core':
+ optional: true
+ postcss:
+ optional: true
+ typescript:
+ optional: true
+ dependencies:
+ bundle-require: 3.1.2([email protected])
+ cac: 6.7.14
+ chokidar: 3.5.3
+ debug: 4.3.4
+ esbuild: 0.14.54
+ execa: 5.1.1
+ globby: 11.1.0
+ joycon: 3.1.1
+ postcss-load-config: 3.1.4([email protected])
+ resolve-from: 5.0.0
+ rollup: 2.79.1
+ source-map: 0.8.0-beta.0
+ sucrase: 3.34.0
+ tree-kill: 1.2.2
+ typescript: 5.1.6
+ transitivePeerDependencies:
+ - supports-color
+ - ts-node
+ dev: true
+
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
engines: {node: '>= 6'}