Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
278 changes: 278 additions & 0 deletions dashboard/e2e/delivery-overview.spec.ts

Large diffs are not rendered by default.

94 changes: 2 additions & 92 deletions dashboard/src/app/analytics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ import { Bar, BarChart, CartesianGrid, Legend, Line, LineChart, ResponsiveContai
import { api, type Analytics, type Stats, type AnalyticsCiOutcomes, type AnalyticsComparison, type AnalyticsCounts, type AnalyticsPeriod } from "@/lib/api";
import { CardSkeleton, ChartSkeleton } from "@/components/skeleton";
import { StatGrid, StatTile } from "@/components/stat-tile";
import { DataTable, type Column } from "@/components/data-table";
import { Problem } from "@/components/problem";
import { Tabs } from "@/components/tabs";
import { useSearchParams } from "next/navigation";
import { Segmented } from "@/components/segmented";
import { Callout } from "@/components/callout";
import { focusRing, inputClass } from "@/components/ui";
import { inputClass } from "@/components/ui";
import { Page, PageHeader, Section } from "@/components/page";
import { RepoFilter, formatDuration } from "@/components/list";

// Categorical slots for the dark chart surface, checked for color-vision
// separation and contrast (blue, orange). Text never takes a series color.
const SERIES = { first: "#3987e5", second: "#d95926" };
import { ChartCard, ChartTip, SERIES, Table, axis, delta, shortDay } from "@/components/charts";

const PERIODS: { value: `${AnalyticsPeriod}`; label: string }[] = [
{ value: "7", label: "7 days" },
Expand Down Expand Up @@ -51,24 +47,6 @@ const totalTokens = (s: { tokens?: number; tokens_in: number; tokens_out: number
const perPr = (s: { tokens?: number; tokens_in: number; tokens_out: number; prs_merged: number; tokens_per_merged_pr?: number | null }) =>
s.tokens_per_merged_pr ?? (s.prs_merged ? Math.round(totalTokens(s) / s.prs_merged) : null);

/** "+12% vs previous 30 days", or points for rates. Neutral ink: the reader judges. */
function delta(cur: number | null, prev: number | null, kind: "count" | "rate" | "hours", vs: string): string {
if (cur == null || prev == null) return `— ${vs}`;
if (kind === "rate") {
const pts = Math.round((cur - prev) * 100);
return `${pts > 0 ? "▲ " : pts < 0 ? "▼ " : ""}${pts === 0 ? "No change" : `${Math.abs(pts)} pts`} ${vs}`;
}
if (prev === 0) return cur === 0 ? `No change ${vs}` : `New ${vs}`;
const change = Math.round(((cur - prev) / prev) * 100);
if (change === 0) return `No change ${vs}`;
return `${change > 0 ? "▲" : "▼"} ${Math.abs(change)}% ${vs}`;
}

const shortDay = (day: string) => {
const d = new Date(`${day}T00:00:00Z`);
return d.toLocaleDateString(undefined, { month: "short", day: "numeric", timeZone: "UTC" });
};

// ── Pieces ─────────────────────────────────────────────────────────────────

/** One number: the shared stat tile, with the change in neutral ink (the reader judges). */
Expand All @@ -89,74 +67,6 @@ function RatingsTile({ up, down }: { up: number; down: number }) {
);
}

function ChartCard({ title, children, table, actions }: { title: string; children: ReactNode; table: ReactNode; actions?: ReactNode }) {
const [showTable, setShowTable] = useState(false);
return (
<div className="min-w-0 rounded-lg border border-zinc-800 bg-zinc-900/50 p-4">
<div className="mb-3 flex flex-wrap items-center justify-between gap-3">
<h3 className="text-sm font-medium text-zinc-200">{title}</h3>
{actions && <div className="order-last w-full sm:order-none sm:ml-auto sm:w-auto">{actions}</div>}
<button type="button" onClick={() => setShowTable((v) => !v)} aria-label={`${showTable ? "Show chart" : "Show table"}: ${title}`} className={`rounded text-xs text-zinc-400 underline-offset-2 hover:text-zinc-200 hover:underline ${focusRing}`}>
{showTable ? "Show chart" : "Show table"}
</button>
</div>
{showTable ? <div className="max-h-64 overflow-auto">{table}</div> : children}
</div>
);
}

function ChartTip({ active, payload, label, format }: { active?: boolean; payload?: { name: string; value: number; color: string }[]; label?: string; format?: (v: number) => string }) {
if (!active || !payload?.length) return null;
return (
<div className="rounded-lg border border-zinc-800 bg-zinc-950/95 px-3 py-2 shadow-xl">
<p className="mb-1 text-xs text-zinc-400">{label ? shortDay(label) : ""}</p>
{payload.map((p) => (
<div key={p.name} className="flex items-center gap-2 text-xs">
<span className="h-2 w-2 rounded-full" style={{ background: p.color }} aria-hidden="true" />
<span className="text-zinc-400">{p.name}</span>
<span className="ml-auto pl-3 font-medium tabular-nums text-zinc-100">{format ? format(p.value) : count(p.value)}</span>
</div>
))}
</div>
);
}

const axis = { stroke: "transparent", tick: { fill: "#71717a", fontSize: 11 }, tickLine: false, axisLine: false };

/**
* A table on the shared DataTable: the first column takes the spare width and
* wraps, numbers stay narrow, and a phone gets one card per row, so no column
* is ever pushed out of its card. `grow` marks other text columns that wrap.
*/
function Table({ head, rows, empty, label, grow = [] }: { head: string[]; rows: ReactNode[][]; empty: string; label: string; grow?: number[] }) {
const columns: Column<ReactNode[]>[] = head.map((h, i) => ({
key: `${i}-${h}`,
header: h,
cell: (r) => <span className="[overflow-wrap:break-word]">{r[i]}</span>,
width: i === 0 || grow.includes(i) ? "grow" : "fit",
align: i === 0 || grow.includes(i) ? "left" : "right",
clamp: grow.includes(i),
}));
const table = (
<DataTable
label={label}
columns={columns}
rows={rows}
rowKey={(_, i) => String(i)}
empty={<p className="rounded-lg border border-zinc-800 bg-zinc-900/50 p-4 text-sm text-zinc-400">{empty}</p>}
/>
);
// A wide table keeps a minimum width from sm: up and scrolls inside its own
// box, so no column squeezes a word in half; a phone gets one card per row.
if (head.length < 4) return table;
const min = head.length >= 7 ? "sm:min-w-[960px]" : head.length >= 5 ? "sm:min-w-[860px]" : "sm:min-w-[600px]";
return (
<div className="min-w-0 overflow-x-auto">
<div className={min}>{table}</div>
</div>
);
}

function actorLabel(a: string) {
return ({ reviewer: "Reviewer", planner: "Planner", coder: "Coding agent", people: "People in the dashboard" } as Record<string, string>)[a] ?? a;
}
Expand Down
47 changes: 39 additions & 8 deletions dashboard/src/app/settings/deliveries/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { RoleGuard } from "@/components/role-guard";
import { Page, PageHeader } from "@/components/page";
import { ListSkeleton, useListParams } from "@/components/list";
import { DEFAULT_RANGE, Deliveries } from "@/components/deliveries";
import { DeliveryOverview } from "@/components/delivery-overview";
import { Tabs } from "@/components/tabs";

const HEADER = (
<PageHeader
Expand All @@ -24,18 +26,47 @@ export default function DeliveriesPageGuarded() {
);
}

const DEFAULTS = { view: "list", source: "all", status: "all", range: DEFAULT_RANGE, q: "", id: "", from: "", until: "", endpoint: "", reason: "", period: "7d" };

/** A tab's address: the source and status filters go along, the rest stays with its view. */
function tabHref(view: "list" | "overview", source: string, status: string): string {
const q = new URLSearchParams();
if (view === "overview") q.set("view", "overview");
if (source !== "all") q.set("source", source);
if (status !== "all" && !(view === "overview" && status === "pending")) q.set("status", status);
const s = q.toString();
return `/settings/deliveries/${s ? `?${s}` : ""}`;
}

function DeliveriesPage() {
// Filters and the open delivery live in the address, so a view can be shared or reloaded.
const [params, set] = useListParams({ source: "all", status: "all", range: DEFAULT_RANGE, q: "", id: "" });
// Filters, the view and the open delivery live in the address, so a view can be shared or reloaded.
const [params, set] = useListParams(DEFAULTS);
const overview = params.view === "overview";
return (
<Page testId="deliveries-page">
<div className="mb-6">{HEADER}</div>
<Deliveries
filters={{ source: params.source, status: params.status, range: params.range, q: params.q }}
onFilters={(patch, opts) => set(patch, opts)}
openId={params.id}
onOpen={(id) => set({ id }, { replace: !id })}
<div className="mb-2">{HEADER}</div>
<Tabs
label="Deliveries views"
className="mb-6 mt-4"
value={overview ? "overview" : "list"}
items={[
{ value: "list", label: "Deliveries", href: tabHref("list", params.source, params.status) },
{ value: "overview", label: "Overview", href: tabHref("overview", params.source, params.status) },
]}
/>
{overview ? (
<DeliveryOverview
filters={{ period: params.period, source: params.source, status: params.status, endpoint: params.endpoint }}
onFilters={(patch) => set(patch)}
/>
) : (
<Deliveries
filters={{ source: params.source, status: params.status, range: params.range, q: params.q, from: params.from, until: params.until, endpoint: params.endpoint, reason: params.reason }}
onFilters={(patch, opts) => set(patch, opts)}
openId={params.id}
onOpen={(id) => set({ id }, { replace: !id })}
/>
)}
</Page>
);
}
100 changes: 100 additions & 0 deletions dashboard/src/components/charts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"use client";

/**
* The chart pieces Insights, Analytics and Settings, Deliveries share: a card
* with a chart and its table, the tooltip, axis styling, the series colors,
* a table that turns into cards on a phone, and the change against the
* period before.
*/

import { useState, type ReactNode } from "react";
import { DataTable, type Column } from "./data-table";
import { focusRing } from "./ui";

// Categorical slots for the dark chart surface, checked for color-vision
// separation and contrast (blue, orange). Text never takes a series color.
export const SERIES = { first: "#3987e5", second: "#d95926" };

/** "+12% vs previous 30 days", or points for rates. Neutral ink: the reader judges. */
export function delta(cur: number | null, prev: number | null, kind: "count" | "rate" | "hours", vs: string): string {
if (cur == null || prev == null) return `— ${vs}`;
if (kind === "rate") {
const pts = Math.round((cur - prev) * 100);
return `${pts > 0 ? "▲ " : pts < 0 ? "▼ " : ""}${pts === 0 ? "No change" : `${Math.abs(pts)} pts`} ${vs}`;
}
if (prev === 0) return cur === 0 ? `No change ${vs}` : `New ${vs}`;
const change = Math.round(((cur - prev) / prev) * 100);
if (change === 0) return `No change ${vs}`;
return `${change > 0 ? "▲" : "▼"} ${Math.abs(change)}% ${vs}`;
}
export const shortDay = (day: string) => {
const d = new Date(`${day}T00:00:00Z`);
return d.toLocaleDateString(undefined, { month: "short", day: "numeric", timeZone: "UTC" });
};
export function ChartCard({ title, children, table, actions }: { title: string; children: ReactNode; table: ReactNode; actions?: ReactNode }) {
const [showTable, setShowTable] = useState(false);
return (
<div className="min-w-0 rounded-lg border border-zinc-800 bg-zinc-900/50 p-4">
<div className="mb-3 flex flex-wrap items-center justify-between gap-3">
<h3 className="text-sm font-medium text-zinc-200">{title}</h3>
{actions && <div className="order-last w-full sm:order-none sm:ml-auto sm:w-auto">{actions}</div>}
<button type="button" onClick={() => setShowTable((v) => !v)} aria-label={`${showTable ? "Show chart" : "Show table"}: ${title}`} className={`rounded text-xs text-zinc-400 underline-offset-2 hover:text-zinc-200 hover:underline ${focusRing}`}>
{showTable ? "Show chart" : "Show table"}
</button>
</div>
{showTable ? <div className="max-h-64 overflow-auto">{table}</div> : children}
</div>
);
}

export function ChartTip({ active, payload, label, format, labelFormat = shortDay }: { active?: boolean; payload?: { name: string; value: number; color: string }[]; label?: string; format?: (v: number) => string; labelFormat?: (label: string) => string }) {
if (!active || !payload?.length) return null;
return (
<div className="rounded-lg border border-zinc-800 bg-zinc-950/95 px-3 py-2 shadow-xl">
<p className="mb-1 text-xs text-zinc-400">{label ? labelFormat(label) : ""}</p>
{payload.map((p) => (
<div key={p.name} className="flex items-center gap-2 text-xs">
<span className="h-2 w-2 rounded-full" style={{ background: p.color }} aria-hidden="true" />
<span className="text-zinc-400">{p.name}</span>
<span className="ml-auto pl-3 font-medium tabular-nums text-zinc-100">{format ? format(p.value) : p.value.toLocaleString()}</span>
</div>
))}
</div>
);
}

export const axis = { stroke: "transparent", tick: { fill: "#71717a", fontSize: 11 }, tickLine: false, axisLine: false };

/**
* A table on the shared DataTable: the first column takes the spare width and
* wraps, numbers stay narrow, and a phone gets one card per row, so no column
* is ever pushed out of its card. `grow` marks other text columns that wrap.
*/
export function Table({ head, rows, empty, label, grow = [] }: { head: string[]; rows: ReactNode[][]; empty: string; label: string; grow?: number[] }) {
const columns: Column<ReactNode[]>[] = head.map((h, i) => ({
key: `${i}-${h}`,
header: h,
cell: (r) => <span className="[overflow-wrap:break-word]">{r[i]}</span>,
width: i === 0 || grow.includes(i) ? "grow" : "fit",
align: i === 0 || grow.includes(i) ? "left" : "right",
clamp: grow.includes(i),
}));
const table = (
<DataTable
label={label}
columns={columns}
rows={rows}
rowKey={(_, i) => String(i)}
empty={<p className="rounded-lg border border-zinc-800 bg-zinc-900/50 p-4 text-sm text-zinc-400">{empty}</p>}
/>
);
// A wide table keeps a minimum width from sm: up and scrolls inside its own
// box, so no column squeezes a word in half; a phone gets one card per row.
if (head.length < 4) return table;
const min = head.length >= 7 ? "sm:min-w-[960px]" : head.length >= 5 ? "sm:min-w-[860px]" : "sm:min-w-[600px]";
return (
<div className="min-w-0 overflow-x-auto">
<div className={min}>{table}</div>
</div>
);
}
Loading
Loading