Skip to content

Commit ed79de6

Browse files
fix(web): retain usage status for unselected environments
1 parent c5365fd commit ed79de6

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎apps/web/src/components/usage/UsagePage.tsx‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import type { EnvironmentId, UsageProviderKind } from "@t3tools/contracts";
2+
import {
3+
USAGE_CONTRACT_VERSION,
4+
type EnvironmentId,
5+
type UsageProviderKind,
6+
} from "@t3tools/contracts";
37
import { CircleAlertIcon, ChevronDownIcon, CircleDashedIcon, RefreshCwIcon } from "lucide-react";
48
import { useMemo, useState } from "react";
59

6-
import type { DailyTotals, HourlyTotals } from "@t3tools/shared/usageMerge";
10+
import {
11+
isCompatibleUsageContractVersion,
12+
type DailyTotals,
13+
type HourlyTotals,
14+
} from "@t3tools/shared/usageMerge";
715

816
import { isElectron } from "../../env";
917
import { cn } from "../../lib/utils";
@@ -679,7 +687,11 @@ function UsageEnvironmentFilter({
679687
const status =
680688
environment.error !== null
681689
? "Unavailable"
682-
: staleEnvironments.includes(environment.environmentId)
690+
: environment.summary !== null &&
691+
!isCompatibleUsageContractVersion(
692+
environment.summary.contractVersion,
693+
USAGE_CONTRACT_VERSION,
694+
)
683695
? "Update required"
684696
: environment.summary === null
685697
? "Scanning…"

‎packages/shared/src/usageMerge.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function bucketTokens(bucket: UsageBucket): number {
173173
);
174174
}
175175

176-
function isCompatibleContractVersion(version: number, expected: number): boolean {
176+
export function isCompatibleUsageContractVersion(version: number, expected: number): boolean {
177177
return version >= USAGE_MERGE_COMPATIBLE_SINCE && version <= expected;
178178
}
179179

@@ -220,7 +220,9 @@ export function mergeUsage(
220220
const current: EnvironmentUsage[] = [];
221221
const staleEnvironments: EnvironmentId[] = [];
222222
for (const environment of environments) {
223-
if (isCompatibleContractVersion(environment.summary.contractVersion, expectedContractVersion)) {
223+
if (
224+
isCompatibleUsageContractVersion(environment.summary.contractVersion, expectedContractVersion)
225+
) {
224226
current.push(environment);
225227
} else {
226228
staleEnvironments.push(environment.environmentId);

0 commit comments

Comments
 (0)