Open source CapCut alternative.
TypeScript
feat(site): su analytics wraps the referral legend, activity grid leads with paying users and newest days
David Le0eb9c4440f38
diff --git a/site/src/app/cut/app/su/analytics/page.tsx b/site/src/app/cut/app/su/analytics/page.tsxindex 81d40271..f97ee5a7 100644--- a/site/src/app/cut/app/su/analytics/page.tsx+++ b/site/src/app/cut/app/su/analytics/page.tsx@@ -302,6 +302,14 @@ function ActivityGrid({const sources = rollup.sources.filter((_, i) => (mask & (1 << i)) !== 0);return `${email} — ${formatDay(day)}: ${sources.join(", ")}`;};+ // Newest day sits in the leftmost column so the current dots are in view+ // before any horizontal scroll; each column keeps its index into the+ // activity masks.+ const columns = rollup.days.map((day, i) => ({ day, i })).reverse();+ // Paying users first; the stable sort keeps recency within each group.+ const users = [...rollup.users].sort(+ (a, b) => Number(b.fundedMicros !== undefined) - Number(a.fundedMicros !== undefined),+ );return (<div className="rounded-xl border bg-card p-5"><p className="font-medium">User activity</p>@@ -314,18 +322,18 @@ function ActivityGrid({<thead><tr><th className="sticky left-0 z-10 bg-card" />- {rollup.days.map((day, i) => (+ {columns.map(({ day }, col) => (<thkey={day}className="pb-2 text-left text-[10px] font-normal whitespace-nowrap text-muted-foreground">- {i === 0 || day.endsWith("-01") ? formatDay(day) : ""}+ {col === 0 || day.endsWith("-01") ? formatDay(day) : ""}</th>))}</tr></thead><tbody>- {rollup.users.map((user) => (+ {users.map((user) => (<tr key={user.id}><td className="sticky left-0 z-10 bg-card py-1 pr-4 whitespace-nowrap"><span className="block max-w-56 truncate text-sm" title={user.name}>@@ -334,9 +342,15 @@ function ActivityGrid({<span className="block text-xs text-muted-foreground">Joined {formatDay(user.registeredAt.slice(0, 10))} ·{" "}{formatMicros(BigInt(user.balanceMicros))}+ {user.fundedMicros !== undefined && (+ <span className="text-emerald-700 dark:text-emerald-500">+ {" "}+ · paid {formatMicros(BigInt(user.fundedMicros))}+ </span>+ )}</span></td>- {rollup.days.map((day, i) => (+ {columns.map(({ day, i }) => (<td key={day} className="p-0.5"><ActivityDotlabel={dotLabel(user.email, day, user.activity[i] ?? 0)}@@ -618,11 +632,21 @@ export default function SuAnalyticsPage() {stackId="sources"/>))}- {/* Recharts 3 sorts legend items by name by default; null keeps- the series order, which is the survey's order. */}- <ChartLegend content={<ChartLegendContent />} itemSorter={null} /></BarChart></ChartContainer>+ {/* The legend renders as its own row below the plot, in the+ survey's order, so it wraps freely at narrow widths. */}+ <div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs text-muted-foreground">+ {Object.entries(referrals.config).map(([id, entry]) => (+ <span key={id} className="flex items-center gap-1.5 whitespace-nowrap">+ <span+ className="size-2 shrink-0 rounded-full"+ style={{ background: "color" in entry ? entry.color : undefined }}+ />+ {entry.label}+ </span>+ ))}+ </div></ChartCard><ChartCarddiff --git a/site/src/lib/analytics/pipeline.ts b/site/src/lib/analytics/pipeline.tsindex d941ad51..d6a0506d 100644--- a/site/src/lib/analytics/pipeline.ts+++ b/site/src/lib/analytics/pipeline.ts@@ -320,15 +320,26 @@ async function consolidate(}const balanceByUser = new Map(snapshot.balances.map((b) => [b.userId, b.balanceMicros]));+ const fundedByUser = new Map<string, bigint>();+ for (const payment of snapshot.payments) {+ fundedByUser.set(+ payment.userId,+ (fundedByUser.get(payment.userId) ?? BigInt(0)) + BigInt(payment.amountMicros),+ );+ }const users = snapshot.users- .map((u) => ({- activity: masks.get(u.id) ?? days.map(() => 0),- balanceMicros: balanceByUser.get(u.id) ?? "0",- email: u.email,- id: u.id,- name: u.name,- registeredAt: u.createdAt,- }))+ .map((u) => {+ const funded = fundedByUser.get(u.id);+ return {+ activity: masks.get(u.id) ?? days.map(() => 0),+ balanceMicros: balanceByUser.get(u.id) ?? "0",+ email: u.email,+ ...(funded !== undefined ? { fundedMicros: funded.toString() } : {}),+ id: u.id,+ name: u.name,+ registeredAt: u.createdAt,+ };+ }).sort((a, b) => (a.registeredAt < b.registeredAt ? 1 : -1));const rollup: AnalyticsRollup = {diff --git a/site/src/lib/analytics/schema.ts b/site/src/lib/analytics/schema.tsindex 32edf1fc..9004e9b5 100644--- a/site/src/lib/analytics/schema.ts+++ b/site/src/lib/analytics/schema.ts@@ -155,6 +155,9 @@ export const analyticsRollupSchema = z.object({registeredAt: z.string(),// BigInt micros as a decimal string; "0" for users without an account row.balanceMicros: z.string(),+ // All-time paid Stripe grants, BigInt micros as a decimal string. Absent+ // for users who never paid and in rollups written before this shipped.+ fundedMicros: z.string().optional(),// One mask per entry of days; a dot is mask !== 0.activity: z.array(z.number()),}),