mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
fix(web): drop the provider label from the plan-usage chip when there is only one
The chip prefixes every row with the provider name, so a machine that only has Claude limits renders "CLAUDE 5H 60% 7D 23%" — a 46px label naming the only thing it could possibly be. The name exists to tell two rows apart, so it should only appear when there are two. updatePlanUsageChip() now checks whether both Claude and Codex actually have windows before building the rows, and emits the .pu-provider span only in that case. The tooltip keeps naming the provider in both cases: it has the room, and the chip no longer does. Verified in a browser on an isolated beta instance: Claude-only renders bare windows with no .pu-provider in the DOM, Codex-only the same, and the two-provider chip is byte-identical to before. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2638,10 +2638,15 @@ class CodemanApp {
|
||||
if (!Number.isFinite(n)) return '';
|
||||
return `<span class="pu-win"><span class="pu-label">${label}</span><span class="pu-val ${colorClass(n)}">${n}%</span></span>`;
|
||||
};
|
||||
// The provider label only earns its space when there is more than one
|
||||
// provider to tell apart: a machine with Claude alone shows bare windows.
|
||||
const hasWindows = (usage) => pct(usage?.fiveHour) !== null || pct(usage?.sevenDay) !== null;
|
||||
const labelled = hasWindows(data) && hasWindows(data.codex);
|
||||
const row = (provider, usage) => {
|
||||
const windows = [seg('5h', pct(usage?.fiveHour)), seg('7d', pct(usage?.sevenDay))].filter(Boolean);
|
||||
if (!windows.length) return '';
|
||||
return `<span class="pu-row"><span class="pu-provider">${provider}</span><span class="pu-windows">${windows.join('<span class="pu-sep">·</span>')}</span></span>`;
|
||||
const label = labelled ? `<span class="pu-provider">${provider}</span>` : '';
|
||||
return `<span class="pu-row">${label}<span class="pu-windows">${windows.join('<span class="pu-sep">·</span>')}</span></span>`;
|
||||
};
|
||||
const rows = [row('Claude', data), row('Codex', data.codex)].filter(Boolean);
|
||||
chip.innerHTML = rows.length ? rows.join('') : '—';
|
||||
|
||||
@@ -79,4 +79,36 @@ describe('header plan usage chip', () => {
|
||||
expect(codexRow).not.toContain('5h');
|
||||
expect(codexRow).toContain('7d');
|
||||
});
|
||||
|
||||
it('drops the provider label when Claude is the only provider with limits', () => {
|
||||
const { CodemanApp, chip } = loadCodemanAppClass();
|
||||
const app = Object.create((CodemanApp as { prototype: object }).prototype) as UsageApp;
|
||||
|
||||
app.updatePlanUsageChip({
|
||||
fiveHour: { usedPercentage: 60, resetAt: 1000 },
|
||||
sevenDay: { usedPercentage: 23, resetAt: 2000 },
|
||||
});
|
||||
|
||||
expect(chip.innerHTML).toContain('class="pu-row"');
|
||||
expect(chip.innerHTML).not.toContain('pu-provider');
|
||||
expect(chip.innerHTML).not.toContain('Claude');
|
||||
expect(chip.innerHTML).toContain('60%');
|
||||
expect(chip.innerHTML).toContain('23%');
|
||||
// The tooltip still names the provider — it has room, and the chip no longer does.
|
||||
expect(chip.title).toContain('Claude plan usage');
|
||||
});
|
||||
|
||||
it('drops the provider label when Codex is the only provider with limits', () => {
|
||||
const { CodemanApp, chip } = loadCodemanAppClass();
|
||||
const app = Object.create((CodemanApp as { prototype: object }).prototype) as UsageApp;
|
||||
|
||||
app.updatePlanUsageChip({
|
||||
codex: { fiveHour: { usedPercentage: 12, resetAt: 3000 } },
|
||||
});
|
||||
|
||||
expect(chip.innerHTML).toContain('class="pu-row"');
|
||||
expect(chip.innerHTML).not.toContain('pu-provider');
|
||||
expect(chip.innerHTML).toContain('12%');
|
||||
expect(chip.title).toContain('Codex plan usage');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user