Skip to content

Open source CapCut alternative.

TypeScript

feat(site): analytics splits into Product and Social tabs

David Le22a43697b1b7
diff --git a/site/src/app/su/SuHeader.tsx b/site/src/app/su/SuHeader.tsx
index 620330c9..c5f1982d 100644
--- a/site/src/app/su/SuHeader.tsx
+++ b/site/src/app/su/SuHeader.tsx
@@ -2,24 +2,22 @@
import { usePathname } from "next/navigation";
-import { SU_NAV } from "@/app/su/nav";
+import { suSurfaceAt } from "@/app/su/nav";
-// Every surface owns a path, so the match is exact; an address outside the
-// rail falls back to the entry the section root opens.
+// The title is the surface's; the description and action belong to whichever
+// tab is showing, since a section's tabs each drive their own work.
export function SuHeader() {
const pathname = usePathname();
- const section = SU_NAV.find((s) => s.href === pathname) ?? SU_NAV[0];
+ const { surface, tab } = suSurfaceAt(pathname);
return (
<div className="sticky top-0 z-20 mx-auto flex w-full max-w-6xl shrink-0 items-start justify-between gap-4 bg-background px-10 pt-9 pb-4">
<div>
- <h1 className="text-lg font-semibold tracking-tight">{section.title}</h1>
- {section.description ? (
- <p className="mt-1 text-sm text-muted-foreground">
- {section.description}
- </p>
+ <h1 className="text-lg font-semibold tracking-tight">{surface.title}</h1>
+ {tab.description ? (
+ <p className="mt-1 text-sm text-muted-foreground">{tab.description}</p>
) : null}
</div>
- {section.Action ? <section.Action /> : null}
+ {tab.Action ? <tab.Action /> : null}
</div>
);
}
diff --git a/site/src/app/su/SuSidebar.tsx b/site/src/app/su/SuSidebar.tsx
index de479fb2..b360efa2 100644
--- a/site/src/app/su/SuSidebar.tsx
+++ b/site/src/app/su/SuSidebar.tsx
@@ -4,17 +4,22 @@ import Link from "next/link";
import { usePathname } from "next/navigation";
import { ArrowLeft } from "lucide-react";
-import { SU_NAV } from "@/app/su/nav";
+import { SU_NAV, suSurfaceAt } from "@/app/su/nav";
import { SU_APP_ORIGIN } from "@/cut/lib/hosts";
import { cn } from "@/lib/utils";
const itemClass =
"flex items-center gap-2.5 rounded-lg px-2.5 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground";
+// A section's tabs sit beneath it, inset to the label's column.
+const tabClass =
+ "flex items-center rounded-lg py-1.5 pl-[38px] pr-2.5 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground";
+
// The super-user section's left rail: same shell as the app sidebar, with the
// admin surfaces as tabs and a way back to the app pinned to the bottom.
export function SuSidebar() {
const pathname = usePathname();
+ const here = suSurfaceAt(pathname);
return (
<aside className="flex w-60 shrink-0 flex-col border-r border-border bg-card px-3 py-4">
@@ -32,17 +37,33 @@ export function SuSidebar() {
</div>
<nav className="flex flex-col gap-0.5">
- {SU_NAV.map(({ href, label, icon: Icon }) => {
- const active = pathname === href;
+ {SU_NAV.map((surface) => {
+ const { href, label, icon: Icon, tabs } = surface;
+ const active = here.surface === surface;
return (
- <Link
- key={label}
- href={href}
- className={cn(itemClass, active && "bg-muted text-foreground")}
- >
- <Icon className="size-4" />
- {label}
- </Link>
+ <div key={label} className="flex flex-col gap-0.5">
+ <Link
+ href={href}
+ className={cn(itemClass, active && !tabs && "bg-muted text-foreground")}
+ >
+ <Icon className="size-4" />
+ {label}
+ </Link>
+ {tabs && active
+ ? tabs.map((tab) => (
+ <Link
+ key={tab.href}
+ href={tab.href}
+ className={cn(
+ tabClass,
+ here.tab === tab && "bg-muted font-medium text-foreground",
+ )}
+ >
+ {tab.label}
+ </Link>
+ ))
+ : null}
+ </div>
);
})}
</nav>
diff --git a/site/src/app/su/analytics/page.tsx b/site/src/app/su/analytics/page.tsx
new file mode 100644
index 00000000..75d67c29
--- /dev/null
+++ b/site/src/app/su/analytics/page.tsx
@@ -0,0 +1,8 @@
+import { redirect } from "next/navigation";
+
+import { SU_NAV } from "@/app/su/nav";
+
+// The section has no surface of its own; it opens its first tab.
+export default function SuAnalyticsPage() {
+ redirect(SU_NAV[0].tabs![0].href);
+}
diff --git a/site/src/app/su/analytics/social/page.tsx b/site/src/app/su/analytics/social/page.tsx
new file mode 100644
index 00000000..8eb788bc
--- /dev/null
+++ b/site/src/app/su/analytics/social/page.tsx
@@ -0,0 +1,9 @@
+"use client";
+
+export default function SuSocialAnalyticsPage() {
+ return (
+ <div className="flex h-full items-center justify-center pb-9">
+ <p className="text-sm text-muted-foreground">No social data yet.</p>
+ </div>
+ );
+}
diff --git a/site/src/app/su/nav.ts b/site/src/app/su/nav.ts
index fc4cac2e..8a0cfcd9 100644
--- a/site/src/app/su/nav.ts
+++ b/site/src/app/su/nav.ts
@@ -9,22 +9,33 @@ import { ScanOutreachButton } from "@/app/su/outreach/ScanOutreachButton";
// the header's title and action — so adding a surface is one edit here and a
// page.tsx. The section root lands on the first entry, so reordering this list
// moves where the host opens.
-export type SuSurface = {
+//
+// A surface with tabs is a section: its href is a folder, each tab is a page
+// under it, and the section's own page redirects to the first tab. The rail
+// opens the tabs beneath the section while any of them is showing.
+export type SuTab = {
href: string;
label: string;
- icon: typeof UserRound;
- title: string;
description?: string;
Action?: ComponentType;
};
+export type SuSurface = SuTab & {
+ icon: typeof UserRound;
+ title: string;
+ tabs?: SuTab[];
+};
+
export const SU_NAV: SuSurface[] = [
{
href: "/analytics",
label: "Analytics",
icon: ChartColumn,
title: "Analytics",
- Action: RunAnalyticsButton,
+ tabs: [
+ { href: "/analytics/product", label: "Product", Action: RunAnalyticsButton },
+ { href: "/analytics/social", label: "Social" },
+ ],
},
{
href: "/users",
@@ -55,3 +66,15 @@ export const SU_NAV: SuSurface[] = [
description: "Background work started from these surfaces, newest first.",
},
];
+
+// The surface an address belongs to, and the tab within it when the surface
+// has tabs. A section address (`/analytics`) resolves to its first tab, the
+// one its page redirects to; an address outside the rail falls back to the
+// entry the section root opens.
+export function suSurfaceAt(pathname: string): { surface: SuSurface; tab: SuTab } {
+ const surface =
+ SU_NAV.find((s) => pathname === s.href || pathname.startsWith(`${s.href}/`)) ??
+ SU_NAV[0];
+ const tab = surface.tabs?.find((t) => t.href === pathname) ?? surface.tabs?.[0] ?? surface;
+ return { surface, tab };
+}