Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(web): show only providers with usage in usage views (#7563)

Tristan Knight17dbe8dda3ba
diff --git a/apps/web/src/components/usage/UsagePage.test.tsx b/apps/web/src/components/usage/UsagePage.test.tsx
index 5755e73b1..373e8a07c 100644
--- a/apps/web/src/components/usage/UsagePage.test.tsx
+++ b/apps/web/src/components/usage/UsagePage.test.tsx
@@ -53,13 +53,16 @@ vi.mock("../WorkspaceBreadcrumb", () => ({
vi.mock("../WorkspacePageContainer", () => ({ WorkspacePageContainer: "main" }));
vi.mock("../WorkspacePageHeader", () => ({ WorkspacePageHeader: "header" }));
vi.mock("./UsageProviderChart", () => ({ UsageProviderChart: "div" }));
-vi.mock("./usageProviders", () => ({
- PROVIDER_ORDER: ["codex", "claude"],
- PROVIDER_PRESENTATION: {
- codex: { color: "white", label: "Codex", mark: "span" },
- claude: { color: "orange", label: "Claude Code", mark: "span" },
- },
-}));
+vi.mock("./usageProviders", async (importOriginal) => {
+ const actual = await importOriginal<typeof import("./usageProviders")>();
+ return {
+ ...actual,
+ PROVIDER_PRESENTATION: {
+ codex: { color: "white", label: "Codex", mark: "span" },
+ claude: { color: "orange", label: "Claude Code", mark: "span" },
+ },
+ };
+});
import { UsagePage } from "./UsagePage";
diff --git a/apps/web/src/components/usage/UsagePage.tsx b/apps/web/src/components/usage/UsagePage.tsx
index 3c99271c1..0c9239a78 100644
--- a/apps/web/src/components/usage/UsagePage.tsx
+++ b/apps/web/src/components/usage/UsagePage.tsx
@@ -32,7 +32,7 @@ import {
import { WorkspacePageContainer } from "../WorkspacePageContainer";
import { WorkspacePageHeader } from "../WorkspacePageHeader";
import { UsageProviderChart, type UsageChartMetric } from "./UsageProviderChart";
-import { PROVIDER_ORDER, PROVIDER_PRESENTATION } from "./usageProviders";
+import { PROVIDER_ORDER, PROVIDER_PRESENTATION, providersWithUsage } from "./usageProviders";
const WINDOW_OPTIONS = [
{ days: 1, label: "Past 24h" },
@@ -74,6 +74,8 @@ export function UsagePage() {
() => (isPast24Hours ? merged.hourly : merged.daily).toReversed(),
[isPast24Hours, merged.daily, merged.hourly],
);
+ const activeProviders = useMemo(() => providersWithUsage(merged.providers), [merged.providers]);
+ const timeValueColumnWidth = `${60 / (activeProviders.length + 2)}%`;
const selectWindow = (days: number) => {
setWindowSelection({
@@ -225,7 +227,7 @@ export function UsagePage() {
</span>
</div>
- {PROVIDER_ORDER.map((provider) => {
+ {activeProviders.map((provider) => {
const totals = merged.providers.find((entry) => entry.provider === provider);
const share =
metric === "cost" ? (totals?.costShare ?? 0) : (totals?.tokenShare ?? 0);
@@ -276,6 +278,7 @@ export function UsagePage() {
{metric === "tokens" ? "processed tokens" : "cost"}
</h2>
<UsageProviderChart
+ providers={activeProviders}
days={days}
daily={merged.daily}
hours={hours}
@@ -331,7 +334,13 @@ export function UsagePage() {
</div>
{breakdown === "model" ? (
- <table className="w-full text-sm">
+ <table className="w-full table-fixed text-sm">
+ <colgroup>
+ <col className="w-2/5" />
+ <col className="w-1/5" />
+ <col className="w-1/5" />
+ <col className="w-1/5" />
+ </colgroup>
<thead>
<tr className="border-b border-border text-left text-xs text-muted-foreground">
<th className="py-2 font-normal">Model</th>
@@ -374,11 +383,19 @@ export function UsagePage() {
</tbody>
</table>
) : (
- <table className="w-full text-sm">
+ <table className="w-full table-fixed text-sm">
+ <colgroup>
+ <col className="w-2/5" />
+ {activeProviders.map((provider) => (
+ <col key={provider} style={{ width: timeValueColumnWidth }} />
+ ))}
+ <col style={{ width: timeValueColumnWidth }} />
+ <col style={{ width: timeValueColumnWidth }} />
+ </colgroup>
<thead>
<tr className="border-b border-border text-left text-xs text-muted-foreground">
<th className="py-2 font-normal">{isPast24Hours ? "Hour" : "Day"}</th>
- {PROVIDER_ORDER.map((provider) => (
+ {activeProviders.map((provider) => (
<th key={provider} className="py-2 text-right font-normal">
{PROVIDER_PRESENTATION[provider].label}
</th>
@@ -390,7 +407,10 @@ export function UsagePage() {
<tbody>
{breakdownPeriods.length === 0 ? (
<tr>
- <td colSpan={5} className="py-6 text-center text-muted-foreground">
+ <td
+ colSpan={activeProviders.length + 3}
+ className="py-6 text-center text-muted-foreground"
+ >
No activity in this window.
</td>
</tr>
@@ -405,7 +425,7 @@ export function UsagePage() {
? formatHourShort(period.hourStart, window.timeZone)
: formatDayShort(period.day)}
</td>
- {PROVIDER_ORDER.map((provider) => (
+ {activeProviders.map((provider) => (
<td
key={provider}
className="py-2 text-right text-muted-foreground tabular-nums"
diff --git a/apps/web/src/components/usage/UsageProviderChart.test.ts b/apps/web/src/components/usage/UsageProviderChart.test.ts
index 1c91ab1b4..09961213b 100644
--- a/apps/web/src/components/usage/UsageProviderChart.test.ts
+++ b/apps/web/src/components/usage/UsageProviderChart.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vite-plus/test";
import { buildDayColumns, niceScale } from "./UsageProviderChart";
+import { providersWithUsage } from "./usageProviders";
describe("niceScale", () => {
it("never puts the peak above the top of the scale", () => {
@@ -96,6 +97,17 @@ describe("buildDayColumns", () => {
});
});
+describe("providersWithUsage", () => {
+ it("omits providers with no cost or tokens", () => {
+ expect(
+ providersWithUsage([
+ { provider: "codex", costUsd: 0, totalTokens: 0 },
+ { provider: "claude", costUsd: 0, totalTokens: 200 },
+ ]),
+ ).toEqual(["claude"]);
+ });
+});
+
describe("hourly chart columns", () => {
it("zero-fills inactive hours and preserves hourly provider values", () => {
const byHour = new Map([
diff --git a/apps/web/src/components/usage/UsageProviderChart.tsx b/apps/web/src/components/usage/UsageProviderChart.tsx
index 8bc846483..26d49e664 100644
--- a/apps/web/src/components/usage/UsageProviderChart.tsx
+++ b/apps/web/src/components/usage/UsageProviderChart.tsx
@@ -19,6 +19,7 @@ const PLOT_TOP = 8;
export type UsageChartMetric = "tokens" | "cost";
interface UsageProviderChartProps {
+ readonly providers: readonly UsageProviderKind[];
readonly days: readonly string[];
readonly daily: readonly DailyTotals[];
readonly hours: readonly string[];
@@ -187,6 +188,7 @@ export function buildDayColumns(
}
export function UsageProviderChart({
+ providers,
days,
daily,
hours,
@@ -209,7 +211,7 @@ export function UsageProviderChart({
const tooltipRef = useRef<HTMLDivElement | null>(null);
const hoverPositionRef = useRef<{ x: number; y: number } | null>(null);
- const { paths, series, stepX, ticks, toY } = useMemo(() => {
+ const { paths, ticks, stepX, toY, series } = useMemo(() => {
if (periods.length === 0) {
return {
paths: [],
@@ -235,7 +237,8 @@ export function UsageProviderChart({
const toY = (value: number) =>
max === 0 ? VIEW_HEIGHT : VIEW_HEIGHT - (value / max) * (VIEW_HEIGHT - PLOT_TOP);
- const built = PROVIDER_ORDER.map((provider, providerIndex) => {
+ const built = providers.map((provider) => {
+ const providerIndex = PROVIDER_ORDER.indexOf(provider);
const line = curvePath(
smoothCurve(
columns.map((column, periodIndex) => ({
@@ -260,7 +263,7 @@ export function UsageProviderChart({
ticks: tickValues,
toY,
};
- }, [byPeriod, metric, periods]);
+ }, [byPeriod, metric, periods, providers]);
const format = metric === "tokens" ? formatTokens : formatUsd;
@@ -422,7 +425,7 @@ export function UsageProviderChart({
}}
>
<div className="mb-1 text-muted-foreground">{formatTooltipPeriod(hoveredPeriod)}</div>
- {PROVIDER_ORDER.map((provider) => {
+ {providers.map((provider) => {
const { label, mark: Mark } = PROVIDER_PRESENTATION[provider];
return (
<div key={provider} className="flex items-center justify-between gap-3">
diff --git a/apps/web/src/components/usage/usageProviders.ts b/apps/web/src/components/usage/usageProviders.ts
index 74ee27a2b..79f62a65a 100644
--- a/apps/web/src/components/usage/usageProviders.ts
+++ b/apps/web/src/components/usage/usageProviders.ts
@@ -10,8 +10,8 @@ type UsageProviderPresentation = {
/**
* Exhaustive presentation for providers supported by the usage contract.
- * Declaration order is reused by every chart, table, legend, and skeleton, so
- * adding a provider only requires its contract support and one entry here.
+ * Declaration order is reused by every chart and table, so adding a provider
+ * only requires its contract support and one entry here.
*/
export const PROVIDER_PRESENTATION = {
codex: {
@@ -28,3 +28,19 @@ export const PROVIDER_PRESENTATION = {
/** Stable provider reading order across charts, summaries, tables, and hover rows. */
export const PROVIDER_ORDER = Object.keys(PROVIDER_PRESENTATION) as UsageProviderKind[];
+
+/** Providers with real activity, independent of the metric currently displayed. */
+export function providersWithUsage(
+ totals: readonly {
+ readonly provider: UsageProviderKind;
+ readonly costUsd: number;
+ readonly totalTokens: number;
+ }[],
+): readonly UsageProviderKind[] {
+ const active = new Set(
+ totals
+ .filter((entry) => entry.totalTokens > 0 || entry.costUsd > 0)
+ .map((entry) => entry.provider),
+ );
+ return PROVIDER_ORDER.filter((provider) => active.has(provider));
+}