mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 08:24:46 +00:00
fix(usage): keep the sidebar usage summary current while it is shown
The summary fetched reports once on mount and never again: no interval, window-focus and reconnect refetches are off app-wide, and the daemon does not push report changes. It only updated when the Usage modal or Settings mounted the same query and refetched it. It now re-reads every minute while visible; the daemon answers from its five-minute cache, so source APIs are still hit at most once per cache window.
This commit is contained in:
@@ -469,3 +469,27 @@ test("visible usage summary requests reports on load", async ({ page }) => {
|
||||
await expectPinnedUsage(page, ["31% 5h", "54% wk", "7% 5h", "12% wk"]);
|
||||
expect(usage.listRequests()).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("visible usage summary picks up changed reports without opening Usage", async ({ page }) => {
|
||||
test.setTimeout(180_000);
|
||||
const usage = await installUsageReportsFixture(page, {
|
||||
lists: [() => claudeSessionAt(31), () => claudeSessionAt(80)],
|
||||
});
|
||||
await seedSidebarFooterPreferences(page, [{ key: "usage", visible: true }]);
|
||||
await page.setViewportSize(WIDE);
|
||||
await page.clock.install();
|
||||
await gotoAppShell(page);
|
||||
await expectPinnedUsage(page, ["31% 5h", "54% wk", "7% 5h", "12% wk"]);
|
||||
expect(usage.listRequests()).toHaveLength(1);
|
||||
|
||||
await page.clock.fastForward(61_000);
|
||||
await expectPinnedUsage(page, ["80% 5h", "54% wk", "7% 5h", "12% wk"]);
|
||||
await expect(usageModal(page)).toHaveCount(0);
|
||||
});
|
||||
|
||||
function claudeSessionAt(usedPct: number) {
|
||||
const reports = claudeAndCodexReports();
|
||||
const claude = reports[0]!;
|
||||
if (claude.report.status === "available") claude.report.windows[0]!.usedPct = usedPct;
|
||||
return reports;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,8 @@ const NO_REPORTS: UsageReportEntry[] = [];
|
||||
|
||||
/**
|
||||
* The reports of the sidebar's usage host, which is connected and reports usage; none until they
|
||||
* load, or without a host.
|
||||
* load, or without a host. Re-read every minute while the summary is shown, since the daemon never
|
||||
* pushes report changes.
|
||||
*/
|
||||
export function useUsageHostReports(serverId: string | null): UsageReportEntry[] {
|
||||
const setting = useUsageSetting(serverId);
|
||||
@@ -177,6 +178,7 @@ export function useUsageHostReports(serverId: string | null): UsageReportEntry[]
|
||||
queryFn: serverId ? () => listReports(queryClient, serverId) : skipToken,
|
||||
dataShape: "list",
|
||||
staleTimeMs: REPORTS_STALE_TIME_MS,
|
||||
refetchInterval: REPORTS_STALE_TIME_MS,
|
||||
});
|
||||
return setting.enabled ? (query.data ?? NO_REPORTS) : NO_REPORTS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user